From cb5516246f0821604617f0c4c41e94c9c12bf5e4 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 19:05:24 +0100 Subject: [PATCH 01/12] 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 02/12] 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 03/12] 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 04/12] 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 05/12] 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 06/12] 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 From 451b414fba704f9457977b50678316f494ba0f88 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 20:55:03 +0100 Subject: [PATCH 07/12] Bump version number --- Changelog.md | 14 ++++++++++++-- package.json | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/Changelog.md b/Changelog.md index 7b98e9b..a0d4fd7 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,9 +1,19 @@ # Changelog + This file is used to list changes made to this software. -## V1.0.0 [2022-11-29] -_Current development version: **1.0.0**_ +_Current development release: 1.1.0-alpha.1_ + +## V1.1.0 [`Unreleased`] + ### Features + +- If a channel gets deleted and the responsible user has been detected, a message will be sent to that user informing him of the deletion + +## V1.0.0 [2022-11-29] + +### Features + - /info - /logchannel - /blocklist get diff --git a/package.json b/package.json index a22723b..669c01d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eu.astrogd.white-leopard", - "version": "1.0.0", + "version": "1.1.0-alpha.1", "description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary", "main": "build/index.js", "scripts": { From b1b087e32c2deee19974dc1181200b7a73165831 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 21:00:09 +0100 Subject: [PATCH 08/12] Update reportEmbed wording --- src/tools/defaultEmbeds.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tools/defaultEmbeds.ts b/src/tools/defaultEmbeds.ts index 5d13943..b213bb5 100644 --- a/src/tools/defaultEmbeds.ts +++ b/src/tools/defaultEmbeds.ts @@ -36,8 +36,7 @@ export function getUserReportEmbed(guildName: string, channelName: string): Embe 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 ${guildName} server. \ -However, your channel name (#${channelName}) contained a word that is not allowed so your channel got deleted. +Your channel (#${channelName}) on the "${guildName}" server contained a blacklisted word and was deleted automatically. Please make sure to keep channel names friendly for everyone!`); return embed; From cb4bddf98361d8ee6ea2df98cefbe5fce10a5189 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 21:00:36 +0100 Subject: [PATCH 09/12] Bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 669c01d..4b51524 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eu.astrogd.white-leopard", - "version": "1.1.0-alpha.1", + "version": "1.1.0-alpha.2", "description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary", "main": "build/index.js", "scripts": { From ccf2fd9361f0c6bea35445011d2eff31e1dbf1dd Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 21:33:13 +0100 Subject: [PATCH 10/12] Bump version number --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 4b51524..377f149 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eu.astrogd.white-leopard", - "version": "1.1.0-alpha.2", + "version": "1.1.0", "description": "A Discord bot that checks channel names for blacklisted words and reverts the changes if necessary", "main": "build/index.js", "scripts": { From b8508a4a82edb30e036f751ebd76a75a78cf1909 Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 21:34:02 +0100 Subject: [PATCH 11/12] Adjust changelog --- Changelog.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Changelog.md b/Changelog.md index a0d4fd7..41cff22 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,9 +2,9 @@ This file is used to list changes made to this software. -_Current development release: 1.1.0-alpha.1_ +_Current development release: 1.1.0_ -## V1.1.0 [`Unreleased`] +## V1.1.0 [2022-11-29] ### Features From 9510116a375190237b341ddd528565be01df470e Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 21:36:18 +0100 Subject: [PATCH 12/12] Update lockfile --- package-lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index d1f9097..b13cafd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "eu.astrogd.white-leopard", - "version": "1.0.0", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "eu.astrogd.white-leopard", - "version": "1.0.0", + "version": "1.1.0", "license": "CC-BY-NC-ND-4.0", "dependencies": { "discord.js": "^14.6.0",