From f1a1ef5984248ded3dfa114bb22b98e21ebe1de0 Mon Sep 17 00:00:00 2001 From: Yuzu Date: Sat, 18 Sep 2021 11:15:53 -0700 Subject: [PATCH] Add length check --- src/discord/Settings.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/discord/Settings.ts b/src/discord/Settings.ts index 589e027..41d46f8 100644 --- a/src/discord/Settings.ts +++ b/src/discord/Settings.ts @@ -40,6 +40,20 @@ const EMBEDS = { user: (data instanceof Interaction) ? data.user : data.author }); }, + PREFIX_TOO_LONG: (data: Message | Interaction) => { + return makeErrorEmbed ({ + title: 'Prefix too long', + description: `I bet you can't even remember that`, + user: (data instanceof Interaction) ? data.user : data.author + }); + }, + PREFIX_IS_MENTION: (data: Message | Interaction) => { + return makeErrorEmbed ({ + title: 'Prefix cannot be mention of me', + description: `You can already call me by mentioning me. I got you covered, don't worry`, + user: (data instanceof Interaction) ? data.user : data.author + }); + }, PREFIX_UPDATED: (data: Message | Interaction, newPrefix: string) => { return makeSuccessEmbed ({ title: 'Prefix updated', @@ -95,6 +109,12 @@ export default class Settings { if(!newPrefix) return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.NO_PREFIX_PROVIDED(data)] }); + if(newPrefix.length > 100) + return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PREFIX_TOO_LONG(data)] }); + + if(newPrefix.startsWith(`<@!${DiscordProvider.client.user?.id}>`)) + return await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PREFIX_IS_MENTION(data)] }); + let placeholder = await sendMessageOrInteractionResponse(data, { embeds: [EMBEDS.PROCESSING(data)] }); await Prisma.client.guild.update({ where: { id: data.guildId! }, data: { prefix: newPrefix }}); Cache.updateGuildCache(data.guildId!);