1
- import { Client , Collection , CommandInteractionOptionResolver , Guild , Message , MessageActionRow , MessageSelectMenu , SelectMenuInteraction , TextChannel , User } from 'discord.js' ;
1
+ import { Collection , CommandInteractionOptionResolver , Message } from 'discord.js' ;
2
2
import type { GClient } from '../lib/GClient' ;
3
3
import { CommandContext } from '../lib/structures/contexts/CommandContext' ;
4
4
import { CommandType } from '../lib/structures/Command' ;
5
+ import { ArgumentType } from '../lib/structures/Argument' ;
5
6
import { Commands } from '../lib/managers/CommandManager' ;
6
7
import { Handlers } from '../lib/managers/HandlerManager' ;
7
8
import { Logger , Events } from '../lib/util/logger/Logger' ;
8
- import { Argument , ArgumentType } from '../lib/structures/Argument' ;
9
- import { MessageArgumentTypeBase , MessageArgumentTypes } from '../lib/structures/arguments/base' ;
10
- import { Util } from '../lib/util/Util' ;
11
9
12
10
const cooldowns = new Collection < string , Collection < string , number > > ( ) ;
13
11
14
- const checkValidation = async ( arg : MessageArgumentTypes , content : string , client : Client , guild : Guild , argument : Argument , channel : TextChannel , user : User ) => {
15
- if ( ! content ) {
16
- const text = `${ user . toString ( ) } , please define argument \`${ argument . name } \`, type: ${ Util . toPascalCase ( ArgumentType [ argument . type . toString ( ) ] ) } `
17
- if ( argument . type === ArgumentType . STRING && argument . choices ?. length !== 0 ) {
18
- const menu = new MessageSelectMenu ( )
19
- . setCustomId ( 'argument_choices' )
20
- . setMaxValues ( 1 )
21
- . setMinValues ( 0 )
22
- . setPlaceholder ( 'Select a choice' ) ;
23
-
24
- menu . setOptions (
25
- argument . choices . map (
26
- ch => ( {
27
- label : ch . name ,
28
- value : ch . value
29
- } )
30
- )
31
- ) ;
32
-
33
- const message = await channel . send ( {
34
- content : text ,
35
- components : [ new MessageActionRow ( ) . addComponents ( menu ) ]
36
- } ) ;
37
-
38
- const component : SelectMenuInteraction = await channel . awaitMessageComponent ( { filter : ( m ) => m . componentType === 'SELECT_MENU' && m . user . id === user . id && m . channelId === channel . id && m . message . id === message . id && m . customId === 'argument_choices' , time : 60000 } ) as SelectMenuInteraction ;
39
-
40
- component . deferUpdate ( ) ;
41
- content = component . values ?. [ 0 ] ;
42
- } else {
43
- channel . send ( text ) ;
44
- const message = await channel . awaitMessages ( { filter : ( m ) => m . author . id === user . id && m . channelId === channel . id , time : 60000 , max : 1 } ) ;
45
-
46
- content = [ ...message . values ( ) ] ?. [ 0 ] ?. content ;
47
- }
48
- }
49
-
50
- if ( ! content ) return channel . send ( `${ user . toString ( ) } , Time :(` ) ;
51
-
52
- const validate = arg . validate ( content ) ;
53
- if ( ! validate ) return checkValidation ( arg , null , client , guild , argument , channel , user ) ;
54
-
55
- return arg . resolve ( argument , client , guild ) ;
56
- } ;
57
-
58
12
export async function MessageCommandHandler (
59
13
message : Message ,
60
14
commandName : string ,
@@ -81,7 +35,7 @@ export async function MessageCommandHandler(
81
35
} ) ;
82
36
}
83
37
84
- /* args = args.map(
38
+ args = args . map (
85
39
( arg , i ) =>
86
40
new Object ( {
87
41
name : command . arguments [ i ] . name ,
@@ -100,13 +54,7 @@ export async function MessageCommandHandler(
100
54
if ( args [ 0 ] ?. type === ArgumentType . SUB_COMMAND_GROUP && args [ 0 ] ?. options [ 0 ] ?. type === ArgumentType . SUB_COMMAND )
101
55
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
102
56
// @ts -ignore
103
- args[0].options[0].options = args[0].options.splice(1);*/
104
-
105
- for ( const argument in command . arguments ) {
106
- const arg = await MessageArgumentTypeBase . createArgument ( command . arguments [ argument ] . type ) ;
107
-
108
- args [ argument ] = await checkValidation ( arg , args [ argument ] as string , client , message . guild , command . arguments [ argument ] , message . channel as TextChannel , message . author ) ;
109
- }
57
+ args [ 0 ] . options [ 0 ] . options = args [ 0 ] . options . splice ( 1 ) ;
110
58
111
59
let replied : Message ;
112
60
const ctx = new CommandContext ( client , {
@@ -162,4 +110,4 @@ export async function MessageCommandHandler(
162
110
Logger . emit ( Events . COMMAND_HANDLER_RUN , ctx ) ;
163
111
Logger . debug ( `Successfully ran command (${ command . name } ) for ${ message . author . username } ` ) ;
164
112
} ) ;
165
- }
113
+ }
0 commit comments