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