1
0
mirror of https://github.com/toast-ts/Daggerbot-TS.git synced 2024-11-17 12:21:00 -05:00

Re-enable view subcmd for bannedWords.

This commit is contained in:
AnxietyisReal 2023-03-11 21:18:08 +11:00
parent 159b2c7118
commit 47fcc58dde
2 changed files with 12 additions and 5 deletions

View File

@ -1,9 +1,11 @@
import Discord,{SlashCommandBuilder} from 'discord.js';
import TClient from 'src/client';
import {writeFileSync} from 'node:fs';
import path from 'node:path';
export default {
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')
const word = interaction.options.getString('word', true);
const word = interaction.options.getString('word');
const wordExists = await client.bannedWords._content.findById(word);
({
add: async()=>{
@ -16,15 +18,19 @@ export default {
await client.bannedWords._content.findOneAndDelete({_id:word});
interaction.reply(`Successfully removed \`${word}\` from the database.`)
},
//view: ()=>interaction.reply({content: 'Here is a complete list of banned words!\n*You can open it with a web browser, e.g Chrome/Firefox/Safari, or you can use Visual Studio Code/Notepad++*', files: ['src/database/bannedWords.json'], ephemeral: true})
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}))
}
} as any)[interaction.options.getSubcommand()]();
},
data: new SlashCommandBuilder()
.setName('bannedwords')
.setDescription('description placeholder')/*
.setDescription('description placeholder')
.addSubcommand((opt)=>opt
.setName('view')
.setDescription('View the list of currently banned words.'))*/
.setDescription('View the list of currently banned words.'))
.addSubcommand((opt)=>opt
.setName('add')
.setDescription('What word do you want to add?')

View File

@ -26,7 +26,8 @@ client.on('ready', async()=>{
// Handle errors
function DZ(error:Error, location:string){// Yes, I may have shiternet but I don't need to wake up to like a hundred messages or so.
if (['getaddrinfo ENOTFOUND discord.com'].includes(error.message)) return;
const channel = client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel | null
//console.error(error);
const channel = client.channels.resolve(client.config.mainServer.channels.errors) as Discord.TextChannel | null;
channel?.send({embeds: [new client.embed().setColor('#420420').setTitle('Error caught!').setFooter({text: location}).setDescription(`**Error:** \`${error.message}\`\n\n**Stack:** \`${`${error.stack}`.slice(0, 2500)}\``)]})
}
process.on('unhandledRejection', (error: Error)=>DZ(error, 'unhandledRejection'));