-
Notifications
You must be signed in to change notification settings - Fork 1
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
Matcha groups size #42
base: master
Are you sure you want to change the base?
Changes from 2 commits
edfbf9a
8996f60
23c7207
461b72f
f7a9b86
b593ff0
697b688
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,9 @@ export default class Matcha extends Command { | |
constructor(client: BotClient) { | ||
const definition = new SlashCommandBuilder() | ||
.setName('matcha') | ||
.addIntegerOption(option => | ||
option.setName('groupsize').setDescription('Set the minimum group size').setRequired(true) | ||
) | ||
.setDescription( | ||
'Triggers matching for Matcha! Threads will be created in the channel where this command is called.' | ||
); | ||
|
@@ -104,17 +107,31 @@ export default class Matcha extends Command { | |
const shuffledMembersList = Matcha.shuffle(users); | ||
const memberPairings = []; | ||
|
||
const groupsize = interaction.options.getInteger('groupsize', true); | ||
Logger.error(`/matcha - ready to match ${shuffledMembersList}`); | ||
while (shuffledMembersList.length > 0) { | ||
let pairedMembers: GuildMember[]; | ||
if (shuffledMembersList.length % 2 === 1) { | ||
// If there's an odd number of people, we start with a group of 3 to correct it. | ||
pairedMembers = shuffledMembersList.splice(0, 3); | ||
const extraMembers = shuffledMembersList.length % groupsize; | ||
const numGroups = Math.floor(shuffledMembersList.length / groupsize); | ||
Logger.error(`/matcha - numGroups ${numGroups}, extraMembers: ${extraMembers} groupsize ${groupsize}`); | ||
if (extraMembers !== 0) { | ||
// If length % size is off add people to the first group or first n groups | ||
// for one group remaining add all extras | ||
if (numGroups === 1) { | ||
pairedMembers = shuffledMembersList.splice(0, shuffledMembersList.length); | ||
Logger.error(`/matcha - pair ${pairedMembers}`); | ||
} | ||
// otherwise, disperse extra people across groupss | ||
else { | ||
const addedToGroup = Math.floor(extraMembers / numGroups); | ||
pairedMembers = shuffledMembersList.splice(0, groupsize + addedToGroup); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think we can make this code more clear by breaking the code out into a helper function (maybe Additionally, I think we need to consider edge cases here:
|
||
} else { | ||
pairedMembers = shuffledMembersList.splice(0, 2); | ||
pairedMembers = shuffledMembersList.splice(0, groupsize); | ||
} | ||
memberPairings.push(pairedMembers); | ||
} | ||
|
||
Logger.error(`/matcha - matching worked? ${memberPairings}`); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. again here, i don't think we need this logging anymore ^ |
||
/** | ||
* To prevent ourselves from hitting Discord's API rate limit (50 requests/second), | ||
* we add a small delay between each creation of a group thread and execute them | ||
|
@@ -181,6 +198,17 @@ export default class Matcha extends Command { | |
await super.edit(interaction, { content: '/matcha was canceled!', components: [] }); | ||
return; | ||
} | ||
const groupsize = interaction.options.getInteger('groupsize', true); | ||
|
||
if (groupsize <= 1) { | ||
await super.edit(interaction, { | ||
content: 'You need to enter an integer greater than 1 otherwise your only friend will be yourself :angry:', | ||
components: [], | ||
ephemeral: true, | ||
}); | ||
return; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: I think we can rewrite this error message to be more in line with what our other messages look like Instead of integer, we can say "group size", and also add some punctuation
|
||
|
||
// Otherwise, the 'Confirm' button was called. | ||
this.lastRun = DateTime.now(); | ||
// Remove the button so they can't press it again. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ export default createLogger({ | |
format: json(), | ||
transports: [ | ||
new Transports.Console({ | ||
level: 'debug', | ||
level: 'error', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. delete |
||
format: | ||
process.env.NODE_ENV === 'development' ? combine(colorize(), consoleLogFormat) : combine(timestamp(), json()), | ||
}), | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this Logger.error here? Is this a logging statement we can remove?