From 24d39d471ef06d9097b55d2bbbcb8e8986fb6359 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Fri, 25 Nov 2022 18:53:03 +0100 Subject: [PATCH] /showblocklist --- README.md | 5 ++++- src/commands/blocklist.ts | 20 ++--------------- src/commands/ci.ts | 3 ++- src/commands/index.ts | 2 ++ src/commands/showblocklist.ts | 41 +++++++++++++++++++++++++++++++++++ 5 files changed, 51 insertions(+), 20 deletions(-) create mode 100644 src/commands/showblocklist.ts diff --git a/README.md b/README.md index ade423b..24c5b95 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Sets the channel where the bot will log if a channel meets the banned word crite ### /blocklist `Permission: MANAGE_GUILD` #### /blocklist get -Gets the global and server specific banned word list and returns it +Gets the global and server specific banned word list and returns it (Same behaviour as /showblocklist) #### /blocklist add [word] Adds the word to the server specific blocklist @@ -24,6 +24,9 @@ Options are: - Keep settings persistent even if the bot leaves - Delete setting when the bot leaves the server [default] +### /showblocklist `Permission: MANAGE_CHANNELS` +Gets the global and server specific banned word list and returns it + ## Environment variables | Name | Description | Required | Example | | :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ | diff --git a/src/commands/blocklist.ts b/src/commands/blocklist.ts index a90b102..6d6878f 100644 --- a/src/commands/blocklist.ts +++ b/src/commands/blocklist.ts @@ -5,6 +5,7 @@ import { getGuildSetting, isPremiumActive } from "../tools/data"; import getDefaultEmbed, { getFailedEmbed, getSuccessEmbed } from "../tools/defaultEmbeds"; import { getGuildChannel } from "../tools/discord"; import { Color, Emoji } from "../tools/design"; +import { execute as showBlocklistRunner } from "./showblocklist"; const builder = new SlashCommandBuilder(); builder.setName("blocklist"); @@ -51,24 +52,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise switch (interaction.options.getSubcommand(true)) { case "get": { - const guildBadWords = await database.getRepository(Badword).find({ - select: { - value: true - }, - where: { - guildID: interaction.guildId - } - }); - const globalBadWords = await database.getRepository(Badword).find({ - where: { - guildID: IsNull() - } - }); - - interaction.reply({ - content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/${isPremium ? 100 : 10})\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`, - ephemeral: true - }).catch(); + await showBlocklistRunner(interaction); break; } diff --git a/src/commands/ci.ts b/src/commands/ci.ts index 118f6a9..b32cf65 100644 --- a/src/commands/ci.ts +++ b/src/commands/ci.ts @@ -2,8 +2,9 @@ import * as notification from "./logchannel"; import * as blocklist from "./blocklist"; import * as info from "./info"; import * as preserveSettings from "./preserveSettings"; +import * as showBlocklist from "./showblocklist"; -const array = [notification.builder.toJSON(), blocklist.builder.toJSON(), info.builder.toJSON(), preserveSettings.builder.toJSON()]; +const array = [notification.builder.toJSON(), blocklist.builder.toJSON(), info.builder.toJSON(), preserveSettings.builder.toJSON(), showBlocklist.builder.toJSON()]; export { array diff --git a/src/commands/index.ts b/src/commands/index.ts index 1c75687..c9fc2f5 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -3,6 +3,7 @@ import * as notification from "./logchannel"; import * as blocklist from "./blocklist"; import * as info from "./info"; import * as preserveSettings from "./preserveSettings"; +import * as showBlocklist from "./showblocklist"; import client from "../client"; import getDefaultEmbed from "../tools/defaultEmbeds"; @@ -11,6 +12,7 @@ commands.set(notification.builder.name, notification); commands.set(blocklist.builder.name, blocklist); commands.set(info.builder.name, info); commands.set(preserveSettings.builder.name, preserveSettings); +commands.set(showBlocklist.builder.name, showBlocklist); client.on(Events.InteractionCreate, async (interaction) => { if (!interaction.isChatInputCommand()) return; diff --git a/src/commands/showblocklist.ts b/src/commands/showblocklist.ts new file mode 100644 index 0000000..347f9a4 --- /dev/null +++ b/src/commands/showblocklist.ts @@ -0,0 +1,41 @@ +import { ChatInputCommandInteraction, PermissionFlagsBits, SlashCommandBuilder } from "discord.js"; +import { IsNull } from "typeorm"; +import { Badword, database } from "../data"; +import { getGuildSetting, isPremiumActive } from "../tools/data"; + +const builder = new SlashCommandBuilder(); +builder.setName("showblocklist"); +builder.setDescription("Shows the blocklist of this server"); +builder.setDMPermission(false); +builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels); + +async function execute(interaction: ChatInputCommandInteraction): Promise { + if (!interaction.inGuild()) throw new Error("Command was executed outside guild context"); + + const settings = await getGuildSetting(interaction.guildId); + const isPremium = isPremiumActive(settings.isPremiumUntil); + + const guildBadWords = await database.getRepository(Badword).find({ + select: { + value: true + }, + where: { + guildID: interaction.guildId + } + }); + const globalBadWords = await database.getRepository(Badword).find({ + where: { + guildID: IsNull() + } + }); + + interaction.reply({ + content: `\`\`\`Global bad word list\`\`\`\n||${globalBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||\n\`\`\`Local server bad word list (${guildBadWords.length}/${isPremium ? 100 : 10})\`\`\`\n||${guildBadWords.map((word) => word.value).reduce((prev, next) => prev + ", " + next, "").slice(2)} ||`, + ephemeral: true + }).catch(); +} + +export { + builder, + execute +} \ No newline at end of file