From cb5516246f0821604617f0c4c41e94c9c12bf5e4 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:05:24 +0100 Subject: [PATCH 1/6] Add user report Embed --- src/tools/defaultEmbeds.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/tools/defaultEmbeds.ts b/src/tools/defaultEmbeds.ts index 0b8c1b2..b7bd4a0 100644 --- a/src/tools/defaultEmbeds.ts +++ b/src/tools/defaultEmbeds.ts @@ -1,5 +1,5 @@ import pack from "../../package.json"; -import { EmbedBuilder } from "discord.js"; +import { EmbedBuilder, GuildTextBasedChannel } from "discord.js"; import client from "../client"; import { Color, Emoji } from "./design"; @@ -28,5 +28,17 @@ export function getFailedEmbed(): EmbedBuilder { const embed = getDefaultEmbed(); embed.setTitle(`${Emoji.CHAT_DENY} Failed`); embed.setColor(Color.STOPSIGN_RED); + return embed; +} + +export function getUserReportEmbed(channel: GuildTextBasedChannel): EmbedBuilder { + const embed = getDefaultEmbed(); + embed.setColor(Color.STOPSIGN_RED); + embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} A channel you modified has been deleted`); + embed.setDescription(`Hey there ${Emoji.WAVING} +You just modified a channel on the ${channel.guild.name} server. \ +However, your channel name (#${channel.name}) contained a word that is not allowed so your channel got deleted. +Please make sure to keep channel names friendly for everyone!`); + return embed; } \ No newline at end of file From eccb379b5162d097b263842e31cb407c2dc4a42b Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:21:00 +0100 Subject: [PATCH 2/6] Update user report embed --- src/tools/defaultEmbeds.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tools/defaultEmbeds.ts b/src/tools/defaultEmbeds.ts index b7bd4a0..dafbd86 100644 --- a/src/tools/defaultEmbeds.ts +++ b/src/tools/defaultEmbeds.ts @@ -31,13 +31,13 @@ export function getFailedEmbed(): EmbedBuilder { return embed; } -export function getUserReportEmbed(channel: GuildTextBasedChannel): EmbedBuilder { +export function getUserReportEmbed(guildName: string, channelName: string): EmbedBuilder { const embed = getDefaultEmbed(); embed.setColor(Color.STOPSIGN_RED); embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} A channel you modified has been deleted`); embed.setDescription(`Hey there ${Emoji.WAVING} -You just modified a channel on the ${channel.guild.name} server. \ -However, your channel name (#${channel.name}) contained a word that is not allowed so your channel got deleted. +You just modified a channel on the ${guildName} server. \ +However, your channel name (#${channelName}) contained a word that is not allowed so your channel got deleted. Please make sure to keep channel names friendly for everyone!`); return embed; From dbb64baae3f94e540279bd72076dd12a35602fb2 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:22:11 +0100 Subject: [PATCH 3/6] Send message to user when their channel gets deleted --- src/events/channelCreate.ts | 9 ++++++++- src/events/channelUpdate.ts | 9 ++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/events/channelCreate.ts b/src/events/channelCreate.ts index 0549c36..15a4d5a 100644 --- a/src/events/channelCreate.ts +++ b/src/events/channelCreate.ts @@ -3,7 +3,7 @@ import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User } import { getGuildSetting } from "../tools/data"; import { Badword, database } from "../data"; import { IsNull } from "typeorm"; -import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds"; +import getDefaultEmbed, { getFailedEmbed, getUserReportEmbed } from "../tools/defaultEmbeds"; import { getGuildChannel } from "../tools/discord"; import { Color, Emoji } from "../tools/design"; @@ -89,6 +89,13 @@ client.on(Events.ChannelCreate, async (newChannel) => { return; } + if (responsibleUser) { + const embed = getUserReportEmbed(guild.name, newChannel.name); + responsibleUser.send({ + embeds: [embed] + }).catch(() => {}); + } + if (!logChannel || !logChannel.isTextBased()) return; const embed = getDefaultEmbed(); embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`); diff --git a/src/events/channelUpdate.ts b/src/events/channelUpdate.ts index 9e297b2..99edb57 100644 --- a/src/events/channelUpdate.ts +++ b/src/events/channelUpdate.ts @@ -3,7 +3,7 @@ import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User } import { getGuildSetting } from "../tools/data"; import { Badword, database } from "../data"; import { IsNull } from "typeorm"; -import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds"; +import getDefaultEmbed, { getFailedEmbed, getUserReportEmbed } from "../tools/defaultEmbeds"; import { getGuildChannel } from "../tools/discord"; import { Color, Emoji } from "../tools/design"; @@ -89,6 +89,13 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => { return; } + if (responsibleUser) { + const embed = getUserReportEmbed(guild.name, newChannel.name); + responsibleUser.send({ + embeds: [embed] + }).catch(() => {}); + } + if (!logChannel || !logChannel.isTextBased()) return; const embed = getDefaultEmbed(); embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`); From 59429ea54850b96952efc803785e6882d7a7ae2e Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:26:28 +0100 Subject: [PATCH 4/6] Removed unused import --- src/tools/defaultEmbeds.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tools/defaultEmbeds.ts b/src/tools/defaultEmbeds.ts index dafbd86..5d13943 100644 --- a/src/tools/defaultEmbeds.ts +++ b/src/tools/defaultEmbeds.ts @@ -1,5 +1,5 @@ import pack from "../../package.json"; -import { EmbedBuilder, GuildTextBasedChannel } from "discord.js"; +import { EmbedBuilder } from "discord.js"; import client from "../client"; import { Color, Emoji } from "./design"; From 173438395e79445244f3a291b9b631070dcde4ef Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:30:25 +0100 Subject: [PATCH 5/6] Update env variable documentation --- README.md | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index ff0c8a5..d4f5e63 100644 --- a/README.md +++ b/README.md @@ -1,47 +1,61 @@ # eu.astrogd.white-leopard + A Discord bot that checks Discord channel names for banned words and prevents renaming of them ## Commands + ### /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 `Permission: MANAGE_GUILD` + #### /blocklist get + Returns 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 #### /blocklist remove [word] + Removes the word from the server specific blocklist ### /info `Permission: EVERYONE` + Returns general information about the bot and the servers stats ### /preservesettings `Permission: ADMINISTRATOR` + Changes the behaviour when the bot leaves the server. Options are: + - Keep settings persistent even if the bot leaves - Delete setting when the bot leaves the server [default] ### /showblocklist `Permission: MANAGE_CHANNELS` + Returns the global and server specific banned word list and returns it ### /showsettings `Permission: MANAGE_GUILD` + Returns the current settings for the server ## Environment variables + | Name | Description | Required | Example | | :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ | -| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... | -| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1:3546 | -| DB_USERNAME | Username of the database | ▶️ | root | -| DB_PASSWORD | Password of the database | ▶️ | abc123 | -| DB_DATABASE | Database name | ▶️ | white-leopard | -| CLIENT_ID | Client ID of the Discord appication associated with the token | 🚀 | 763035392692274 | -| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... | -| DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 | +| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... | +| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1 | +| DB_USERNAME | Username of the database | ▶️ | root | +| DB_PASSWORD | Password of the database | ▶️ | abc123 | +| DB_DATABASE | Database name | ▶️ | white-leopard | +| CLIENT_ID | Client ID of the Discord appication associated with the token | 🚀 | 763035392692274 | +| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... | +| DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 | + +### Icon explanation -### Icon explanation: - ▶️ = Required in runtime -- 🚀 = Required during CI/CD \ No newline at end of file +- 🚀 = Required during CI/CD From f34e06d31fac32496e00d816ab92ac552951974b Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:38:18 +0100 Subject: [PATCH 6/6] Format Readme --- README.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index d4f5e63..a5020d2 100644 --- a/README.md +++ b/README.md @@ -46,14 +46,14 @@ Returns the current settings for the server | Name | Description | Required | Example | | :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ | -| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... | -| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1 | -| DB_USERNAME | Username of the database | ▶️ | root | -| DB_PASSWORD | Password of the database | ▶️ | abc123 | -| DB_DATABASE | Database name | ▶️ | white-leopard | -| CLIENT_ID | Client ID of the Discord appication associated with the token | 🚀 | 763035392692274 | -| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... | -| DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 | +| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... | +| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1 | +| DB_USERNAME | Username of the database | ▶️ | root | +| DB_PASSWORD | Password of the database | ▶️ | abc123 | +| DB_DATABASE | Database name | ▶️ | white-leopard | +| CLIENT_ID | Client ID of the Discord appication associated with the token | 🚀 | 763035392692274 | +| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... | +| DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 | ### Icon explanation