Skip to content

Commit 1faadee

Browse files
authored
do not match someone with themself if only one user has coffechat role (#486)
1 parent 66ed6ab commit 1faadee

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/commands/coffeeChat/coffeeChat.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ export class CoffeeChatCommand extends Subcommand {
1717
name: 'coffee',
1818
description: 'Handle coffee chat functions.',
1919
detailedDescription: `**Examples:**
20-
\`${container.botPrefix}coffeechat match\`
2120
\`${container.botPrefix}coffee match\`
22-
\`${container.botPrefix}coffeechat test 5\`
2321
\`${container.botPrefix}coffee test 10\``,
2422
subcommands: [
2523
{ name: 'match', messageRun: 'match' },
@@ -32,6 +30,8 @@ export class CoffeeChatCommand extends Subcommand {
3230
async match(message: Message): Promise<Message> {
3331
//makes sure future matches are valid (made for the current group / still has matches left)
3432
const matches = await getMatch();
33+
if (!matches.length)
34+
return message.reply(`Not enough members with coffee chat role to generate matches.`);
3535
await alertMatches(matches);
3636
await writeHistoricMatches(matches);
3737
return message.reply(`Sent ${matches.length} match(es).`);

src/components/coffeeChat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ interface historic_match {
2626
export const getMatch = async (): Promise<string[][]> => {
2727
// Gets the list of users that are currently "enrolled" in role
2828
const userList = await loadRoleUsers(COFFEE_ROLE_ID);
29+
if (userList.length <= 1) return [];
2930

3031
// Assigns each user ID a unique index
3132
const notMatched: Map<string, number> = new Map();

src/components/cron.ts

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,16 +122,19 @@ export const createBonusInterviewerListCron = (): CronJob =>
122122
export const createCoffeeChatCron = (client: Client): CronJob =>
123123
new CronJob('0 0 14 * * 5', async function () {
124124
const matches = await getMatch();
125-
await alertMatches(matches);
126-
await writeHistoricMatches(matches);
127125

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+
}
135138
}
136139
});
137140

0 commit comments

Comments
 (0)