@@ -12,12 +12,32 @@ export class CourseChannelImplementService {
1212 categoryId : string ,
1313 mainRoleId : string ,
1414 taRoleId : string ) : Promise < Discord . Channel > {
15+ let discordChannelType : any ;
16+ let topic = null ;
17+
1518 switch ( type ) {
1619 case CourseImplementChannelType . CHAT :
17- return this . createChatChannel ( guildContext , course , categoryId , mainRoleId , taRoleId ) ;
20+ discordChannelType = "text" ;
21+ topic = course . title ? `:information_source: ${ course . title } ` : "" ;
22+ break ;
1823 case CourseImplementChannelType . VOICE :
19- return this . createVoiceChannel ( guildContext , course , categoryId , mainRoleId , taRoleId ) ;
24+ discordChannelType = "voice" ;
25+ break ;
2026 }
27+
28+ const channel = await guildContext . guild . channels . create (
29+ CourseUtils . getChannelNameByType ( course , type ) ,
30+ {
31+ type : discordChannelType ,
32+ topic : topic ,
33+ parent : categoryId ,
34+ position : 0 ,
35+ permissionOverwrites : this . generateChannelPermissionsByType ( guildContext , type , mainRoleId , taRoleId ) ,
36+ reason : "StudyBot automatic course channel creation." ,
37+ }
38+ ) ;
39+
40+ return channel ;
2141 }
2242
2343 public static async resetChannelPermissionsByType (
@@ -36,9 +56,10 @@ export class CourseChannelImplementService {
3656 mainRoleId : string ,
3757 taRoleId : string
3858 ) : Discord . OverwriteResolvable [ ] {
59+ let permissions : Discord . OverwriteResolvable [ ] = [ ] ;
3960 switch ( type ) {
4061 case CourseImplementChannelType . CHAT :
41- return [
62+ permissions = [
4263 {
4364 type : "role" ,
4465 id : guildContext . guild . roles . everyone . id ,
@@ -60,8 +81,17 @@ export class CourseChannelImplementService {
6081 allow : [ "VIEW_CHANNEL" ]
6182 }
6283 ] ;
84+
85+ if ( guildContext . guildConfig . studentAdvisoryCommittee ) {
86+ permissions . push ( {
87+ type : "role" ,
88+ id : guildContext . guildConfig . studentAdvisoryCommittee . roleId ,
89+ allow : [ "VIEW_CHANNEL" ]
90+ } ) ;
91+ }
92+ break ;
6393 case CourseImplementChannelType . VOICE :
64- return [
94+ permissions = [
6595 {
6696 type : "role" ,
6797 id : guildContext . guild . roles . everyone . id ,
@@ -84,47 +114,17 @@ export class CourseChannelImplementService {
84114 allow : [ "VIEW_CHANNEL" ]
85115 }
86116 ] ;
87- }
88- }
89-
90- public static async createChatChannel (
91- guildContext : GuildContext ,
92- course : Course ,
93- categoryId : string ,
94- mainRoleId : string ,
95- taRoleId : string ) : Promise < Discord . TextChannel > {
96- const channel = await guildContext . guild . channels . create (
97- CourseUtils . getChatChannelName ( course ) ,
98- {
99- type : "text" ,
100- topic : `:information_source: ${ course . title } ` ,
101- parent : categoryId ,
102- position : 0 ,
103- permissionOverwrites : this . generateChannelPermissionsByType ( guildContext , CourseImplementChannelType . CHAT , mainRoleId , taRoleId ) ,
104- reason : "StudyBot automatic course channel creation." ,
105- }
106- ) ;
107-
108- return channel ;
109- }
110-
111- public static async createVoiceChannel (
112- guildContext : GuildContext ,
113- course : Course ,
114- categoryId : string ,
115- mainRoleId : string ,
116- taRoleId : string ) : Promise < Discord . VoiceChannel > {
117- const channel = await guildContext . guild . channels . create (
118- CourseUtils . getVoiceChannelName ( course ) ,
119- {
120- type : "voice" ,
121- parent : categoryId ,
122- position : 0 ,
123- permissionOverwrites : this . generateChannelPermissionsByType ( guildContext , CourseImplementChannelType . VOICE , mainRoleId , taRoleId ) ,
124- reason : "StudyBot automatic course channel creation." ,
125- }
126- ) ;
127117
128- return channel ;
118+ if ( guildContext . guildConfig . studentAdvisoryCommittee ) {
119+ permissions . push ( {
120+ type : "role" ,
121+ id : guildContext . guildConfig . studentAdvisoryCommittee . roleId ,
122+ allow : [ "VIEW_CHANNEL" , "SPEAK" , "STREAM" ]
123+ } ) ;
124+ }
125+ break ;
126+ }
127+
128+ return permissions ;
129129 }
130130}
0 commit comments