Skip to content

Commit

Permalink
feat(message-parser): add caseInsensitivePrefixes client option (#170)
Browse files Browse the repository at this point in the history
This was a feature still missing that did exist in Klasa
  • Loading branch information
favna committed Feb 7, 2021
1 parent a5bda61 commit 61f9c41
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/events/command-handler/CoreMessageParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,14 @@ export class CoreEvent extends Event<Events.PreMessageParsed> {

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;
}
}
7 changes: 7 additions & 0 deletions src/lib/SapphireClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 61f9c41

Please sign in to comment.