From 1a4ec1ece80becd9156582cc490f6681cb2a1f39 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Wed, 31 Jul 2024 19:29:27 +0700 Subject: [PATCH] feat(bots/discord): add more options for curing, fix default regex --- bots/discord/config.schema.ts | 2 ++ bots/discord/src/utils/discord/moderation.ts | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/bots/discord/config.schema.ts b/bots/discord/config.schema.ts index 8738981..2df4e54 100644 --- a/bots/discord/config.schema.ts +++ b/bots/discord/config.schema.ts @@ -9,6 +9,8 @@ export type Config = { moderation?: { roles: string[] cure?: { + minimumNameLength?: number + removeCharactersRegex?: RegExp defaultName: string } log?: { diff --git a/bots/discord/src/utils/discord/moderation.ts b/bots/discord/src/utils/discord/moderation.ts index 38d3953..062e6b1 100644 --- a/bots/discord/src/utils/discord/moderation.ts +++ b/bots/discord/src/utils/discord/moderation.ts @@ -54,9 +54,9 @@ export const cureNickname = async (member: GuildMember) => { const name = member.displayName let cured = decancer(name) .toString() - .replace(/[^a-zA-Z0-9]/g, '') + .replace(new RegExp(config.moderation?.cure?.removeCharactersRegex ?? '[^a-zA-Z0-9 \\-_]', 'g'), '') - if (cured.length < 3 || !/^[a-zA-Z]/.test(cured)) + if (cured.length < (config?.moderation?.cure?.minimumNameLength ?? 3)) cured = member.user.username.length >= 3 ? member.user.username