Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow mention prefix to be disabled #350

Merged
merged 8 commits into from
Jan 1, 2022
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