33 ChannelType ,
44 PermissionFlagsBits ,
55 SlashCommandBuilder ,
6+ inlineCode ,
67} from 'discord.js' ;
8+ import { client } from 'index.js' ;
79import type { Config } from '../base/Command.js' ;
810import Command from '../base/Command.js' ;
911
@@ -68,7 +70,9 @@ export default class Ping extends Command {
6870 . addSubcommand ( subcommand =>
6971 subcommand
7072 . setName ( 'ban-approvals' )
71- . setDescription ( 'Set ban approvals' )
73+ . setDescription (
74+ 'Set the numbers of ban approvals needed to ban the user.'
75+ )
7276 . addNumberOption ( numberOption =>
7377 numberOption
7478 . setName ( 'ban-approvals-setting' )
@@ -94,6 +98,31 @@ export default class Ping extends Command {
9498 )
9599 . setRequired ( true )
96100 )
101+ )
102+ . addSubcommand ( subcommand =>
103+ subcommand
104+ . setName ( 'enabled-commands' )
105+ . setDescription ( 'Toggle active state of commands' )
106+ . addStringOption ( stringOption =>
107+ stringOption
108+ . setName ( 'command-name' )
109+ . setDescription (
110+ 'The command name to toggle on/off.'
111+ )
112+ . setRequired ( true )
113+ . setChoices (
114+ ...client . commands . map ( command => ( {
115+ name : command . name ,
116+ value : command . name ,
117+ } ) )
118+ )
119+ )
120+ . addBooleanOption ( booleanOption =>
121+ booleanOption
122+ . setName ( 'enabled' )
123+ . setDescription ( 'Set the status' )
124+ . setRequired ( true )
125+ )
97126 ) ;
98127
99128 super ( cmd as unknown as Config ) ;
@@ -112,6 +141,9 @@ export default class Ping extends Command {
112141 case 'welcome-message' :
113142 this . setWelcomeMessage ( interaction ) ;
114143 break ;
144+ case 'enabled-commands' :
145+ this . setEnabledCommand ( interaction ) ;
146+ break ;
115147 default :
116148 break ;
117149 }
@@ -120,7 +152,7 @@ export default class Ping extends Command {
120152 private async setSetting (
121153 guildId : string ,
122154 setting : string ,
123- value : string | number
155+ value : string | string [ ] | number
124156 ) {
125157 await this . db . guildSettings . upsert ( {
126158 where : {
@@ -149,40 +181,55 @@ export default class Ping extends Command {
149181 }
150182
151183 private async setChannel ( interaction : ChatInputCommandInteraction ) {
152- const setting = interaction . options . getString ( 'channel-setting' ) ;
184+ if ( ! interaction . guildId ) return ;
185+ const setting = interaction . options . getString ( 'channel-setting' , true ) ;
153186 const channel = interaction . options . getChannel ( 'channel' , true ) ;
154187
155- await this . setSetting (
156- interaction . guildId as string ,
157- setting as string ,
158- channel . id
159- ) ;
188+ await this . setSetting ( interaction . guildId , setting , channel . id ) ;
160189
161190 interaction . reply ( `${ setting } set to ${ channel } ` ) ;
162191 }
163192
164193 private async setRole ( interaction : ChatInputCommandInteraction ) {
165- const setting = interaction . options . getString ( 'role-setting' ) ;
194+ if ( ! interaction . guildId ) return ;
195+ const setting = interaction . options . getString ( 'role-setting' , true ) ;
166196 const role = interaction . options . getRole ( 'role' , true ) ;
167197
168- await this . setSetting (
169- interaction . guildId as string ,
170- setting as string ,
171- role . id
172- ) ;
198+ await this . setSetting ( interaction . guildId , setting , role . id ) ;
173199
174200 interaction . reply ( `${ setting } set to ${ role } ` ) ;
175201 }
176202
177203 private async setWelcomeMessage ( interaction : ChatInputCommandInteraction ) {
204+ if ( ! interaction . guildId ) return ;
178205 const welcomeMessage = interaction . options . getString (
179- 'welcome-message-setting'
206+ 'welcome-message-setting' ,
207+ true
180208 ) ;
181209 await this . setSetting (
182- interaction . guildId as string ,
210+ interaction . guildId ,
183211 'welcomeMessage' ,
184- welcomeMessage as string
212+ welcomeMessage
185213 ) ;
186214 interaction . reply ( `welcomeMessage set to ${ welcomeMessage } ` ) ;
187215 }
216+
217+ private async setEnabledCommand ( interaction : ChatInputCommandInteraction ) {
218+ if ( ! interaction . guildId ) return ;
219+ const commandName = interaction . options . getString ( 'command-name' , true ) ;
220+ const isEnabled = interaction . options . getBoolean ( 'enabled' , true ) ;
221+ const guildSettings = await this . getGuildSettings ( interaction . guildId ) ;
222+ if ( ! guildSettings ) return ;
223+ const disabledCommands = new Set ( guildSettings . disabledCommands ) ;
224+
225+ if ( isEnabled ) disabledCommands . delete ( commandName ) ;
226+ else disabledCommands . add ( commandName ) ;
227+ await this . setSetting ( interaction . guildId , 'disabledCommands' , [
228+ ...disabledCommands ,
229+ ] ) ;
230+
231+ interaction . reply (
232+ `disabledCommands set to ${ inlineCode ( [ ...disabledCommands ] . join ( ', ' ) ) } `
233+ ) ;
234+ }
188235}
0 commit comments