Skip to content
Merged
Changes from 1 commit
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
19 changes: 11 additions & 8 deletions commands/course.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ const get_real_course_name = (course) => {
};

const is_valid_course = (course) => {
const reg_valid_course = /^[a-zA-Z]{4}\d{4}$/;

return reg_valid_course.test(course);
};

const is_supported_course = (course) => {
const reg_comp_course = /^comp\d{4}$/;
const reg_math_course = /^math\d{4}$/;
const reg_binf_course = /^binf\d{4}$/;
Expand Down Expand Up @@ -86,17 +92,14 @@ module.exports = {
const input_course = await interaction.options.getString("course");
const course = get_real_course_name(input_course);

const other_courses = /^[a-zA-Z]{4}\d{4}$/;
const is_valid = is_valid_course(course);

if (!is_valid && other_courses.test(course.toLowerCase())) {
if (!is_valid_course(course)) {
return await interaction.reply({
content: `❌ | Course chats for other faculties are not supported.`,
content: `❌ | You are not allowed to join this channel using this command.`,
ephemeral: true,
});
} else if (!is_valid) {
} else if (!is_supported_course(course)) {
return await interaction.reply({
content: `❌ | You are not allowed to join this channel using this command.`,
content: `❌ | Course chats for other faculties are not supported.`,
ephemeral: true,
});
}
Expand Down Expand Up @@ -158,7 +161,7 @@ module.exports = {
const input_course = await interaction.options.getString("course");
const course = get_real_course_name(input_course);

if (!is_valid_course(course)) {
if (!is_supported_course(course)) {
return await interaction.reply({
content: `❌ | You are not allowed to leave this channel using this command.`,
ephemeral: true,
Expand Down