From 61f9c41d53f641a92a1f344cba96a2d5ae589d43 Mon Sep 17 00:00:00 2001 From: Jeroen Claassens Date: Sun, 7 Feb 2021 19:44:16 +0100 Subject: [PATCH] feat(message-parser): add `caseInsensitivePrefixes` client option (#170) This was a feature still missing that did exist in Klasa --- src/events/command-handler/CoreMessageParser.ts | 11 +++++++++-- src/lib/SapphireClient.ts | 7 +++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/events/command-handler/CoreMessageParser.ts b/src/events/command-handler/CoreMessageParser.ts index cd86e9a74..2c9e283f9 100644 --- a/src/events/command-handler/CoreMessageParser.ts +++ b/src/events/command-handler/CoreMessageParser.ts @@ -72,7 +72,14 @@ export class CoreEvent extends Event { private getPrefix(content: string, prefixes: readonly string[] | string | null): string | null { if (prefixes === null) return null; - if (typeof prefixes === 'string') return content.startsWith(prefixes) ? prefixes : null; - return prefixes.find((prefix) => content.startsWith(prefix)) ?? null; + const { caseInsensitivePrefixes } = this.context.client.options; + + if (caseInsensitivePrefixes) content = content.toLowerCase(); + + if (typeof prefixes === 'string') { + return content.startsWith(caseInsensitivePrefixes ? prefixes.toLowerCase() : prefixes) ? prefixes : null; + } + + return prefixes.find((prefix) => content.startsWith(caseInsensitivePrefixes ? prefix.toLowerCase() : prefix)) ?? null; } } diff --git a/src/lib/SapphireClient.ts b/src/lib/SapphireClient.ts index 6792f2862..20e5ca3f6 100644 --- a/src/lib/SapphireClient.ts +++ b/src/lib/SapphireClient.ts @@ -42,6 +42,13 @@ export interface SapphireClientOptions { */ caseInsensitiveCommands?: boolean | null; + /** + * Whether prefixes can be case insensitive + * @since 1.0.0 + * @default false + */ + caseInsensitivePrefixes?: boolean | null; + /** * The default prefix, in case of `null`, only mention prefix will trigger the bot's commands. * @since 1.0.0