Skip to content

Commit

Permalink
feat: allow mention prefix to be disabled (#350)
Browse files Browse the repository at this point in the history
Co-authored-by: Jeroen Claassens <jeroen.claassens@live.nl>
  • Loading branch information
megatank58 and favna authored Jan 1, 2022
1 parent ab7c5b1 commit 26ef1dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/lib/SapphireClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ export interface SapphireClientOptions {
* @default "No cooldown options"
*/
defaultCooldown?: CooldownOptions;
/**
* Controls whether the bot has mention as a prefix disabled
* @default false
*/
disableMentionPrefix?: boolean;
}

/**
Expand Down Expand Up @@ -211,6 +216,16 @@ export class SapphireClient<Ready extends boolean = boolean> extends Client<Read
*/
public logger: ILogger;

/**
* Whether the bot has mention as a prefix disabled
* @default false
* @example
* ```typescript
* client.disableMentionPrefix = false;
* ```
*/
public disableMentionPrefix?: boolean;

/**
* The registered stores.
* @since 1.0.0
Expand All @@ -237,6 +252,7 @@ export class SapphireClient<Ready extends boolean = boolean> extends Client<Read
container.stores = this.stores;

this.fetchPrefix = options.fetchPrefix ?? (() => this.options.defaultPrefix ?? null);
this.disableMentionPrefix = options.disableMentionPrefix;

for (const plugin of SapphireClient.plugins.values(PluginHook.PreInitialization)) {
plugin.hook.call(this, options);
Expand Down
1 change: 1 addition & 0 deletions src/listeners/command-handler/CoreMessageParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export class CoreListener extends Listener<typeof Events.PreMessageParsed> {
}

private getMentionPrefix(message: Message): string | null {
if (this.container.client.disableMentionPrefix) return null;
// If the content is shorter than 20 characters, or does not start with `<@` then skip early:
if (message.content.length < 20 || !message.content.startsWith('<@')) return null;

Expand Down

0 comments on commit 26ef1dd

Please sign in to comment.