/[sudobot]/branches/6.x/src/core/CommandArgumentParserInterface.ts
ViewVC logotype

Contents of /branches/6.x/src/core/CommandArgumentParserInterface.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 577 - (show annotations)
Mon Jul 29 18:52:37 2024 UTC (8 months ago) by rakinar2
File MIME type: application/typescript
File size: 1938 byte(s)
chore: add old version archive branches (2.x to 9.x-dev)
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 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26