From 9261497dc4a438e37643dbd21662cfeb4b73141f Mon Sep 17 00:00:00 2001 From: adan-ea <57812567+adan-ea@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:05:10 +0100 Subject: [PATCH 1/2] feat(qotd): Add banned key words --- package-lock.json | 8 ++++---- package.json | 2 +- src/modules/qotd/commands/qotd.ts | 4 ++++ src/modules/qotd/models/qotd.model.ts | 3 ++- src/utils/errors.ts | 3 ++- 5 files changed, 13 insertions(+), 7 deletions(-) diff --git a/package-lock.json b/package-lock.json index 93888c3..e608214 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,7 +9,7 @@ "version": "4.0.0", "license": "AGPL-3.0", "dependencies": { - "adroi.d.ea": "^1.0.9", + "adroi.d.ea": "^1.1.0", "ansis": "^1.5.5", "bullmq": "^3.12.0", "discord.js": "^14.14.1", @@ -1916,9 +1916,9 @@ } }, "node_modules/adroi.d.ea": { - "version": "1.0.9", - "resolved": "https://registry.npmjs.org/adroi.d.ea/-/adroi.d.ea-1.0.9.tgz", - "integrity": "sha512-c51VQJgR3fPYQogTJmjTTcPLUFZU1AqYHG5f7hUnWnoYAigoXp9NBTgXu0txg1i8v9HWO8lHotlU/9RhtDxRHQ==" + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/adroi.d.ea/-/adroi.d.ea-1.1.0.tgz", + "integrity": "sha512-MO1m0KdoroNsbNIieZfG3dlOiJ61YdOoH4XJrSJqU3YpApyPxSRS54iPVm3Kp3uXAh2t7EkbhajBmERUYYF1vw==" }, "node_modules/ajv": { "version": "6.12.6", diff --git a/package.json b/package.json index e5905bd..9920dc9 100644 --- a/package.json +++ b/package.json @@ -41,7 +41,7 @@ ] }, "dependencies": { - "adroi.d.ea": "^1.0.9", + "adroi.d.ea": "^1.1.0", "ansis": "^1.5.5", "bullmq": "^3.12.0", "discord.js": "^14.14.1", diff --git a/src/modules/qotd/commands/qotd.ts b/src/modules/qotd/commands/qotd.ts index 4debbe6..f0e0a49 100644 --- a/src/modules/qotd/commands/qotd.ts +++ b/src/modules/qotd/commands/qotd.ts @@ -50,6 +50,10 @@ export default { if (qotd.blacklist?.includes(interaction.user.id)) throw CustomErrors.BlacklistedUserError; const question = interaction.options.getString('question', true); + + if (qotd.bannedWords?.some(word => new RegExp(word, 'i').test(question))) + throw CustomErrors.BannedWordError; + const author = interaction.options.getUser('auteur'); const user = (interaction.member as GuildMember).user; diff --git a/src/modules/qotd/models/qotd.model.ts b/src/modules/qotd/models/qotd.model.ts index d188d99..c385caf 100644 --- a/src/modules/qotd/models/qotd.model.ts +++ b/src/modules/qotd/models/qotd.model.ts @@ -15,7 +15,8 @@ export const qotdSchema = new mongoose.Schema({ pingedRoleId: String, blacklist: [String], whitelist: [String], - questionsThreshold: Number + questionsThreshold: Number, + bannedWords: [String] }); export const questionsSchema = new mongoose.Schema({ diff --git a/src/utils/errors.ts b/src/utils/errors.ts index a28f55a..8361ca4 100644 --- a/src/utils/errors.ts +++ b/src/utils/errors.ts @@ -57,7 +57,8 @@ export const CustomErrors = { // QOtD related err // //////////////////////////////////////////////////// QOtDeDisabledError: new CustomError('Les QdJ ne sont pas activées sur ce serveur.'), - BlacklistedUserError: new CustomError('Les requêtes personnalisées sont désactivés pour toi.'), + BlacklistedUserError: new CustomError('Tu es blacklisté, tu ne peux pas proposer de question.'), + BannedWordError: new CustomError('Ta question contient un mot interdit.'), //////////////////////////////////////////////////// // Twitch related err // From 2eb1a896c791af242083e3e7c3e3a6fc1653a8c6 Mon Sep 17 00:00:00 2001 From: adan-ea <57812567+adan-ea@users.noreply.github.com> Date: Tue, 13 Feb 2024 17:06:50 +0100 Subject: [PATCH 2/2] docs: update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 60f766b..02de6c1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file. ❄️ Twitch: Now can ignore some categories for the Category Change notification - [[#75](https://github.com/adroidea/bot/issues/75)] +❄️ QotD: Add banned key words - [[#78](https://github.com/adroidea/bot/issues/78)] + ### 🧱 Changed ### 🚮 Removed