fix: multiple prefix conflicts
This commit is contained in:
parent
0eadfd829e
commit
65766db1ac
2 changed files with 42 additions and 20 deletions
|
@ -23,6 +23,8 @@ export interface CommandClientOptions extends ClientOptions {
|
||||||
getGuildPrefix?: (guildID: string) => PrefixReturnType
|
getGuildPrefix?: (guildID: string) => PrefixReturnType
|
||||||
/** Method to get a User's custom prefix(s). */
|
/** Method to get a User's custom prefix(s). */
|
||||||
getUserPrefix?: (userID: string) => PrefixReturnType
|
getUserPrefix?: (userID: string) => PrefixReturnType
|
||||||
|
/** Method to get a Channel's custom prefix(s). */
|
||||||
|
getChannelPrefix?: (channelID: string) => PrefixReturnType
|
||||||
/** Method to check if certain Guild is blacklisted from using Commands. */
|
/** Method to check if certain Guild is blacklisted from using Commands. */
|
||||||
isGuildBlacklisted?: (guildID: string) => boolean | Promise<boolean>
|
isGuildBlacklisted?: (guildID: string) => boolean | Promise<boolean>
|
||||||
/** Method to check if certain User is blacklisted from using Commands. */
|
/** Method to check if certain User is blacklisted from using Commands. */
|
||||||
|
@ -44,19 +46,25 @@ export interface CommandClientOptions extends ClientOptions {
|
||||||
export class CommandClient extends Client implements CommandClientOptions {
|
export class CommandClient extends Client implements CommandClientOptions {
|
||||||
prefix: string | string[]
|
prefix: string | string[]
|
||||||
mentionPrefix: boolean
|
mentionPrefix: boolean
|
||||||
|
|
||||||
getGuildPrefix: (guildID: string) => PrefixReturnType
|
getGuildPrefix: (guildID: string) => PrefixReturnType
|
||||||
getUserPrefix: (userID: string) => PrefixReturnType
|
getUserPrefix: (userID: string) => PrefixReturnType
|
||||||
|
getChannelPrefix: (channelID: string) => PrefixReturnType
|
||||||
|
|
||||||
isGuildBlacklisted: (guildID: string) => boolean | Promise<boolean>
|
isGuildBlacklisted: (guildID: string) => boolean | Promise<boolean>
|
||||||
isUserBlacklisted: (guildID: string) => boolean | Promise<boolean>
|
isUserBlacklisted: (guildID: string) => boolean | Promise<boolean>
|
||||||
isChannelBlacklisted: (guildID: string) => boolean | Promise<boolean>
|
isChannelBlacklisted: (guildID: string) => boolean | Promise<boolean>
|
||||||
|
|
||||||
spacesAfterPrefix: boolean
|
spacesAfterPrefix: boolean
|
||||||
owners: string[]
|
owners: string[]
|
||||||
allowBots: boolean
|
allowBots: boolean
|
||||||
allowDMs: boolean
|
allowDMs: boolean
|
||||||
caseSensitive: boolean
|
caseSensitive: boolean
|
||||||
|
|
||||||
extensions: ExtensionsManager = new ExtensionsManager(this)
|
extensions: ExtensionsManager = new ExtensionsManager(this)
|
||||||
commands: CommandsManager = new CommandsManager(this)
|
commands: CommandsManager = new CommandsManager(this)
|
||||||
categories: CategoriesManager = new CategoriesManager(this)
|
categories: CategoriesManager = new CategoriesManager(this)
|
||||||
|
|
||||||
_decoratedCommands?: { [name: string]: Command }
|
_decoratedCommands?: { [name: string]: Command }
|
||||||
|
|
||||||
constructor(options: CommandClientOptions) {
|
constructor(options: CommandClientOptions) {
|
||||||
|
@ -64,6 +72,7 @@ export class CommandClient extends Client implements CommandClientOptions {
|
||||||
this.prefix = options.prefix
|
this.prefix = options.prefix
|
||||||
this.mentionPrefix =
|
this.mentionPrefix =
|
||||||
options.mentionPrefix === undefined ? false : options.mentionPrefix
|
options.mentionPrefix === undefined ? false : options.mentionPrefix
|
||||||
|
|
||||||
this.getGuildPrefix =
|
this.getGuildPrefix =
|
||||||
options.getGuildPrefix === undefined
|
options.getGuildPrefix === undefined
|
||||||
? (id: string) => this.prefix
|
? (id: string) => this.prefix
|
||||||
|
@ -72,6 +81,12 @@ export class CommandClient extends Client implements CommandClientOptions {
|
||||||
options.getUserPrefix === undefined
|
options.getUserPrefix === undefined
|
||||||
? (id: string) => this.prefix
|
? (id: string) => this.prefix
|
||||||
: options.getUserPrefix
|
: options.getUserPrefix
|
||||||
|
|
||||||
|
this.getChannelPrefix =
|
||||||
|
options.getChannelPrefix === undefined
|
||||||
|
? (id: string) => this.prefix
|
||||||
|
: options.getChannelPrefix
|
||||||
|
|
||||||
this.isUserBlacklisted =
|
this.isUserBlacklisted =
|
||||||
options.isUserBlacklisted === undefined
|
options.isUserBlacklisted === undefined
|
||||||
? (id: string) => false
|
? (id: string) => false
|
||||||
|
@ -84,10 +99,12 @@ export class CommandClient extends Client implements CommandClientOptions {
|
||||||
options.isChannelBlacklisted === undefined
|
options.isChannelBlacklisted === undefined
|
||||||
? (id: string) => false
|
? (id: string) => false
|
||||||
: options.isChannelBlacklisted
|
: options.isChannelBlacklisted
|
||||||
|
|
||||||
this.spacesAfterPrefix =
|
this.spacesAfterPrefix =
|
||||||
options.spacesAfterPrefix === undefined
|
options.spacesAfterPrefix === undefined
|
||||||
? false
|
? false
|
||||||
: options.spacesAfterPrefix
|
: options.spacesAfterPrefix
|
||||||
|
|
||||||
this.owners = options.owners === undefined ? [] : options.owners
|
this.owners = options.owners === undefined ? [] : options.owners
|
||||||
this.allowBots = options.allowBots === undefined ? false : options.allowBots
|
this.allowBots = options.allowBots === undefined ? false : options.allowBots
|
||||||
this.allowDMs = options.allowDMs === undefined ? true : options.allowDMs
|
this.allowDMs = options.allowDMs === undefined ? true : options.allowDMs
|
||||||
|
@ -128,40 +145,45 @@ export class CommandClient extends Client implements CommandClientOptions {
|
||||||
if (isGuildBlacklisted === true) return
|
if (isGuildBlacklisted === true) return
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix: string | string[] = await awaitSync(
|
let prefix: string | string[] = []
|
||||||
this.getUserPrefix(msg.author.id)
|
if (typeof this.prefix === 'string') prefix = [...prefix, this.prefix]
|
||||||
)
|
else prefix = [...prefix, ...this.prefix]
|
||||||
|
|
||||||
|
const userPrefix = await awaitSync(this.getUserPrefix(msg.author.id))
|
||||||
|
if (userPrefix !== undefined) {
|
||||||
|
if (typeof userPrefix === 'string') prefix = [...prefix, userPrefix]
|
||||||
|
else prefix = [...prefix, ...userPrefix]
|
||||||
|
}
|
||||||
|
|
||||||
if (msg.guild !== undefined) {
|
if (msg.guild !== undefined) {
|
||||||
prefix = await awaitSync(this.getGuildPrefix(msg.guild.id))
|
const guildPrefix = await awaitSync(this.getGuildPrefix(msg.guild.id))
|
||||||
|
if (guildPrefix !== undefined) {
|
||||||
|
if (typeof guildPrefix === 'string') prefix = [...prefix, guildPrefix]
|
||||||
|
else prefix = [...prefix, ...guildPrefix]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
prefix = [...new Set(prefix)]
|
||||||
|
|
||||||
let mentionPrefix = false
|
let mentionPrefix = false
|
||||||
|
|
||||||
if (typeof prefix === 'string') {
|
let usedPrefix = prefix
|
||||||
if (msg.content.startsWith(prefix) === false) {
|
.filter((v) => msg.content.startsWith(v))
|
||||||
if (this.mentionPrefix) mentionPrefix = true
|
.sort((b, a) => a.length - b.length)[0]
|
||||||
else return
|
if (usedPrefix === undefined && this.mentionPrefix) mentionPrefix = true
|
||||||
}
|
|
||||||
} else {
|
|
||||||
const usedPrefix = prefix.find((v) => msg.content.startsWith(v))
|
|
||||||
if (usedPrefix === undefined) {
|
|
||||||
if (this.mentionPrefix) mentionPrefix = true
|
|
||||||
else return
|
|
||||||
} else prefix = usedPrefix
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mentionPrefix) {
|
if (mentionPrefix) {
|
||||||
if (msg.content.startsWith(this.user?.mention as string) === true)
|
if (msg.content.startsWith(this.user?.mention as string) === true)
|
||||||
prefix = this.user?.mention as string
|
usedPrefix = this.user?.mention as string
|
||||||
else if (
|
else if (
|
||||||
msg.content.startsWith(this.user?.nickMention as string) === true
|
msg.content.startsWith(this.user?.nickMention as string) === true
|
||||||
)
|
)
|
||||||
prefix = this.user?.nickMention as string
|
usedPrefix = this.user?.nickMention as string
|
||||||
else return
|
else return
|
||||||
}
|
}
|
||||||
|
|
||||||
if (typeof prefix !== 'string') return
|
if (typeof usedPrefix !== 'string') return
|
||||||
|
prefix = usedPrefix
|
||||||
|
|
||||||
const parsed = parseCommand(this, msg, prefix)
|
const parsed = parseCommand(this, msg, prefix)
|
||||||
const command = this.commands.fetch(parsed)
|
const command = this.commands.fetch(parsed)
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { TOKEN } from './config.ts'
|
||||||
class MyClient extends CommandClient {
|
class MyClient extends CommandClient {
|
||||||
constructor() {
|
constructor() {
|
||||||
super({
|
super({
|
||||||
prefix: '!',
|
prefix: ['!', '!!'],
|
||||||
caseSensitive: false
|
caseSensitive: false
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue