1
- import { Collection , CommandInteractionOptionResolver , Message } from 'discord.js' ;
1
+ import { Client , Collection , CommandInteractionOptionResolver , Guild , Message , TextChannel , User } 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' ;
6
5
import { Commands } from '../lib/managers/CommandManager' ;
7
6
import { Handlers } from '../lib/managers/HandlerManager' ;
8
7
import Logger from 'js-logger' ;
8
+ import { UserType } from '../lib/structures/arguments/User' ;
9
+ import type { Argument } from '../lib/structures/Argument' ;
9
10
10
11
const cooldowns = new Collection < string , Collection < string , number > > ( ) ;
11
12
13
+ const checkValidation = async ( arg : UserType , content : string , client : Client , guild : Guild , argument : Argument , channel : TextChannel , user : User ) => {
14
+ if ( ! content ) {
15
+ const message = await channel . awaitMessages ( { filter : ( m ) => m . author . id === user . id && m . channelId === channel . id , time : 60000 , max : 1 } ) ;
16
+
17
+ content = [ ...message . values ( ) ] ?. [ 0 ] ?. content ;
18
+ }
19
+
20
+ const validate = arg . validate ( content ) ;
21
+ if ( ! validate ) return checkValidation ( arg , null , client , guild , argument , channel , user ) ;
22
+
23
+ return arg . resolve ( argument , client , guild ) ;
24
+ }
25
+
12
26
export async function MessageCommandHandler (
13
27
message : Message ,
14
28
commandName : string ,
@@ -35,7 +49,7 @@ export async function MessageCommandHandler(
35
49
} ) ;
36
50
}
37
51
38
- args = args . map (
52
+ /* args = args.map(
39
53
(arg, i) =>
40
54
new Object({
41
55
name: command.arguments[i].name,
@@ -54,7 +68,13 @@ export async function MessageCommandHandler(
54
68
if (args[0]?.type === ArgumentType.SUB_COMMAND_GROUP && args[0]?.options[0]?.type === ArgumentType.SUB_COMMAND)
55
69
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
56
70
// @ts -ignore
57
- args [ 0 ] . options [ 0 ] . options = args [ 0 ] . options . splice ( 1 ) ;
71
+ args[0].options[0].options = args[0].options.splice(1);*/
72
+
73
+ for ( const argument in command . arguments ) {
74
+ const arg = new UserType ( ) ;
75
+
76
+ args [ argument ] = await checkValidation ( arg , args [ argument ] as string , client , message . guild , command . arguments [ argument ] , message . channel as TextChannel , message . author ) ;
77
+ }
58
78
59
79
let replied : Message ;
60
80
const ctx = new CommandContext ( client , {
@@ -106,4 +126,4 @@ export async function MessageCommandHandler(
106
126
. then ( ( ) => {
107
127
Logger . debug ( `Successfully ran command (${ command . name } ) for ${ message . author . username } ` ) ;
108
128
} ) ;
109
- }
129
+ }
0 commit comments