Skip to content

Commit

Permalink
do not match someone with themself if only one user has coffechat role (
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan-Yang-284 authored Jun 18, 2023
1 parent 66ed6ab commit 1faadee
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/commands/coffeeChat/coffeeChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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' },
Expand All @@ -32,6 +30,8 @@ export class CoffeeChatCommand extends Subcommand {
async match(message: Message): Promise<Message> {
//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).`);
Expand Down
1 change: 1 addition & 0 deletions src/components/coffeeChat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ interface historic_match {
export const getMatch = async (): Promise<string[][]> => {
// 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<string, number> = new Map();
Expand Down
21 changes: 12 additions & 9 deletions src/components/cron.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}
}
});

Expand Down

0 comments on commit 1faadee

Please sign in to comment.