@kotori-bot/core 1.4.1 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/components/config.js +109 -35
- package/lib/components/core.d.ts +2 -0
- package/lib/components/core.js +842 -30
- package/lib/components/index.js +858 -17
- package/lib/components/message.d.ts +9 -2
- package/lib/components/message.js +832 -125
- package/lib/global/constants.js +66 -17
- package/lib/global/index.js +81 -16
- package/lib/global/symbols.d.ts +2 -0
- package/lib/global/symbols.js +50 -11
- package/lib/index.js +871 -35
- package/lib/service/adapter.d.ts +2 -5
- package/lib/service/adapter.js +826 -125
- package/lib/service/api.js +81 -44
- package/lib/service/cache.js +68 -33
- package/lib/service/elements.js +74 -38
- package/lib/service/index.js +850 -19
- package/lib/types/adapter.js +28 -1
- package/lib/types/config.js +28 -1
- package/lib/types/index.js +73 -17
- package/lib/types/message.d.ts +19 -6
- package/lib/types/message.js +70 -14
- package/lib/utils/command.d.ts +18 -10
- package/lib/utils/command.js +253 -204
- package/lib/utils/commandError.js +75 -12
- package/lib/utils/container.js +60 -20
- package/lib/utils/error.js +68 -28
- package/lib/utils/factory.d.ts +11 -3
- package/lib/utils/factory.js +846 -36
- package/lib/utils/jsxFactory.js +28 -1
- package/package.json +5 -7
- package/lib/components/modules.d.ts +0 -12
- package/lib/components/modules.js +0 -127
- package/lib/constants.d.ts +0 -15
- package/lib/constants.js +0 -19
- package/lib/consts.d.ts +0 -15
- package/lib/consts.js +0 -19
- package/lib/context/context.d.ts +0 -36
- package/lib/context/context.js +0 -115
- package/lib/context/events.d.ts +0 -18
- package/lib/context/events.js +0 -2
- package/lib/context/index.d.ts +0 -5
- package/lib/context/index.js +0 -21
- package/lib/context/modules.d.ts +0 -39
- package/lib/context/modules.js +0 -65
- package/lib/context/service.d.ts +0 -16
- package/lib/context/service.js +0 -22
- package/lib/context/symbols.d.ts +0 -12
- package/lib/context/symbols.js +0 -18
- package/lib/context/test.d.ts +0 -6
- package/lib/context/test.js +0 -12
- package/lib/global/tokens.d.ts +0 -8
- package/lib/global/tokens.js +0 -12
- package/lib/service/service.d.ts +0 -16
- package/lib/service/service.js +0 -22
- package/lib/types/core.d.ts +0 -7
- package/lib/types/core.js +0 -2
- package/lib/types/modules.d.ts +0 -39
- package/lib/types/modules.js +0 -2
- package/lib/types/service.d.ts +0 -23
- package/lib/types/service.js +0 -2
- package/lib/utils/errror.d.ts +0 -24
- package/lib/utils/errror.js +0 -29
package/lib/types/adapter.js
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.4.2-beta.1
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/6 21:03:53
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
|
|
27
|
+
// src/types/adapter.ts
|
|
28
|
+
var adapter_exports = {};
|
|
29
|
+
module.exports = __toCommonJS(adapter_exports);
|
package/lib/types/config.js
CHANGED
|
@@ -1,2 +1,29 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.4.2-beta.1
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/6 21:03:53
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __copyProps = (to, from, except, desc) => {
|
|
18
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
19
|
+
for (let key of __getOwnPropNames(from))
|
|
20
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
21
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
22
|
+
}
|
|
23
|
+
return to;
|
|
24
|
+
};
|
|
25
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
26
|
+
|
|
27
|
+
// src/types/config.ts
|
|
28
|
+
var config_exports = {};
|
|
29
|
+
module.exports = __toCommonJS(config_exports);
|
package/lib/types/index.js
CHANGED
|
@@ -1,19 +1,75 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.4.2-beta.1
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/6 21:03:53
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
22
|
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
+
|
|
41
|
+
// src/types/index.ts
|
|
42
|
+
var types_exports = {};
|
|
43
|
+
__export(types_exports, {
|
|
44
|
+
CommandAccess: () => CommandAccess,
|
|
45
|
+
MessageScope: () => MessageScope,
|
|
46
|
+
commandArgTypeSignSchema: () => commandArgTypeSignSchema,
|
|
47
|
+
eventDataTargetIdSchema: () => eventDataTargetIdSchema
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(types_exports);
|
|
50
|
+
|
|
51
|
+
// src/types/message.ts
|
|
52
|
+
var import_tsukiko = __toESM(require("tsukiko"));
|
|
53
|
+
var CommandAccess = /* @__PURE__ */ ((CommandAccess2) => {
|
|
54
|
+
CommandAccess2[CommandAccess2["MEMBER"] = 0] = "MEMBER";
|
|
55
|
+
CommandAccess2[CommandAccess2["MANGER"] = 1] = "MANGER";
|
|
56
|
+
CommandAccess2[CommandAccess2["ADMIN"] = 2] = "ADMIN";
|
|
57
|
+
return CommandAccess2;
|
|
58
|
+
})(CommandAccess || {});
|
|
59
|
+
var commandArgTypeSignSchema = import_tsukiko.default.Union([
|
|
60
|
+
import_tsukiko.default.Union([import_tsukiko.default.Literal("string"), import_tsukiko.default.Literal("number")]),
|
|
61
|
+
import_tsukiko.default.Literal("boolean")
|
|
62
|
+
]);
|
|
63
|
+
var MessageScope = /* @__PURE__ */ ((MessageScope2) => {
|
|
64
|
+
MessageScope2[MessageScope2["PRIVATE"] = 0] = "PRIVATE";
|
|
65
|
+
MessageScope2[MessageScope2["GROUP"] = 1] = "GROUP";
|
|
66
|
+
return MessageScope2;
|
|
67
|
+
})(MessageScope || {});
|
|
68
|
+
var eventDataTargetIdSchema = import_tsukiko.default.Union([import_tsukiko.default.Number(), import_tsukiko.default.String()]);
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
CommandAccess,
|
|
72
|
+
MessageScope,
|
|
73
|
+
commandArgTypeSignSchema,
|
|
74
|
+
eventDataTargetIdSchema
|
|
75
|
+
});
|
package/lib/types/message.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Tsu, { TsuError } from 'tsukiko';
|
|
2
2
|
import type I18n from '@kotori-bot/i18n';
|
|
3
|
-
import type { EventsList } from 'fluoro';
|
|
3
|
+
import type { Context, EventsList } from 'fluoro';
|
|
4
4
|
import type CommandError from '../utils/commandError';
|
|
5
5
|
import type { Api, Elements } from '../service';
|
|
6
6
|
import { Command } from '../utils/command';
|
|
@@ -11,6 +11,7 @@ declare module 'fluoro' {
|
|
|
11
11
|
parse(data: EventDataParse): void;
|
|
12
12
|
before_command(data: EventDataBeforeCommand): void;
|
|
13
13
|
command(data: EventDataCommand): void;
|
|
14
|
+
regexp(data: EventDataRegexp): void;
|
|
14
15
|
before_send(data: EventDataBeforeSend): void;
|
|
15
16
|
send(data: EventDataSend): void;
|
|
16
17
|
on_message(session: EventDataPrivateMsg | EventDataGroupMsg): void;
|
|
@@ -28,9 +29,11 @@ export declare const enum CommandAccess {
|
|
|
28
29
|
MANGER = 1,
|
|
29
30
|
ADMIN = 2
|
|
30
31
|
}
|
|
31
|
-
export type
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
export type ArgsOrigin = CommandArgType[];
|
|
33
|
+
export type OptsOrigin = Record<string, CommandArgType>;
|
|
34
|
+
export type CommandAction<Args = ArgsOrigin, Opts = OptsOrigin> = (data: {
|
|
35
|
+
args: Args;
|
|
36
|
+
options: Opts;
|
|
34
37
|
}, session: SessionData) => MessageQuick;
|
|
35
38
|
export type CommandArgType = string | number | boolean;
|
|
36
39
|
export declare const commandArgTypeSignSchema: import("tsukiko").UnionParser<[import("tsukiko").UnionParser<[import("tsukiko").LiteralParser<"string">, import("tsukiko").LiteralParser<"number">]>, import("tsukiko").LiteralParser<"boolean">]>;
|
|
@@ -97,10 +100,14 @@ export declare enum MessageScope {
|
|
|
97
100
|
GROUP = 1
|
|
98
101
|
}
|
|
99
102
|
export type MessageRaw = string;
|
|
100
|
-
export type MessageQuickReal =
|
|
103
|
+
export type MessageQuickReal = [string, (CommandArgType | undefined)[] | Record<string, CommandArgType | undefined>] | MessageRaw | CommandError | void;
|
|
101
104
|
export type MessageQuick = MessageQuickReal | Promise<MessageQuickReal>;
|
|
102
105
|
export type MidwareCallback = (next: () => void, session: SessionData) => MessageQuick;
|
|
103
106
|
export type RegexpCallback = (match: RegExpMatchArray, session: SessionData) => MessageQuick;
|
|
107
|
+
export type TaskCallback = (ctx: Context) => void;
|
|
108
|
+
export type EventApiType = {
|
|
109
|
+
[K in keyof EventsList]: EventsList[K] extends EventDataApiBase ? EventsList[K] : never;
|
|
110
|
+
};
|
|
104
111
|
export declare const eventDataTargetIdSchema: import("tsukiko").UnionParser<[import("tsukiko").NumberParser, import("tsukiko").StringParser]>;
|
|
105
112
|
export type EventDataTargetId = Tsu.infer<typeof eventDataTargetIdSchema>;
|
|
106
113
|
interface EventDataMidwares {
|
|
@@ -129,6 +136,12 @@ interface EventDataCommand {
|
|
|
129
136
|
command: Command;
|
|
130
137
|
result: EventDataParse['result'] | MessageQuick;
|
|
131
138
|
}
|
|
139
|
+
interface EventDataRegexp {
|
|
140
|
+
session: SessionData;
|
|
141
|
+
raw: string;
|
|
142
|
+
regexp: RegExp;
|
|
143
|
+
result: RegExpMatchArray;
|
|
144
|
+
}
|
|
132
145
|
interface EventDataBeforeSend {
|
|
133
146
|
api: Api;
|
|
134
147
|
message: MessageRaw;
|
|
@@ -154,7 +167,7 @@ export interface EventDataApiBase {
|
|
|
154
167
|
operatorId?: EventDataTargetId;
|
|
155
168
|
i18n: I18n;
|
|
156
169
|
send(message: MessageRaw): void;
|
|
157
|
-
format(template: string, data: Record<string,
|
|
170
|
+
format(template: string, data: Record<string, CommandArgType | undefined> | (CommandArgType | undefined)[]): string;
|
|
158
171
|
quick(message: MessageQuick): void;
|
|
159
172
|
prompt(message?: MessageRaw): Promise<MessageRaw>;
|
|
160
173
|
confirm(options?: {
|
package/lib/types/message.js
CHANGED
|
@@ -1,17 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package @kotori-bot/core
|
|
4
|
+
* @Version 1.4.2-beta.1
|
|
5
|
+
* @Author Hotaru <biyuehuya@gmail.com>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/6/6 21:03:53
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
|
|
13
|
+
var __create = Object.create;
|
|
14
|
+
var __defProp = Object.defineProperty;
|
|
15
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
16
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
17
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
18
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
19
|
+
var __export = (target, all) => {
|
|
20
|
+
for (var name in all)
|
|
21
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
4
22
|
};
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
23
|
+
var __copyProps = (to, from, except, desc) => {
|
|
24
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
25
|
+
for (let key of __getOwnPropNames(from))
|
|
26
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
27
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
28
|
+
}
|
|
29
|
+
return to;
|
|
30
|
+
};
|
|
31
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
32
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
33
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
34
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
35
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
36
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
37
|
+
mod
|
|
38
|
+
));
|
|
39
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
40
|
+
|
|
41
|
+
// src/types/message.ts
|
|
42
|
+
var message_exports = {};
|
|
43
|
+
__export(message_exports, {
|
|
44
|
+
CommandAccess: () => CommandAccess,
|
|
45
|
+
MessageScope: () => MessageScope,
|
|
46
|
+
commandArgTypeSignSchema: () => commandArgTypeSignSchema,
|
|
47
|
+
eventDataTargetIdSchema: () => eventDataTargetIdSchema
|
|
48
|
+
});
|
|
49
|
+
module.exports = __toCommonJS(message_exports);
|
|
50
|
+
var import_tsukiko = __toESM(require("tsukiko"));
|
|
51
|
+
var CommandAccess = /* @__PURE__ */ ((CommandAccess2) => {
|
|
52
|
+
CommandAccess2[CommandAccess2["MEMBER"] = 0] = "MEMBER";
|
|
53
|
+
CommandAccess2[CommandAccess2["MANGER"] = 1] = "MANGER";
|
|
54
|
+
CommandAccess2[CommandAccess2["ADMIN"] = 2] = "ADMIN";
|
|
55
|
+
return CommandAccess2;
|
|
56
|
+
})(CommandAccess || {});
|
|
57
|
+
var commandArgTypeSignSchema = import_tsukiko.default.Union([
|
|
58
|
+
import_tsukiko.default.Union([import_tsukiko.default.Literal("string"), import_tsukiko.default.Literal("number")]),
|
|
59
|
+
import_tsukiko.default.Literal("boolean")
|
|
11
60
|
]);
|
|
12
|
-
var MessageScope
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
})(MessageScope ||
|
|
17
|
-
|
|
61
|
+
var MessageScope = /* @__PURE__ */ ((MessageScope2) => {
|
|
62
|
+
MessageScope2[MessageScope2["PRIVATE"] = 0] = "PRIVATE";
|
|
63
|
+
MessageScope2[MessageScope2["GROUP"] = 1] = "GROUP";
|
|
64
|
+
return MessageScope2;
|
|
65
|
+
})(MessageScope || {});
|
|
66
|
+
var eventDataTargetIdSchema = import_tsukiko.default.Union([import_tsukiko.default.Number(), import_tsukiko.default.String()]);
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
CommandAccess,
|
|
70
|
+
MessageScope,
|
|
71
|
+
commandArgTypeSignSchema,
|
|
72
|
+
eventDataTargetIdSchema
|
|
73
|
+
});
|
package/lib/utils/command.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CommandAccess, type CommandAction, type CommandArgType, type CommandArgTypeSign, type CommandConfig } from '../types';
|
|
1
|
+
import { CommandAccess, type CommandAction, type CommandArgType, type CommandArgTypeSign, type CommandConfig, ArgsOrigin, OptsOrigin } from '../types';
|
|
2
2
|
import { CommandError } from './commandError';
|
|
3
3
|
interface CommandArg {
|
|
4
4
|
name: string;
|
|
@@ -13,7 +13,7 @@ interface CommandOption {
|
|
|
13
13
|
realname: string;
|
|
14
14
|
description?: string;
|
|
15
15
|
}
|
|
16
|
-
interface CommandData {
|
|
16
|
+
interface CommandData<Args = ArgsOrigin, Opts = OptsOrigin> {
|
|
17
17
|
root: string;
|
|
18
18
|
alias: string[];
|
|
19
19
|
args: CommandArg[];
|
|
@@ -21,23 +21,31 @@ interface CommandData {
|
|
|
21
21
|
scope: CommandConfig['scope'];
|
|
22
22
|
access: CommandAccess;
|
|
23
23
|
help?: string;
|
|
24
|
-
action?: CommandAction
|
|
24
|
+
action?: CommandAction<Args, Opts>;
|
|
25
25
|
description?: string;
|
|
26
26
|
}
|
|
27
|
-
|
|
27
|
+
type GetSignType<T extends string> = T extends `${string}number${string}` ? number : T extends `${string}boolean${string}` ? boolean : string;
|
|
28
|
+
type GetArgCtn<Template extends string> = Template extends `${string}:${infer Suffix}` ? Suffix extends `${infer T}=${string}` ? GetSignType<T> : GetSignType<Suffix> : Template extends `${infer T}=${string}` ? GetSignType<T> : string;
|
|
29
|
+
type ParseArgs<Template extends string> = string extends Template ? ArgsOrigin : Template extends `${string} ${`<${infer Ctn}>`}${infer Rest}` ? Ctn extends `...${infer Ctn2}` ? [...GetSignType<Ctn2>[]] : [GetArgCtn<Ctn>, ...ParseArgs<Rest>] : Template extends `${string} [${infer Ctn}]${infer Rest}` ? Ctn extends `${infer Ctn2}=${string}` ? Ctn2 extends `...${infer Ctn3}` ? [...GetSignType<Ctn3>[]] : [GetArgCtn<Ctn2>, ...ParseArgs<Rest>] : Ctn extends `...${infer Ctn2}` ? [...GetSignType<Ctn2>[]] : [GetArgCtn<Ctn>?, ...ParseArgs<Rest>] : [];
|
|
30
|
+
type ParseOpts<Template extends string> = string extends Template ? {} : Template extends `${infer K}:${infer V}` ? GetSignType<V> extends Boolean ? {
|
|
31
|
+
[C in K]: GetSignType<V>;
|
|
32
|
+
} : {
|
|
33
|
+
[C in K]?: GetSignType<V>;
|
|
34
|
+
} : {};
|
|
35
|
+
export declare class Command<Template extends string = string, Opts extends OptsOrigin = OptsOrigin> {
|
|
28
36
|
static run(input: string, data: CommandData): CommandError | {
|
|
29
|
-
args:
|
|
30
|
-
options:
|
|
37
|
+
args: ArgsOrigin;
|
|
38
|
+
options: OptsOrigin;
|
|
31
39
|
};
|
|
32
40
|
private template;
|
|
33
|
-
readonly meta: CommandData
|
|
34
|
-
constructor(template:
|
|
41
|
+
readonly meta: CommandData<ParseArgs<Template>, Opts>;
|
|
42
|
+
constructor(template: Template, config?: CommandConfig);
|
|
35
43
|
private parse;
|
|
36
44
|
alias(alias: string | string[]): this;
|
|
37
45
|
scope(scope: CommandConfig['scope']): this;
|
|
38
46
|
access(access: CommandAccess): this;
|
|
39
|
-
option(name: string, template:
|
|
40
|
-
action(callback: CommandAction): this;
|
|
47
|
+
option<TemplateOpt extends string>(name: string, template: TemplateOpt): Command<Template, Opts & ParseOpts<TemplateOpt>>;
|
|
48
|
+
action(callback: CommandAction<ParseArgs<Template>, Opts>): this;
|
|
41
49
|
help(text: string): this;
|
|
42
50
|
}
|
|
43
51
|
export default Command;
|