@@ -83,12 +83,17 @@ module.exports = {
8383 async execute ( interaction ) {
8484 try {
8585 if ( interaction . options . getSubcommand ( ) === COMMAND_JOIN ) {
86- const input_course = await interaction . options . getString ( "course" ) ;
86+ const input_course = await interaction . options . getString ( "course" ) . toLowerCase ( ) ;
8787 const course = get_real_course_name ( input_course ) ;
8888
8989 const other_courses = / ^ [ a - z A - Z ] { 4 } \d { 4 } $ / ;
9090 const is_valid = is_valid_course ( course ) ;
9191
92+ const course_with_alias =
93+ course != input_course
94+ ? `${ course } (same course chat as \`${ input_course } \`)`
95+ : `${ course } ` ;
96+
9297 if ( ! is_valid && other_courses . test ( course . toLowerCase ( ) ) ) {
9398 return await interaction . reply ( {
9499 content : `❌ | Course chats for other faculties are not supported.` ,
@@ -101,7 +106,29 @@ module.exports = {
101106 } ) ;
102107 }
103108
104- // Find a channel with the same name as the course
109+ // First, let's see if there's a role that matches the name of the course
110+ const role = await interaction . guild . roles . cache . find (
111+ ( r ) => r . name . toLowerCase ( ) === course . toLowerCase ( ) ,
112+ ) ;
113+
114+ // If there is, let's see if the member already has that role
115+ if ( role !== undefined ) {
116+ if ( interaction . member . roles . cache . has ( role . id ) ) {
117+ return await interaction . reply ( {
118+ content : `❌ | You are already in the course chat for \`${ course_with_alias } \`.` ,
119+ ephemeral : true ,
120+ } ) ;
121+ }
122+
123+ // If they don't, let's add the role to them
124+ await interaction . member . roles . add ( role ) ;
125+ return await interaction . reply ( {
126+ content : `✅ | Added you to the chat for \`${ course_with_alias } \`.` ,
127+ ephemeral : true ,
128+ } ) ;
129+ }
130+
131+ // Otherwise, find a channel with the same name as the course
105132 const channel = await interaction . guild . channels . cache . find (
106133 ( c ) => c . name . toLowerCase ( ) === course . toLowerCase ( ) ,
107134 ) ;
@@ -119,11 +146,6 @@ module.exports = {
119146 } ) ;
120147 }
121148
122- const course_with_alias =
123- course != input_course
124- ? `${ course } (alias for \`${ input_course } \`)`
125- : `${ course } ` ;
126-
127149 const permissions = new Permissions (
128150 channel . permissionsFor ( interaction . user . id ) . bitfield ,
129151 ) ;
0 commit comments