11const { SlashCommandBuilder } = require ( "@discordjs/builders" ) ;
2+ const { ChannelType } = require ( "discord.js" ) ;
23
34const COMMAND_JOIN = "join" ;
45const COMMAND_LEAVE = "leave" ;
@@ -35,20 +36,26 @@ const get_real_course_name = (course) => {
3536} ;
3637
3738const is_valid_course = ( course ) => {
38- const reg_comp_course = / ^ c o m p \d { 4 } $ / ;
39- const reg_math_course = / ^ m a t h \d { 4 } $ / ;
40- const reg_binf_course = / ^ b i n f \d { 4 } $ / ;
41- const reg_engg_course = / ^ e n g g \d { 4 } $ / ;
42- const reg_seng_course = / ^ s e n g \d { 4 } $ / ;
43- const reg_desn_course = / ^ d e s n \d { 4 } $ / ;
39+ const reg_valid_course = / ^ [ a - z A - Z ] { 4 } \d { 4 } $ / ;
40+
41+ return reg_valid_course . test ( course ) ;
42+ } ;
43+
44+ const is_supported_course = ( course ) => {
45+ const reg_comp_course = / ^ c o m p \d { 4 } $ / i;
46+ const reg_math_course = / ^ m a t h \d { 4 } $ / i;
47+ const reg_binf_course = / ^ b i n f \d { 4 } $ / i;
48+ const reg_engg_course = / ^ e n g g \d { 4 } $ / i;
49+ const reg_seng_course = / ^ s e n g \d { 4 } $ / i;
50+ const reg_desn_course = / ^ d e s n \d { 4 } $ / i;
4451
4552 return (
46- reg_comp_course . test ( course . toLowerCase ( ) ) ||
47- reg_math_course . test ( course . toLowerCase ( ) ) ||
48- reg_binf_course . test ( course . toLowerCase ( ) ) ||
49- reg_engg_course . test ( course . toLowerCase ( ) ) ||
50- reg_seng_course . test ( course . toLowerCase ( ) ) ||
51- reg_desn_course . test ( course . toLowerCase ( ) )
53+ reg_comp_course . test ( course ) ||
54+ reg_math_course . test ( course ) ||
55+ reg_binf_course . test ( course ) ||
56+ reg_engg_course . test ( course ) ||
57+ reg_seng_course . test ( course ) ||
58+ reg_desn_course . test ( course )
5259 ) ;
5360} ;
5461
@@ -87,20 +94,20 @@ module.exports = {
8794 const input_course = await interaction . options . getString ( "course" ) . toLowerCase ( ) ;
8895 const course = get_real_course_name ( input_course ) ;
8996
90- const other_courses = / ^ [ a - z A - Z ] { 4 } \d { 4 } $ / ;
9197 const is_valid = is_valid_course ( course ) ;
98+ const is_supported = is_supported_course ( course ) ;
9299
93100 const course_with_alias =
94101 course != input_course
95102 ? `${ course } (same course chat as ${ input_course } )`
96103 : `${ course } ` ;
97104
98- if ( ! is_valid && other_courses . test ( course . toLowerCase ( ) ) ) {
105+ if ( ! is_supported && is_valid ) {
99106 return await interaction . reply ( {
100107 content : `❌ | Course chats for other faculties are not supported.` ,
101108 ephemeral : true ,
102109 } ) ;
103- } else if ( ! is_valid ) {
110+ } else if ( ! is_supported ) {
104111 return await interaction . reply ( {
105112 content : `❌ | You are not allowed to join this channel using this command.` ,
106113 ephemeral : true ,
@@ -138,7 +145,7 @@ module.exports = {
138145 const input_course = await interaction . options . getString ( "course" ) ;
139146 const course = get_real_course_name ( input_course ) ;
140147
141- if ( ! is_valid_course ( course ) ) {
148+ if ( ! is_supported_course ( course ) ) {
142149 return await interaction . reply ( {
143150 content : `❌ | Not a valid course.` ,
144151 ephemeral : true ,
@@ -155,7 +162,7 @@ module.exports = {
155162 content : `❌ | The course chat for \`${ course } \` does not exist.` ,
156163 ephemeral : true ,
157164 } ) ;
158- } else if ( channel . type !== "GUILD_TEXT" ) {
165+ } else if ( channel . type !== ChannelType . GuildText ) {
159166 return await interaction . reply ( {
160167 content : `❌ | The course chat for \`${ course } \` is not a text channel.` ,
161168 ephemeral : true ,
0 commit comments