@@ -25,7 +25,7 @@ import * as discordMessages from '../discordUtils/discordMessages';
2525import { DiscordManager } from '../managers/discordManager' ;
2626import * as types from '../utils/types' ;
2727import { Languages } from '../managers/LocaleManager' ;
28- import { GuildChannelIds , GuildInstance } from '../managers/guildInstanceManager' ;
28+ import { GuildChannelIds , GuildInstance , SettingsMessages } from '../managers/guildInstanceManager' ;
2929
3030const channelChoices = [
3131 'category' ,
@@ -68,26 +68,22 @@ export default {
6868 } ,
6969
7070 async execute ( dm : DiscordManager , interaction : discordjs . ChatInputCommandInteraction ) : Promise < boolean > {
71- const fn = '[SlashCommand: reset]' ;
72- const logParam = {
73- guildId : interaction . guildId
74- } ;
75-
71+ const guildId = interaction . guildId as types . GuildId ;
7672 const id = `Interaction ID: ${ interaction . id } -`
7773 await interaction . deferReply ( { flags : discordjs . MessageFlags . Ephemeral } ) ;
7874
7975 if ( ! interaction . guild ) {
8076 await discordMessages . sendDefaultMessage ( dm , interaction , 'errorTitleUnknownError' ,
8177 'errorDescUnknownError' ) ;
82- log . warn ( `${ fn } ${ id } Unknown Error: interaction.guild is not valid.` , logParam ) ;
78+ log . warn ( `${ id } Unknown Error: interaction.guild is not valid.` , { guildId : guildId } ) ;
8379 return false ;
8480 }
8581
8682 if ( ! dm . validPermissions ( interaction , true ) ) {
8783 await discordMessages . sendDefaultMessage ( dm , interaction , 'errorTitleMissingPermission' ,
8884 'errorDescMissingPermission' ) ;
89- log . warn ( `${ fn } ${ id } ${ lm . getIntl ( config . general . language , 'errorDescMissingPermission' ) } ` ,
90- logParam ) ;
85+ log . warn ( `${ id } ${ lm . getIntl ( config . general . language , 'errorDescMissingPermission' ) } ` ,
86+ { guildId : guildId } ) ;
9187 return false ;
9288 }
9389
@@ -107,7 +103,8 @@ export default {
107103 }
108104 await discordMessages . sendDefaultMessage ( dm , interaction , 'errorTitleInvalidSubcommand' ,
109105 'errorDescInvalidSubcommand' , parameters ) ;
110- log . warn ( `${ fn } ${ id } ${ lm . getIntl ( config . general . language , 'errorDescInvalidSubcommand' ) } ` , logParam ) ;
106+ log . warn ( `${ id } ${ lm . getIntl ( config . general . language , 'errorDescInvalidSubcommand' ) } ` ,
107+ { guildId : guildId } ) ;
111108 result = false ;
112109 } break ;
113110 }
@@ -118,12 +115,7 @@ export default {
118115
119116async function executeMissingChannels ( dm : DiscordManager , interaction : discordjs . ChatInputCommandInteraction ) :
120117 Promise < boolean > {
121- const fn = '[SlashCommand: reset: missing_channels]' ;
122118 const guildId = interaction . guildId as types . GuildId ;
123- const logParam = {
124- guildId : guildId
125- } ;
126-
127119 const id = `Interaction ID: ${ interaction . id } -`
128120
129121 const gInstance = gim . getGuildInstance ( guildId ) as GuildInstance ;
@@ -137,29 +129,36 @@ async function executeMissingChannels(dm: DiscordManager, interaction: discordjs
137129 }
138130
139131 resetChannels . push ( channelName ) ;
140- await dm . setupGuildChannel ( interaction . guild as discordjs . Guild , channelName as keyof GuildChannelIds , true ) ;
141- await setupChannel ( dm , interaction , channelName as keyof GuildChannelIds ) ;
132+
133+ if ( channelName === 'category' ) {
134+ await dm . setupGuildCategory ( interaction . guild as discordjs . Guild , true ) ;
135+ }
136+ else {
137+ await dm . setupGuildChannel ( interaction . guild as discordjs . Guild ,
138+ channelName as keyof GuildChannelIds , true ) ;
139+ gim . updateGuildInstance ( interaction . guildId as types . GuildId ) ;
140+ await setupChannel ( dm , interaction , channelName as keyof GuildChannelIds ) ;
141+ }
142+ }
143+
144+ if ( resetChannels . includes ( 'category' ) ) {
145+ await dm . setupGuildChannels ( interaction . guild as discordjs . Guild , true ) ;
142146 }
143147
144148 const parameters = {
145149 channels : resetChannels . join ( ', ' )
146150 } ;
147151 await discordMessages . sendDefaultMessage ( dm , interaction , 'slashCommandSuccessTitleResetMissingChannels' ,
148152 'slashCommandSuccessDescResetMissingChannels' , parameters ) ;
149- log . info ( `${ fn } ${ id } ${ lm . getIntl ( config . general . language , 'slashCommandSuccessDescResetMissingChannels' ,
150- parameters ) } `, logParam ) ;
153+ log . info ( `${ id } ${ lm . getIntl ( config . general . language , 'slashCommandSuccessDescResetMissingChannels' ,
154+ parameters ) } `, { guildId : guildId } ) ;
151155
152156 return true ;
153157}
154158
155159async function executeChannel ( dm : DiscordManager , interaction : discordjs . ChatInputCommandInteraction ) :
156160 Promise < boolean > {
157- const fn = '[SlashCommand: reset: channel]' ;
158161 const guildId = interaction . guildId as types . GuildId ;
159- const logParam = {
160- guildId : guildId
161- } ;
162-
163162 const id = `Interaction ID: ${ interaction . id } -`
164163 const channelName = interaction . options . getString ( 'channel' , true ) as keyof GuildChannelIds ;
165164
@@ -175,25 +174,38 @@ async function executeChannel(dm: DiscordManager, interaction: discordjs.ChatInp
175174 gim . updateGuildInstance ( guildId ) ;
176175 }
177176
178- await dm . setupGuildChannel ( interaction . guild as discordjs . Guild , channelName , true ) ;
179- await setupChannel ( dm , interaction , channelName ) ;
177+ if ( channelName === 'category' ) {
178+ await dm . setupGuildCategory ( interaction . guild as discordjs . Guild , true ) ;
179+ await dm . setupGuildChannels ( interaction . guild as discordjs . Guild , true ) ;
180+ }
181+ else {
182+ await dm . setupGuildChannel ( interaction . guild as discordjs . Guild , channelName , true ) ;
183+ gim . updateGuildInstance ( interaction . guildId as types . GuildId ) ;
184+ await setupChannel ( dm , interaction , channelName ) ;
185+ }
180186
181187 const parameters = {
182188 channel : channelName
183189 } ;
184190 await discordMessages . sendDefaultMessage ( dm , interaction , 'slashCommandSuccessTitleResetChannel' ,
185191 'slashCommandSuccessDescResetChannel' , parameters ) ;
186- log . info ( `${ fn } ${ id } ${ lm . getIntl ( config . general . language , 'slashCommandSuccessDescResetChannel' ,
187- parameters ) } `, logParam ) ;
192+ log . info ( `${ id } ${ lm . getIntl ( config . general . language , 'slashCommandSuccessDescResetChannel' ,
193+ parameters ) } `, { guildId : guildId } ) ;
188194
189195 return true ;
190196}
191197
192198async function setupChannel ( dm : DiscordManager , interaction : discordjs . ChatInputCommandInteraction ,
193199 channelName : keyof GuildChannelIds ) {
194200 const guild = interaction . guild as discordjs . Guild ;
201+ const gInstance = gim . getGuildInstance ( guild . id ) as GuildInstance ;
195202
196203 if ( channelName === 'settings' ) {
204+ ( Object . keys ( gInstance . settingsMessages ) as ( keyof SettingsMessages ) [ ] ) . forEach ( ( key ) => {
205+ gInstance . settingsMessages [ key ] = null ;
206+ } ) ;
207+ gim . updateGuildInstance ( guild . id ) ;
208+
197209 await dm . setupGuildSettingsChannel ( guild , true , true ) ;
198210 }
199211 else if ( channelName === 'servers' ) {
0 commit comments