@@ -44,6 +44,7 @@ const TEST_DATE = undefined;
44
44
// Google maps API URL
45
45
const today = new Date ( TEST_DATE ?? new Date ( ) . toLocaleDateString ( ) ) ;
46
46
const nextWeek = new Date ( today ) ;
47
+ let operationsDate : Date | undefined = undefined ; // to pass into the hook
47
48
nextWeek . setDate ( today . getDate ( ) + 8 ) ;
48
49
console . log ( "Today: " , today , "\nNext Week: " , nextWeek ) ;
49
50
@@ -106,6 +107,7 @@ function removeHTMLTags(str: string) {
106
107
107
108
// date obj to string
108
109
function dateToString ( date : Date ) {
110
+ date = new Date ( date . toLocaleDateString ( ) ) ;
109
111
const day = date . getDate ( ) ;
110
112
const month = date . getMonth ( ) + 1 ;
111
113
const year = date . getFullYear ( ) ;
@@ -275,12 +277,29 @@ async function getValidEvents(data: GoogleCalendarDataProps[]) {
275
277
allEvents . map ( ( obj : GoogleCalendarDataProps ) => {
276
278
// gets the event date based on two fields from the API
277
279
// also sets this to local time zone
278
- const eventDate = new Date (
280
+ let eventDate = new Date (
279
281
new Date (
280
282
obj . start . dateTime ?? obj . start . date ?? "TBA"
281
283
) . toLocaleDateString ( )
282
284
) ;
283
285
286
+ // the ops meeting event caused so many issues.
287
+ // we decided to hardcode it, and so,
288
+ // this sets the ops meeting's date to the monday within
289
+ // the next 7 days (or today if today's the meeting).
290
+ if ( obj . summary . includes ( "Operations Meeting" ) ) {
291
+ if ( today . getDay ( ) == 1 ) {
292
+ eventDate = today ;
293
+ operationsDate = eventDate ;
294
+ } else {
295
+ const daysOfWeek = today . getDay ( ) + 1 ;
296
+ const daysUntilMonday = ( 8 - daysOfWeek ) % 7 ;
297
+ eventDate = new Date ( today ) ;
298
+ eventDate . setDate ( today . getDate ( ) + daysUntilMonday ) ;
299
+ operationsDate = eventDate ;
300
+ }
301
+ }
302
+
284
303
console . log ( today , tomorrow , nextWeek ) ;
285
304
if ( isSameDay ( today , eventDate , `${ obj . summary } TODAY` ) ) {
286
305
validEvents . push ( {
@@ -320,10 +339,14 @@ async function hookLogic(client: Client, webhook: WebhookClient) {
320
339
if ( events . length === 0 ) {
321
340
return ;
322
341
} else if ( events . length >= 1 ) {
323
- const messageDay = new Date ( today ) ;
324
- messageDay . setDate ( today . getDate ( ) + 1 ) ;
342
+ let messageDate = today ;
343
+ if ( TEST_DATE ) {
344
+ messageDate = new Date ( TEST_DATE ) ;
345
+ messageDate . setDate ( messageDate . getDate ( ) + 1 ) ;
346
+ } // for some reason its one day behind when using a test date.
347
+
325
348
webhook . send (
326
- `Hey <@&${ config . CALENDAR_ROLE_ID } >, it's ${ dateToString ( messageDay ) } , here are some reminders about our upcoming events!\n`
349
+ `Hey <@&${ config . CALENDAR_ROLE_ID } >, it's ${ dateToString ( messageDate ) } , here are some reminders about our upcoming events!\n`
327
350
) ;
328
351
}
329
352
@@ -374,7 +397,9 @@ async function hookLogic(client: Client, webhook: WebhookClient) {
374
397
if ( date . date ) {
375
398
fields . splice ( 1 , 0 , {
376
399
name : "Date" ,
377
- value : `${ date . date } ` ,
400
+ value : `${
401
+ operationsDate ? dateToString ( operationsDate ) : date . date
402
+ } `, // if date is an ops meeting, set it to that specific date
378
403
inline : false ,
379
404
} ) ;
380
405
}
@@ -417,7 +442,7 @@ export async function execute(client: Client) {
417
442
418
443
try {
419
444
// Check events on a schedule
420
- cron . schedule ( "0 8 * * *" , async ( ) => hookLogic ( client , preWebhook ) ) ;
445
+ cron . schedule ( "15 10 * * *" , async ( ) => hookLogic ( client , preWebhook ) ) ;
421
446
cron . schedule ( "0 12 * * *" , async ( ) => hookLogic ( client , webhook ) ) ;
422
447
// Catch any errors
423
448
} catch ( err : unknown ) {
0 commit comments