11import { GuildContext } from "guild-context" ;
2+ import { CourseImplementChannelType } from "models/implement/course" ;
23import moment from "moment" ;
34
5+ import { GuildStorageDatabaseService } from "./database/guild-storage" ;
46import { UserDatabaseService } from "./database/user" ;
7+ import { HealthAssuranceService } from "./health-assurance" ;
58import { MemberUpdateService } from "./member-update" ;
69
710export class ResetService {
8- constructor ( private guildContext : GuildContext ) {
11+ constructor ( private guildContext : GuildContext , private healthAssuranceService : HealthAssuranceService ) {
912 }
1013
1114 /**
@@ -17,7 +20,7 @@ export class ResetService {
1720 * @returns The number of members who had their courses unassigned.
1821 */
1922 public async resetCourseAssignments ( gracePeriodDays = 30 ) : Promise < number > {
20- this . guildContext . guildLog ( "!!! Reset initiated !" ) ;
23+ this . guildContext . guildLog ( "!!! Resetting Course Assignments !" ) ;
2124
2225 // Figure out who has not updated their assignments recently.
2326 let usersToReset = ( await UserDatabaseService . getAllUsers ( ) ) . filter ( user => {
@@ -41,8 +44,29 @@ export class ResetService {
4144 // This will automatically clean up any un-used courses as well.
4245 await MemberUpdateService . queueUnassignAllCoursesManyMembers ( this . guildContext , membersToReset ) ;
4346
44- this . guildContext . guildLog ( "!!! Reset complete !" ) ;
47+ this . guildContext . guildLog ( "!!! Course Assignment Reset Complete !" ) ;
4548
4649 return membersToReset . length ;
4750 }
51+
52+ public async wipeCourseChannels ( ) : Promise < void > {
53+ this . guildContext . guildLog ( "!!! Wiping Course Channels!" ) ;
54+
55+ // Delete all course text channels, since Discord does not expose a way to clear a channel.
56+ const guildStorage = await GuildStorageDatabaseService . findOrCreateGuildStorage ( this . guildContext ) ;
57+ for ( let majorImplement of guildStorage . majorImplements ) {
58+ let courseImplements = majorImplement [ 1 ] . courseImplements ;
59+ for ( let courseImplement of courseImplements ) {
60+ const channel = this . guildContext . guild . channels . resolve ( courseImplement [ 1 ] . channelIds [ CourseImplementChannelType . CHAT ] ) ;
61+ if ( channel ) {
62+ await channel . delete ( "StudyBot Course Wipe" ) ;
63+ }
64+ }
65+ }
66+
67+ // Re-build the deleted channels.
68+ await this . healthAssuranceService . guaranteeCourseImplements ( ) ;
69+
70+ this . guildContext . guildLog ( "!!! Course Channel Wipe Complete!" ) ;
71+ }
4872}
0 commit comments