From 47fcc58dde39aa73fafb1d4c11904e2eb72c289e Mon Sep 17 00:00:00 2001 From: AnxietyisReal <96593068+AnxietyisReal@users.noreply.github.com> Date: Sat, 11 Mar 2023 21:18:08 +1100 Subject: [PATCH] Re-enable view subcmd for bannedWords. --- src/commands/bannedWords.ts | 14 ++++++++++---- src/index.ts | 3 ++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/commands/bannedWords.ts b/src/commands/bannedWords.ts index d30bcb8..9d1810f 100644 --- a/src/commands/bannedWords.ts +++ b/src/commands/bannedWords.ts @@ -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?') diff --git a/src/index.ts b/src/index.ts index e05abcf..2c74c80 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'));