Skip to content

Commit 2294030

Browse files
committed
courses: remove courses via roles
1 parent 2b2f1e8 commit 2294030

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

commands/course.js

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const COMMAND_LEAVE = "leave";
77

88
// map of course aliases to their actual names
99
const course_aliases = {
10-
comp6841: "comp6841",
10+
comp6841: "comp6441",
1111
comp9044: "comp2041",
1212
comp3891: "comp3231",
1313
comp9201: "comp3231",
@@ -91,7 +91,7 @@ module.exports = {
9191

9292
const course_with_alias =
9393
course != input_course
94-
? `${course} (same course chat as \`${input_course}\`)`
94+
? `${course} (same course chat as ${input_course})`
9595
: `${course}`;
9696

9797
if (!is_valid && other_courses.test(course.toLowerCase())) {
@@ -187,12 +187,34 @@ module.exports = {
187187
});
188188
}
189189

190+
// First, let's see if there's a role that matches the name of the course
191+
const role = await interaction.guild.roles.cache.find(
192+
(r) => r.name.toLowerCase() === course.toLowerCase(),
193+
);
194+
195+
// If there is, let's see if the member already has that role
196+
if (role !== undefined) {
197+
if (!interaction.member.roles.cache.has(role.id)) {
198+
return await interaction.reply({
199+
content: `❌ | You are not in the course chat for \`${course}\`.`,
200+
ephemeral: true,
201+
});
202+
}
203+
204+
// If they do, let's remove the role from them
205+
await interaction.member.roles.remove(role);
206+
return await interaction.reply({
207+
content: `✅ | Removed you from the chat for \`${course}\`.`,
208+
ephemeral: true,
209+
});
210+
}
211+
190212
// Find a channel with the same name as the course
191213
const channel = await interaction.guild.channels.cache.find(
192214
(c) => c.name.toLowerCase() === course.toLowerCase(),
193215
);
194216

195-
// Make sure that the channel exists, and is a text channel
217+
// Otherwise, make sure that the channel exists, and is a text channel
196218
if (channel === undefined) {
197219
return await interaction.reply({
198220
content: `❌ | The course chat for \`${course}\` does not exist.`,

0 commit comments

Comments
 (0)