2022-12-22 02:19:56 -05:00
import Discord , { SlashCommandBuilder } from 'discord.js' ;
2023-04-14 06:47:58 -04:00
import TClient from '../client.js' ;
2023-03-11 05:18:08 -05:00
import { writeFileSync } from 'node:fs' ;
import path from 'node:path' ;
2022-12-22 02:19:56 -05:00
export default {
2023-03-05 05:04:10 -05:00
async run ( client : TClient , interaction : Discord.ChatInputCommandInteraction < 'cached' > ) {
if ( ! client . isStaff ( interaction . member ) && ! client . config . eval . whitelist . includes ( interaction . member . id ) ) return client . youNeedRole ( interaction , 'admin' )
2023-03-11 05:18:08 -05:00
const word = interaction . options . getString ( 'word' ) ;
2023-03-05 05:04:10 -05:00
const wordExists = await client . bannedWords . _content . findById ( word ) ;
( {
add : async ( ) = > {
if ( wordExists ) return interaction . reply ( { content : ` \` ${ word } \` is already added. ` , ephemeral : true } ) ;
2023-03-09 20:32:29 -05:00
await client . bannedWords . _content . create ( { _id :word } ) . then ( a = > a . save ( ) ) . catch ( e = > { if ( e . name == 'No document found for query' ) return } ) ;
2023-03-05 05:04:10 -05:00
interaction . reply ( ` Successfully added \` ${ word } \` to the database. ` )
} ,
remove : async ( ) = > {
if ( ! wordExists ) return interaction . reply ( { content : ` \` ${ word } \` doesn't exist on the list. ` , ephemeral : true } ) ;
await client . bannedWords . _content . findOneAndDelete ( { _id :word } ) ;
interaction . reply ( ` Successfully removed \` ${ word } \` from the database. ` )
} ,
2023-03-11 05:18:08 -05:00
view : async ( ) = > {
const findAll = await client . bannedWords . _content . find ( { } ) ;
writeFileSync ( path . join ( __dirname , '../database/bw_dump.json' ) , JSON . stringify ( findAll . map ( i = > i . _id ) , null , 2 ) , { encoding : 'utf8' , flag : 'w+' } ) ;
interaction . reply ( { content : 'Here\'s the dump file from the database.' , files : [ 'src/database/bw_dump.json' ] , ephemeral : true } ) . catch ( err = > interaction . reply ( { content : ` Ran into an error, notify <@& ${ client . config . mainServer . roles . bottech } > if it happens again: \ n \` ${ err . message } \` ` , ephemeral : true } ) )
}
2023-03-05 05:04:10 -05:00
} as any ) [ interaction . options . getSubcommand ( ) ] ( ) ;
} ,
data : new SlashCommandBuilder ( )
. setName ( 'bannedwords' )
2023-03-11 05:18:08 -05:00
. setDescription ( 'description placeholder' )
2023-04-24 06:10:11 -04:00
. addSubcommand ( opt = > opt
2023-03-05 05:04:10 -05:00
. setName ( 'view' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'View the list of currently banned words' ) )
2023-04-24 06:10:11 -04:00
. addSubcommand ( opt = > opt
2023-03-05 05:04:10 -05:00
. setName ( 'add' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'Add the word to the list' )
2023-04-24 06:10:11 -04:00
. addStringOption ( optt = > optt
2023-03-05 05:04:10 -05:00
. setName ( 'word' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'Add the specific word to automod\'s bannedWords database' )
2023-03-05 05:04:10 -05:00
. setRequired ( true ) ) )
2023-04-24 06:10:11 -04:00
. addSubcommand ( opt = > opt
2023-03-05 05:04:10 -05:00
. setName ( 'remove' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'Remove the word from the list' )
2023-04-24 06:10:11 -04:00
. addStringOption ( optt = > optt
2023-03-05 05:04:10 -05:00
. setName ( 'word' )
2023-03-29 07:21:46 -04:00
. setDescription ( 'Remove the specific word from automod\'s bannedWords list' )
2023-03-05 05:04:10 -05:00
. setRequired ( true ) ) )
2022-12-22 02:19:56 -05:00
}