Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not match someone with themself if only one user has coffeechat role #486

Merged
merged 1 commit into from
Jun 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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