@@ -83,12 +83,17 @@ module.exports = {
83
83
async execute ( interaction ) {
84
84
try {
85
85
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 ( ) ;
87
87
const course = get_real_course_name ( input_course ) ;
88
88
89
89
const other_courses = / ^ [ a - z A - Z ] { 4 } \d { 4 } $ / ;
90
90
const is_valid = is_valid_course ( course ) ;
91
91
92
+ const course_with_alias =
93
+ course != input_course
94
+ ? `${ course } (same course chat as \`${ input_course } \`)`
95
+ : `${ course } ` ;
96
+
92
97
if ( ! is_valid && other_courses . test ( course . toLowerCase ( ) ) ) {
93
98
return await interaction . reply ( {
94
99
content : `❌ | Course chats for other faculties are not supported.` ,
@@ -101,7 +106,29 @@ module.exports = {
101
106
} ) ;
102
107
}
103
108
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
105
132
const channel = await interaction . guild . channels . cache . find (
106
133
( c ) => c . name . toLowerCase ( ) === course . toLowerCase ( ) ,
107
134
) ;
@@ -119,11 +146,6 @@ module.exports = {
119
146
} ) ;
120
147
}
121
148
122
- const course_with_alias =
123
- course != input_course
124
- ? `${ course } (alias for \`${ input_course } \`)`
125
- : `${ course } ` ;
126
-
127
149
const permissions = new Permissions (
128
150
channel . permissionsFor ( interaction . user . id ) . bitfield ,
129
151
) ;
0 commit comments