add args parser into command class (not tested)
This commit is contained in:
		
							parent
							
								
									d9925a4ac4
								
							
						
					
					
						commit
						7f96dfebc3
					
				
					 3 changed files with 10 additions and 8 deletions
				
			
		|  | @ -9,6 +9,7 @@ import { | ||||||
|   CommandsManager, |   CommandsManager, | ||||||
|   parseCommand |   parseCommand | ||||||
| } from './command.ts' | } from './command.ts' | ||||||
|  | import { parseArgs } from '../utils/command.ts' | ||||||
| import { Extension, ExtensionsManager } from './extension.ts' | import { Extension, ExtensionsManager } from './extension.ts' | ||||||
| 
 | 
 | ||||||
| type PrefixReturnType = string | string[] | Promise<string | string[]> | type PrefixReturnType = string | string[] | Promise<string | string[]> | ||||||
|  | @ -239,7 +240,7 @@ export class CommandClient extends Client implements CommandClientOptions { | ||||||
|       client: this, |       client: this, | ||||||
|       name: parsed.name, |       name: parsed.name, | ||||||
|       prefix, |       prefix, | ||||||
|       args: parsed.args, |       args: parseArgs(command.args, parsed.args), | ||||||
|       argString: parsed.argString, |       argString: parsed.argString, | ||||||
|       message: msg, |       message: msg, | ||||||
|       author: msg.author, |       author: msg.author, | ||||||
|  |  | ||||||
|  | @ -6,7 +6,7 @@ import { Collection } from '../utils/collection.ts' | ||||||
| import type { CommandClient } from './client.ts' | import type { CommandClient } from './client.ts' | ||||||
| import type { Extension } from './extension.ts' | import type { Extension } from './extension.ts' | ||||||
| import { join, walk } from '../../deps.ts' | import { join, walk } from '../../deps.ts' | ||||||
| 
 | import type { Args } from '../utils/command.ts' | ||||||
| export interface CommandContext { | export interface CommandContext { | ||||||
|   /** The Client object */ |   /** The Client object */ | ||||||
|   client: CommandClient |   client: CommandClient | ||||||
|  | @ -23,7 +23,7 @@ export interface CommandContext { | ||||||
|   /** Name of Command which was used */ |   /** Name of Command which was used */ | ||||||
|   name: string |   name: string | ||||||
|   /** Array of Arguments used with Command */ |   /** Array of Arguments used with Command */ | ||||||
|   args: string[] |   args: Record<string, unknown> | null | ||||||
|   /** Complete Raw String of Arguments */ |   /** Complete Raw String of Arguments */ | ||||||
|   argString: string |   argString: string | ||||||
|   /** Guild which the command has called */ |   /** Guild which the command has called */ | ||||||
|  | @ -46,7 +46,7 @@ export interface CommandOptions { | ||||||
|   /** Usage Example of Command, only Arguments (without Prefix and Name) */ |   /** Usage Example of Command, only Arguments (without Prefix and Name) */ | ||||||
|   examples?: string | string[] |   examples?: string | string[] | ||||||
|   /** Does the Command take Arguments? Maybe number of required arguments? Or list of arguments? */ |   /** Does the Command take Arguments? Maybe number of required arguments? Or list of arguments? */ | ||||||
|   args?: number | boolean | string[] |   args?: Args[] | ||||||
|   /** Permissions(s) required by both User and Bot in order to use Command */ |   /** Permissions(s) required by both User and Bot in order to use Command */ | ||||||
|   permissions?: string | string[] |   permissions?: string | string[] | ||||||
|   /** Permission(s) required for using Command */ |   /** Permission(s) required for using Command */ | ||||||
|  | @ -81,7 +81,7 @@ export class Command implements CommandOptions { | ||||||
|   extension?: Extension |   extension?: Extension | ||||||
|   usage?: string | string[] |   usage?: string | string[] | ||||||
|   examples?: string | string[] |   examples?: string | string[] | ||||||
|   args?: number | boolean | string[] |   args?: Args[] | ||||||
|   permissions?: string | string[] |   permissions?: string | string[] | ||||||
|   userPermissions?: string | string[] |   userPermissions?: string | string[] | ||||||
|   botPermissions?: string | string[] |   botPermissions?: string | string[] | ||||||
|  |  | ||||||
|  | @ -15,10 +15,11 @@ export interface Args { | ||||||
| 
 | 
 | ||||||
| const mentionRegex = /([0-9]{18})/g | const mentionRegex = /([0-9]{18})/g | ||||||
| 
 | 
 | ||||||
| export function parseArgs2( | export function parseArgs( | ||||||
|   commandArgs: Args[], |   commandArgs: Args[] | undefined, | ||||||
|   messageArgs: string[] |   messageArgs: string[] | ||||||
| ): Record<string, unknown> { | ): Record<string, unknown> | null { | ||||||
|  |   if (!commandArgs) return null | ||||||
|   const messageArgsNullableCopy: Array<string | null> = [...messageArgs] |   const messageArgsNullableCopy: Array<string | null> = [...messageArgs] | ||||||
|   const args: Record<string, unknown> = {} |   const args: Record<string, unknown> = {} | ||||||
|   for (const entry of commandArgs) { |   for (const entry of commandArgs) { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue