Merge branch 'main' of https://github.com/DjDeveloperr/discord.deno into main
This commit is contained in:
commit
15ff747718
2 changed files with 30 additions and 17 deletions
|
@ -1,3 +1,4 @@
|
|||
import { Guild } from '../structures/guild.ts'
|
||||
import { Message } from '../structures/message.ts'
|
||||
import { TextChannel } from '../structures/textChannel.ts'
|
||||
import { User } from '../structures/user.ts'
|
||||
|
@ -23,11 +24,13 @@ export interface CommandContext {
|
|||
args: string[]
|
||||
/** Complete Raw String of Arguments */
|
||||
argString: string
|
||||
/** Guild which the command has called */
|
||||
guild?: Guild
|
||||
}
|
||||
|
||||
export class Command {
|
||||
/** Name of the Command */
|
||||
name: string = ""
|
||||
name: string = ''
|
||||
/** Description of the Command */
|
||||
description?: string
|
||||
/** Array of Aliases of Command, or only string */
|
||||
|
@ -62,13 +65,15 @@ export class CommandsManager {
|
|||
find (search: string): Command | undefined {
|
||||
if (this.client.caseSensitive === false) search = search.toLowerCase()
|
||||
return this.list.find((cmd: Command): boolean => {
|
||||
const name = this.client.caseSensitive === true ? cmd.name : cmd.name.toLowerCase()
|
||||
const name =
|
||||
this.client.caseSensitive === true ? cmd.name : cmd.name.toLowerCase()
|
||||
if (name === search) return true
|
||||
else if (cmd.aliases !== undefined) {
|
||||
let aliases: string[]
|
||||
if (typeof cmd.aliases === "string") aliases = [cmd.aliases]
|
||||
if (typeof cmd.aliases === 'string') aliases = [cmd.aliases]
|
||||
else aliases = cmd.aliases
|
||||
if (this.client.caseSensitive === false) aliases = aliases.map(e => e.toLowerCase())
|
||||
if (this.client.caseSensitive === false)
|
||||
aliases = aliases.map(e => e.toLowerCase())
|
||||
return aliases.includes(search)
|
||||
} else return false
|
||||
})
|
||||
|
@ -77,12 +82,15 @@ export class CommandsManager {
|
|||
/** Check whether a Command exists or not */
|
||||
exists (search: Command | string): boolean {
|
||||
let exists = false
|
||||
if (typeof search === "string") return this.find(search) !== undefined
|
||||
if (typeof search === 'string') return this.find(search) !== undefined
|
||||
else {
|
||||
exists = this.find(search.name) !== undefined
|
||||
if (search.aliases !== undefined) {
|
||||
const aliases: string[] = typeof search.aliases === "string" ? [search.aliases] : search.aliases
|
||||
exists = aliases.map(alias => this.find(alias) !== undefined).find(e => e) ?? false
|
||||
const aliases: string[] =
|
||||
typeof search.aliases === 'string' ? [search.aliases] : search.aliases
|
||||
exists =
|
||||
aliases.map(alias => this.find(alias) !== undefined).find(e => e) ??
|
||||
false
|
||||
}
|
||||
return exists
|
||||
}
|
||||
|
@ -99,7 +107,7 @@ export class CommandsManager {
|
|||
|
||||
/** Delete a Command */
|
||||
delete (cmd: string | Command): boolean {
|
||||
const find = typeof cmd === "string" ? this.find(cmd) : cmd
|
||||
const find = typeof cmd === 'string' ? this.find(cmd) : cmd
|
||||
if (find === undefined) return false
|
||||
else return this.list.delete(find.name)
|
||||
}
|
||||
|
@ -111,7 +119,11 @@ export interface ParsedCommand {
|
|||
argString: string
|
||||
}
|
||||
|
||||
export const parseCommand = (client: CommandClient, msg: Message, prefix: string): ParsedCommand => {
|
||||
export const parseCommand = (
|
||||
client: CommandClient,
|
||||
msg: Message,
|
||||
prefix: string
|
||||
): ParsedCommand => {
|
||||
let content = msg.content.slice(prefix.length)
|
||||
if (client.spacesAfterPrefix === true) content = content.trim()
|
||||
const args = content.split(client.betterArgs === true ? /[\S\s]*/ : / +/)
|
||||
|
|
|
@ -152,7 +152,8 @@ export class CommandClient extends Client implements CommandClientOptions {
|
|||
message: msg,
|
||||
author: msg.author,
|
||||
command,
|
||||
channel: msg.channel
|
||||
channel: msg.channel,
|
||||
guild: msg.guild
|
||||
}
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue