1
- import { container } from '@sapphire/framework ' ;
1
+ import { Client } from 'discord.js ' ;
2
2
import { CronJob } from 'cron' ;
3
3
import { MessageEmbed , TextChannel } from 'discord.js' ;
4
4
import _ from 'lodash' ;
@@ -15,21 +15,20 @@ const NOTIF_CHANNEL_ID: string = vars.NOTIF_CHANNEL_ID;
15
15
const OFFICE_STATUS_CHANNEL_ID : string = vars . OFFICE_STATUS_CHANNEL_ID ;
16
16
const OFFICE_HOURS_STATUS_API = 'https://csclub.uwaterloo.ca/~n3parikh/office-status.json' ;
17
17
18
- export const initCrons = async ( ) : Promise < void > => {
19
- createSuggestionCron ( ) . start ( ) ;
18
+ export const initCrons = async ( client : Client ) : Promise < void > => {
19
+ createSuggestionCron ( client ) . start ( ) ;
20
20
createBonusInterviewerListCron ( ) . start ( ) ;
21
- createCoffeeChatCron ( ) . start ( ) ;
22
- createOfficeStatusCron ( ) . start ( ) ;
21
+ createCoffeeChatCron ( client ) . start ( ) ;
22
+ createOfficeStatusCron ( client ) . start ( ) ;
23
23
} ;
24
24
25
25
interface officeStatus {
26
26
status : number ;
27
27
time : number ;
28
28
}
29
29
// Updates office status based on webcom API
30
- export const createOfficeStatusCron = ( ) : CronJob =>
30
+ export const createOfficeStatusCron = ( client : Client ) : CronJob =>
31
31
new CronJob ( '0 */1 * * * *' , async function ( ) {
32
- const { client } = container ;
33
32
const response = ( await ( await fetch ( OFFICE_HOURS_STATUS_API ) ) . json ( ) ) as officeStatus ;
34
33
const messageChannel = client . channels . cache . get ( OFFICE_STATUS_CHANNEL_ID ) ;
35
34
if ( ! messageChannel ) {
@@ -51,9 +50,8 @@ export const createOfficeStatusCron = (): CronJob =>
51
50
} ) ;
52
51
53
52
// Checks for new suggestions every min
54
- export const createSuggestionCron = ( ) : CronJob =>
53
+ export const createSuggestionCron = ( client : Client ) : CronJob =>
55
54
new CronJob ( '0 */1 * * * *' , async function ( ) {
56
- const { client } = container ;
57
55
const createdSuggestions = await getSuggestions ( SuggestionState . Created ) ;
58
56
const createdSuggestionIds = createdSuggestions . map ( ( a ) => Number ( a . id ) ) ;
59
57
if ( ! _ . isEmpty ( createdSuggestionIds ) ) {
@@ -89,10 +87,8 @@ export const createBonusInterviewerListCron = (): CronJob =>
89
87
} ) ;
90
88
91
89
// Match coffeechat users every week on Friday
92
- export const createCoffeeChatCron = ( ) : CronJob =>
90
+ export const createCoffeeChatCron = ( client : Client ) : CronJob =>
93
91
new CronJob ( '0 0 14 * * 5' , async function ( ) {
94
- const { client } = container ;
95
-
96
92
const matches = await getMatch ( ) ;
97
93
await CoffeeChatCommand . alertMatches ( matches ) ;
98
94
await writeHistoricMatches ( matches ) ;
0 commit comments