1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-09-29 16:30:59 -04:00
Daggerbot-TS/src/commands/bannedWords.ts

49 lines
2.6 KiB
TypeScript
Raw Normal View History

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({});
2023-04-24 08:03:05 -04:00
writeFileSync('src/database/bw_dump.json', JSON.stringify(findAll.map(i=>i._id), null, 2), {encoding: 'utf8', flag: 'w+'});
2023-03-11 05:18:08 -05:00
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')
.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')
.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')
.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')
.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')
.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
}