From 966625bac430316f9f553d33f93d7fe099a2c26a Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Fri, 25 Nov 2022 18:41:15 +0100 Subject: [PATCH 1/3] Change logchannel default permission --- src/commands/ci.ts | 2 +- src/commands/index.ts | 2 +- src/commands/{notification.ts => logchannel.ts} | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename src/commands/{notification.ts => logchannel.ts} (98%) diff --git a/src/commands/ci.ts b/src/commands/ci.ts index 0c6db03..118f6a9 100644 --- a/src/commands/ci.ts +++ b/src/commands/ci.ts @@ -1,4 +1,4 @@ -import * as notification from "./notification"; +import * as notification from "./logchannel"; import * as blocklist from "./blocklist"; import * as info from "./info"; import * as preserveSettings from "./preserveSettings"; diff --git a/src/commands/index.ts b/src/commands/index.ts index 589dcfd..1c75687 100644 --- a/src/commands/index.ts +++ b/src/commands/index.ts @@ -1,5 +1,5 @@ import { ChatInputCommandInteraction, Collection, Events, SlashCommandBuilder } from "discord.js"; -import * as notification from "./notification"; +import * as notification from "./logchannel"; import * as blocklist from "./blocklist"; import * as info from "./info"; import * as preserveSettings from "./preserveSettings"; diff --git a/src/commands/notification.ts b/src/commands/logchannel.ts similarity index 98% rename from src/commands/notification.ts rename to src/commands/logchannel.ts index edf73c7..d9ac245 100644 --- a/src/commands/notification.ts +++ b/src/commands/logchannel.ts @@ -9,7 +9,7 @@ const builder = new SlashCommandBuilder(); builder.setName("logchannel"); builder.setDescription("Configures the log channel"); builder.setDMPermission(false); -builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageChannels); +builder.setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild); builder.addChannelOption((option) => { option.addChannelTypes(ChannelType.GuildText, ChannelType.GuildAnnouncement); option.setName("channel"); From 545bda9bee5394fe6b68112d95d61af1f9512bb7 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Fri, 25 Nov 2022 18:41:34 +0100 Subject: [PATCH 2/3] Document default permissions --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 19c40e0..ade423b 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,10 @@ A Discord bot that checks Discord channel names for banned words and prevents renaming of them ## Commands -### /logchanel [channel?] +### /logchanel [channel?] `Permission: MANAGE_GUILD` Sets the channel where the bot will log if a channel meets the banned word criteria. If channel is omitted, the log channel will be disabled. -### /blocklist +### /blocklist `Permission: MANAGE_GUILD` #### /blocklist get Gets the global and server specific banned word list and returns it @@ -15,10 +15,10 @@ Adds the word to the server specific blocklist #### /blocklist remove [word] Removes the word from the server specific blocklist -### /info +### /info `Permission: EVERYONE` Returns general information about the bot and the servers stats -### /preservesettings +### /preservesettings `Permission: ADMINISTRATOR` Changes the behaviour when the bot leaves the server. Options are: - Keep settings persistent even if the bot leaves From 24d39d471ef06d9097b55d2bbbcb8e8986fb6359 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Fri, 25 Nov 2022 18:53:03 +0100 Subject: [PATCH 3/3] /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