1 |
import { Awaitable, Message } from "discord.js"; |
2 |
|
3 |
export type ParsingState = { |
4 |
argv: string[]; |
5 |
args: string[]; |
6 |
parsedArgs: Record<string | number, any>; |
7 |
index: number; |
8 |
currentArg: string | undefined; |
9 |
rule: ValidationRule; |
10 |
parseOptions: ParseOptions; |
11 |
type: ArgumentType; |
12 |
}; |
13 |
|
14 |
export enum ArgumentType { |
15 |
String, |
16 |
Number, |
17 |
Integer, |
18 |
Float, |
19 |
User, |
20 |
Role, |
21 |
Member, |
22 |
Channel, |
23 |
StringRest, |
24 |
Snowflake, |
25 |
Link, |
26 |
TimeInterval |
27 |
} |
28 |
|
29 |
export type ValidationErrorType = |
30 |
| "required" |
31 |
| "type:invalid" |
32 |
| "entity:null" |
33 |
| "number:range:min" |
34 |
| "number:range:max" |
35 |
| "number:range" |
36 |
| "time:range:min" |
37 |
| "time:range:max" |
38 |
| "time:range" |
39 |
| "string:length:min" |
40 |
| "string:length:max" |
41 |
| "string:rest:length:min" |
42 |
| "string:rest:length:max" |
43 |
| "string:empty"; |
44 |
|
45 |
export type ValidationRuleErrorMessages = { [K in ValidationErrorType]?: string }; |
46 |
export type ValidationRule = { |
47 |
types: readonly ArgumentType[]; |
48 |
optional?: boolean; |
49 |
default?: any; |
50 |
name?: string; |
51 |
errors?: ValidationRuleErrorMessages; |
52 |
number?: { |
53 |
min?: number; |
54 |
max?: number; |
55 |
}; |
56 |
string?: { |
57 |
maxLength?: number; |
58 |
minLength?: number; |
59 |
notEmpty?: boolean; |
60 |
}; |
61 |
time?: { |
62 |
unit?: "ms" | "s"; |
63 |
min?: number; |
64 |
max?: number; |
65 |
}; |
66 |
link?: { |
67 |
urlObject?: boolean; |
68 |
}; |
69 |
entity?: |
70 |
| boolean |
71 |
| { |
72 |
notNull?: boolean; |
73 |
}; |
74 |
}; |
75 |
|
76 |
export type ParseOptions = { |
77 |
input: string; |
78 |
message?: Message; |
79 |
rules: readonly ValidationRule[]; |
80 |
prefix: string; |
81 |
}; |
82 |
|
83 |
export enum ParserJump { |
84 |
Next, |
85 |
Break, |
86 |
Steps |
87 |
} |
88 |
|
89 |
export type ParseResult<T = any> = { |
90 |
jump?: ParserJump; |
91 |
steps?: number; |
92 |
result?: T; |
93 |
}; |
94 |
|
95 |
export default interface CommandArgumentParserInterface { |
96 |
parse(options: ParseOptions): Awaitable<Record<string | number, any>>; |
97 |
} |