support for root, group and sub command parsing from name
This commit is contained in:
		
							parent
							
								
									75620ee7ea
								
							
						
					
					
						commit
						95145c1bc2
					
				
					 1 changed files with 16 additions and 2 deletions
				
			
		
							
								
								
									
										18
									
								
								deploy.ts
									
										
									
									
									
								
							
							
						
						
									
										18
									
								
								deploy.ts
									
										
									
									
									
								
							|  | @ -79,11 +79,25 @@ export function handle( | |||
|     }, | ||||
|   handler: SlashCommandHandlerCallback | ||||
| ): void { | ||||
|   client.handle({ | ||||
|   const handle = { | ||||
|     name: typeof cmd === 'string' ? cmd : cmd.name, | ||||
|     handler, | ||||
|     ...(typeof cmd === 'string' ? {} : cmd) | ||||
|   }) | ||||
|   } | ||||
| 
 | ||||
|   if (typeof handle.name === 'string' && handle.name.includes(' ') && handle.parent === undefined && handle.group === undefined) { | ||||
|     const parts = handle.name.split(/ +/).filter(e => e !== '') | ||||
|     if (parts.length > 3 || parts.length < 1) throw new Error('Invalid command name') | ||||
|     const root = parts.shift() as string | ||||
|     const group = parts.length === 3 ? parts.shift() : undefined | ||||
|     const sub = parts.shift() | ||||
| 
 | ||||
|     handle.name = sub ?? root | ||||
|     handle.group = group | ||||
|     handle.parent = sub === undefined ? undefined : root | ||||
|   } | ||||
| 
 | ||||
|   client.handle(handle) | ||||
| } | ||||
| 
 | ||||
| export { commands, client } | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue