File tree Expand file tree Collapse file tree 3 files changed +15
-11
lines changed Expand file tree Collapse file tree 3 files changed +15
-11
lines changed Original file line number Diff line number Diff line change @@ -17,9 +17,7 @@ export class CoffeeChatCommand extends Subcommand {
17
17
name : 'coffee' ,
18
18
description : 'Handle coffee chat functions.' ,
19
19
detailedDescription : `**Examples:**
20
- \`${ container . botPrefix } coffeechat match\`
21
20
\`${ container . botPrefix } coffee match\`
22
- \`${ container . botPrefix } coffeechat test 5\`
23
21
\`${ container . botPrefix } coffee test 10\`` ,
24
22
subcommands : [
25
23
{ name : 'match' , messageRun : 'match' } ,
@@ -32,6 +30,8 @@ export class CoffeeChatCommand extends Subcommand {
32
30
async match ( message : Message ) : Promise < Message > {
33
31
//makes sure future matches are valid (made for the current group / still has matches left)
34
32
const matches = await getMatch ( ) ;
33
+ if ( ! matches . length )
34
+ return message . reply ( `Not enough members with coffee chat role to generate matches.` ) ;
35
35
await alertMatches ( matches ) ;
36
36
await writeHistoricMatches ( matches ) ;
37
37
return message . reply ( `Sent ${ matches . length } match(es).` ) ;
Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ interface historic_match {
26
26
export const getMatch = async ( ) : Promise < string [ ] [ ] > => {
27
27
// Gets the list of users that are currently "enrolled" in role
28
28
const userList = await loadRoleUsers ( COFFEE_ROLE_ID ) ;
29
+ if ( userList . length <= 1 ) return [ ] ;
29
30
30
31
// Assigns each user ID a unique index
31
32
const notMatched : Map < string , number > = new Map ( ) ;
Original file line number Diff line number Diff line change @@ -122,16 +122,19 @@ export const createBonusInterviewerListCron = (): CronJob =>
122
122
export const createCoffeeChatCron = ( client : Client ) : CronJob =>
123
123
new CronJob ( '0 0 14 * * 5' , async function ( ) {
124
124
const matches = await getMatch ( ) ;
125
- await alertMatches ( matches ) ;
126
- await writeHistoricMatches ( matches ) ;
127
125
128
- const messageChannel = client . channels . cache . get ( NOTIF_CHANNEL_ID ) ;
129
- if ( ! messageChannel ) {
130
- throw 'Bad channel ID' ;
131
- } else if ( messageChannel . type === ChannelType . GuildText ) {
132
- ( messageChannel as TextChannel ) . send ( `Sent ${ matches . length } match(es).` ) ;
133
- } else {
134
- throw 'Bad channel type' ;
126
+ if ( ! matches . length ) throw `Not enough members with coffee chat role to generate matches.` ;
127
+ else {
128
+ await alertMatches ( matches ) ;
129
+ await writeHistoricMatches ( matches ) ;
130
+ const messageChannel = client . channels . cache . get ( NOTIF_CHANNEL_ID ) ;
131
+ if ( ! messageChannel ) {
132
+ throw 'Bad channel ID' ;
133
+ } else if ( messageChannel . type === ChannelType . GuildText ) {
134
+ ( messageChannel as TextChannel ) . send ( `Sent ${ matches . length } match(es).` ) ;
135
+ } else {
136
+ throw 'Bad channel type' ;
137
+ }
135
138
}
136
139
} ) ;
137
140
You can’t perform that action at this time.
0 commit comments