Merge pull request #17 from r-Overwatch2/feature/16-send-dm-to-user-that-used-blocked-word-in-channel

closes https://github.com/r-Overwatch2/eu.astrogd.white-leopard/issues/16
This commit is contained in:
Lukas | AstroGD 2022-11-29 19:40:29 +01:00 committed by GitHub
commit b53c08a553
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 45 additions and 5 deletions

View File

@ -1,40 +1,53 @@
# eu.astrogd.white-leopard # eu.astrogd.white-leopard
A Discord bot that checks Discord channel names for banned words and prevents renaming of them A Discord bot that checks Discord channel names for banned words and prevents renaming of them
## Commands ## Commands
### /logchanel [channel?] `Permission: MANAGE_GUILD` ### /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. 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 `Permission: MANAGE_GUILD`
#### /blocklist get #### /blocklist get
Returns the global and server specific banned word list and returns it (Same behaviour as /showblocklist) Returns the global and server specific banned word list and returns it (Same behaviour as /showblocklist)
#### /blocklist add [word] #### /blocklist add [word]
Adds the word to the server specific blocklist Adds the word to the server specific blocklist
#### /blocklist remove [word] #### /blocklist remove [word]
Removes the word from the server specific blocklist Removes the word from the server specific blocklist
### /info `Permission: EVERYONE` ### /info `Permission: EVERYONE`
Returns general information about the bot and the servers stats Returns general information about the bot and the servers stats
### /preservesettings `Permission: ADMINISTRATOR` ### /preservesettings `Permission: ADMINISTRATOR`
Changes the behaviour when the bot leaves the server. Changes the behaviour when the bot leaves the server.
Options are: Options are:
- Keep settings persistent even if the bot leaves - Keep settings persistent even if the bot leaves
- Delete setting when the bot leaves the server [default] - Delete setting when the bot leaves the server [default]
### /showblocklist `Permission: MANAGE_CHANNELS` ### /showblocklist `Permission: MANAGE_CHANNELS`
Returns the global and server specific banned word list and returns it Returns the global and server specific banned word list and returns it
### /showsettings `Permission: MANAGE_GUILD` ### /showsettings `Permission: MANAGE_GUILD`
Returns the current settings for the server Returns the current settings for the server
## Environment variables ## Environment variables
| Name | Description | Required | Example | | Name | Description | Required | Example |
| :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ | | :--------------- | :------------------------------------------------------------------------------ | :------: | :------------------ |
| TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... | | TOKEN | Discord bot token to log into the API with | ▶️/🚀 | NzYzMDP3MzE1Mzky... |
| DB_HOST | Hostname of the database | ▶️ | 127.0.0.1:3546 | | DB_HOST | Hostname of the database | ▶️ | 127.0.0.1 |
| DB_USERNAME | Username of the database | ▶️ | root | | DB_USERNAME | Username of the database | ▶️ | root |
| DB_PASSWORD | Password of the database | ▶️ | abc123 | | DB_PASSWORD | Password of the database | ▶️ | abc123 |
| DB_DATABASE | Database name | ▶️ | white-leopard | | DB_DATABASE | Database name | ▶️ | white-leopard |
@ -42,6 +55,7 @@ Returns the current settings for the server
| DEPLOY_TOKEN | Production Discord bot token to log into the API with | 🚀 | NzYzMDP3MzE1Mzky... | | 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 | | DEPLOY_CLIENT_ID | Production Client ID of the Discord appication associated with the deploy token | 🚀 | 763035392692274 |
### Icon explanation: ### Icon explanation
- ▶️ = Required in runtime - ▶️ = Required in runtime
- 🚀 = Required during CI/CD - 🚀 = Required during CI/CD

View File

@ -3,7 +3,7 @@ import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User }
import { getGuildSetting } from "../tools/data"; import { getGuildSetting } from "../tools/data";
import { Badword, database } from "../data"; import { Badword, database } from "../data";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds"; import getDefaultEmbed, { getFailedEmbed, getUserReportEmbed } from "../tools/defaultEmbeds";
import { getGuildChannel } from "../tools/discord"; import { getGuildChannel } from "../tools/discord";
import { Color, Emoji } from "../tools/design"; import { Color, Emoji } from "../tools/design";
@ -89,6 +89,13 @@ client.on(Events.ChannelCreate, async (newChannel) => {
return; return;
} }
if (responsibleUser) {
const embed = getUserReportEmbed(guild.name, newChannel.name);
responsibleUser.send({
embeds: [embed]
}).catch(() => {});
}
if (!logChannel || !logChannel.isTextBased()) return; if (!logChannel || !logChannel.isTextBased()) return;
const embed = getDefaultEmbed(); const embed = getDefaultEmbed();
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`); embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);

View File

@ -3,7 +3,7 @@ import { AuditLogEvent, Events, GuildAuditLogsEntry, PermissionFlagsBits, User }
import { getGuildSetting } from "../tools/data"; import { getGuildSetting } from "../tools/data";
import { Badword, database } from "../data"; import { Badword, database } from "../data";
import { IsNull } from "typeorm"; import { IsNull } from "typeorm";
import getDefaultEmbed, { getFailedEmbed } from "../tools/defaultEmbeds"; import getDefaultEmbed, { getFailedEmbed, getUserReportEmbed } from "../tools/defaultEmbeds";
import { getGuildChannel } from "../tools/discord"; import { getGuildChannel } from "../tools/discord";
import { Color, Emoji } from "../tools/design"; import { Color, Emoji } from "../tools/design";
@ -89,6 +89,13 @@ client.on(Events.ChannelUpdate, async (oldChannel, newChannel) => {
return; return;
} }
if (responsibleUser) {
const embed = getUserReportEmbed(guild.name, newChannel.name);
responsibleUser.send({
embeds: [embed]
}).catch(() => {});
}
if (!logChannel || !logChannel.isTextBased()) return; if (!logChannel || !logChannel.isTextBased()) return;
const embed = getDefaultEmbed(); const embed = getDefaultEmbed();
embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`); embed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Blocked word detected`);

View File

@ -30,3 +30,15 @@ export function getFailedEmbed(): EmbedBuilder {
embed.setColor(Color.STOPSIGN_RED); embed.setColor(Color.STOPSIGN_RED);
return embed; return embed;
} }
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 ${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;
}