From 1faadee347de4589401fec407fefbd919013b528 Mon Sep 17 00:00:00 2001 From: Fan-Yang-284 <69977136+Fan-Yang-284@users.noreply.github.com> Date: Sun, 18 Jun 2023 17:15:02 -0400 Subject: [PATCH] do not match someone with themself if only one user has coffechat role (#486) --- src/commands/coffeeChat/coffeeChat.ts | 4 ++-- src/components/coffeeChat.ts | 1 + src/components/cron.ts | 21 ++++++++++++--------- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/commands/coffeeChat/coffeeChat.ts b/src/commands/coffeeChat/coffeeChat.ts index 409d0162..0beb594a 100644 --- a/src/commands/coffeeChat/coffeeChat.ts +++ b/src/commands/coffeeChat/coffeeChat.ts @@ -17,9 +17,7 @@ export class CoffeeChatCommand extends Subcommand { name: 'coffee', description: 'Handle coffee chat functions.', detailedDescription: `**Examples:** -\`${container.botPrefix}coffeechat match\` \`${container.botPrefix}coffee match\` -\`${container.botPrefix}coffeechat test 5\` \`${container.botPrefix}coffee test 10\``, subcommands: [ { name: 'match', messageRun: 'match' }, @@ -32,6 +30,8 @@ export class CoffeeChatCommand extends Subcommand { async match(message: Message): Promise { //makes sure future matches are valid (made for the current group / still has matches left) const matches = await getMatch(); + if (!matches.length) + return message.reply(`Not enough members with coffee chat role to generate matches.`); await alertMatches(matches); await writeHistoricMatches(matches); return message.reply(`Sent ${matches.length} match(es).`); diff --git a/src/components/coffeeChat.ts b/src/components/coffeeChat.ts index 7e726c07..dc18c028 100644 --- a/src/components/coffeeChat.ts +++ b/src/components/coffeeChat.ts @@ -26,6 +26,7 @@ interface historic_match { export const getMatch = async (): Promise => { // Gets the list of users that are currently "enrolled" in role const userList = await loadRoleUsers(COFFEE_ROLE_ID); + if (userList.length <= 1) return []; // Assigns each user ID a unique index const notMatched: Map = new Map(); diff --git a/src/components/cron.ts b/src/components/cron.ts index c2598dd9..810d4b84 100644 --- a/src/components/cron.ts +++ b/src/components/cron.ts @@ -122,16 +122,19 @@ export const createBonusInterviewerListCron = (): CronJob => export const createCoffeeChatCron = (client: Client): CronJob => new CronJob('0 0 14 * * 5', async function () { const matches = await getMatch(); - await alertMatches(matches); - await writeHistoricMatches(matches); - const messageChannel = client.channels.cache.get(NOTIF_CHANNEL_ID); - if (!messageChannel) { - throw 'Bad channel ID'; - } else if (messageChannel.type === ChannelType.GuildText) { - (messageChannel as TextChannel).send(`Sent ${matches.length} match(es).`); - } else { - throw 'Bad channel type'; + if (!matches.length) throw `Not enough members with coffee chat role to generate matches.`; + else { + await alertMatches(matches); + await writeHistoricMatches(matches); + const messageChannel = client.channels.cache.get(NOTIF_CHANNEL_ID); + if (!messageChannel) { + throw 'Bad channel ID'; + } else if (messageChannel.type === ChannelType.GuildText) { + (messageChannel as TextChannel).send(`Sent ${matches.length} match(es).`); + } else { + throw 'Bad channel type'; + } } });