@kotori-bot/core 1.1.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/LICENSE +674 -0
- package/lib/base/command.d.ts +20 -0
- package/lib/base/command.js +217 -0
- package/lib/base/core.d.ts +30 -0
- package/lib/base/core.js +52 -0
- package/lib/base/events.d.ts +13 -0
- package/lib/base/events.js +41 -0
- package/lib/base/filter.d.ts +1 -0
- package/lib/base/filter.js +2 -0
- package/lib/base/internal.d.ts +34 -0
- package/lib/base/internal.js +89 -0
- package/lib/base/message.d.ts +18 -0
- package/lib/base/message.js +177 -0
- package/lib/base/modules.d.ts +15 -0
- package/lib/base/modules.js +205 -0
- package/lib/components/adapter.d.ts +38 -0
- package/lib/components/adapter.js +128 -0
- package/lib/components/api.d.ts +35 -0
- package/lib/components/api.js +47 -0
- package/lib/components/elements.d.ts +12 -0
- package/lib/components/elements.js +28 -0
- package/lib/components/service.d.ts +13 -0
- package/lib/components/service.js +7 -0
- package/lib/consts.d.ts +11 -0
- package/lib/consts.js +13 -0
- package/lib/context.d.ts +13 -0
- package/lib/context.js +35 -0
- package/lib/index.d.ts +17 -0
- package/lib/index.js +43 -0
- package/lib/types.d.ts +417 -0
- package/lib/types.js +81 -0
- package/lib/utils/commandExtra.d.ts +6 -0
- package/lib/utils/commandExtra.js +11 -0
- package/lib/utils/errror.d.ts +41 -0
- package/lib/utils/errror.js +34 -0
- package/lib/utils/i18n.d.ts +13 -0
- package/lib/utils/i18n.js +65 -0
- package/lib/utils/jsxFactory.d.ts +6 -0
- package/lib/utils/jsxFactory.js +2 -0
- package/package.json +30 -0
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { CommandAccess, type CommandAction, type CommandConfig, type CommandData } from '../types';
|
|
2
|
+
export declare class Command {
|
|
3
|
+
private static parseOption;
|
|
4
|
+
private static parseArgs;
|
|
5
|
+
static readonly dataList: CommandData[];
|
|
6
|
+
static parse(input: string): void;
|
|
7
|
+
private template;
|
|
8
|
+
constructor(template: string, config?: CommandConfig);
|
|
9
|
+
readonly data: CommandData;
|
|
10
|
+
private requiredParamMatch;
|
|
11
|
+
private optionalParamMatch;
|
|
12
|
+
private parseTemplate;
|
|
13
|
+
alias(alias: string | string[]): this;
|
|
14
|
+
scope(scope: CommandConfig['scope']): this;
|
|
15
|
+
access(access: CommandAccess): this;
|
|
16
|
+
option(name: string, template: string): this;
|
|
17
|
+
action(callback: CommandAction): this;
|
|
18
|
+
help(text: string): this;
|
|
19
|
+
}
|
|
20
|
+
export default Command;
|
|
@@ -0,0 +1,217 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Command = void 0;
|
|
7
|
+
const tools_1 = require("@kotori-bot/tools");
|
|
8
|
+
const errror_1 = require("../utils/errror");
|
|
9
|
+
const commandExtra_1 = __importDefault(require("../utils/commandExtra"));
|
|
10
|
+
function parseTemplateParam(content) {
|
|
11
|
+
const { '0': root, '1': defaultValue } = content.split('=');
|
|
12
|
+
const { '0': argName, '1': argType } = root.split(':');
|
|
13
|
+
let handleDefault = defaultValue || undefined;
|
|
14
|
+
let handleArg = 'string';
|
|
15
|
+
if (argType === 'number') {
|
|
16
|
+
handleArg = argType;
|
|
17
|
+
if (handleDefault !== undefined)
|
|
18
|
+
handleDefault = parseInt(handleDefault, 10);
|
|
19
|
+
}
|
|
20
|
+
return {
|
|
21
|
+
name: argName || 'content',
|
|
22
|
+
type: handleArg,
|
|
23
|
+
default: handleDefault,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function error(type, data) {
|
|
27
|
+
return new errror_1.CommandError(undefined, new commandExtra_1.default({ type, ...data }));
|
|
28
|
+
}
|
|
29
|
+
class Command {
|
|
30
|
+
static parseOption(expectedOptions, input) {
|
|
31
|
+
const realityOptions = {};
|
|
32
|
+
let cmd = input;
|
|
33
|
+
[...`${cmd} `.matchAll(/\s-([a-z]+)(=(\w+)|)\s?\b/g)].forEach(el => {
|
|
34
|
+
cmd = cmd.replace(el[0], '');
|
|
35
|
+
const key = el[1];
|
|
36
|
+
let val = el[3] || undefined;
|
|
37
|
+
expectedOptions.forEach(option => {
|
|
38
|
+
if (option.realname !== key)
|
|
39
|
+
return;
|
|
40
|
+
if (val !== undefined && val !== '') {
|
|
41
|
+
if (option.type === 'number' && typeof val !== 'number') {
|
|
42
|
+
val = parseInt(val, 10);
|
|
43
|
+
if (Number.isNaN(val)) {
|
|
44
|
+
throw error('option_error', {
|
|
45
|
+
expected: 'number',
|
|
46
|
+
reality: 'string,',
|
|
47
|
+
target: option.realname,
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
val = option.default || '';
|
|
53
|
+
realityOptions[option.name] = val;
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
return [realityOptions, cmd];
|
|
57
|
+
}
|
|
58
|
+
static parseArgs(expectedArgs, inputHandel) {
|
|
59
|
+
const realityArgs = [];
|
|
60
|
+
let current = '';
|
|
61
|
+
let inBackslash = false;
|
|
62
|
+
let inQuote = false;
|
|
63
|
+
`${inputHandel} `.split('').forEach(char => {
|
|
64
|
+
if (inBackslash) {
|
|
65
|
+
inBackslash = false;
|
|
66
|
+
current += char;
|
|
67
|
+
}
|
|
68
|
+
else if (char === ' ' && !inQuote) {
|
|
69
|
+
if (!current)
|
|
70
|
+
return;
|
|
71
|
+
const arg = expectedArgs[realityArgs.length];
|
|
72
|
+
if (!arg) {
|
|
73
|
+
throw error('arg_many', { expected: expectedArgs.length, reality: realityArgs.length + 1 });
|
|
74
|
+
}
|
|
75
|
+
let val = current.trim();
|
|
76
|
+
if (arg.type === 'number' && typeof val !== 'number') {
|
|
77
|
+
val = parseInt(current, 10);
|
|
78
|
+
if (Number.isNaN(val)) {
|
|
79
|
+
throw error('arg_error', { expected: 'number', reality: 'string', target: arg.name });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
realityArgs.push(val);
|
|
83
|
+
current = '';
|
|
84
|
+
}
|
|
85
|
+
else if (char === '"' || char === "'") {
|
|
86
|
+
// dont fix it for big and small quote
|
|
87
|
+
inQuote = !inQuote;
|
|
88
|
+
}
|
|
89
|
+
else if (char === '\\') {
|
|
90
|
+
inBackslash = true;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
current += char;
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
if (!inQuote && !inBackslash)
|
|
97
|
+
return realityArgs;
|
|
98
|
+
throw error('syntax', { index: inputHandel.lastIndexOf(inQuote ? '"' : '\\'), char: inQuote ? '"' : '\\' });
|
|
99
|
+
}
|
|
100
|
+
static dataList = [];
|
|
101
|
+
static parse(input) {
|
|
102
|
+
this.dataList.forEach(command => {
|
|
103
|
+
if (!command.action)
|
|
104
|
+
return;
|
|
105
|
+
const cmd = input
|
|
106
|
+
.replace(/(\s+)/g, ' ')
|
|
107
|
+
.replace(/("\s?")|('\s?')/g, '')
|
|
108
|
+
.trim();
|
|
109
|
+
if (!`${input} `.startsWith(`${command.root} `)) {
|
|
110
|
+
const alias = command.alias.filter(el => `${input} `.startsWith(`${el} `));
|
|
111
|
+
if (alias.length <= 0)
|
|
112
|
+
return;
|
|
113
|
+
// cmd = (input.split(alias[0])[1] ?? '').trim();
|
|
114
|
+
}
|
|
115
|
+
const tempArray = this.parseOption(command.options, cmd);
|
|
116
|
+
const realityOptions = tempArray[0];
|
|
117
|
+
const realityArgs = this.parseArgs(command.args, (0, tools_1.stringRightSplit)(tempArray[1], cmd.split(' ')[0]));
|
|
118
|
+
const expectedLength = command.args.filter(el => !el.optional).length;
|
|
119
|
+
if (expectedLength > realityArgs.length) {
|
|
120
|
+
throw error('arg_few', { expected: expectedLength, reality: realityArgs.length });
|
|
121
|
+
}
|
|
122
|
+
if (command.args.length > realityArgs.length) {
|
|
123
|
+
let index = realityArgs.length;
|
|
124
|
+
while (index < command.args.length) {
|
|
125
|
+
const arg = command.args[index];
|
|
126
|
+
if (arg.default === undefined)
|
|
127
|
+
break;
|
|
128
|
+
realityArgs.push(arg.default);
|
|
129
|
+
index += 1;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
throw error('parsed', { action: command.action, args: realityArgs, options: realityOptions });
|
|
133
|
+
});
|
|
134
|
+
throw error('unknown', { input });
|
|
135
|
+
}
|
|
136
|
+
template;
|
|
137
|
+
constructor(template, config) {
|
|
138
|
+
this.template = template;
|
|
139
|
+
this.data = Object.assign(this.data, config);
|
|
140
|
+
Command.dataList.push(this.data);
|
|
141
|
+
this.parseTemplate();
|
|
142
|
+
}
|
|
143
|
+
data = {
|
|
144
|
+
root: '',
|
|
145
|
+
alias: [],
|
|
146
|
+
scope: 'all',
|
|
147
|
+
access: 0 /* CommandAccess.MEMBER */,
|
|
148
|
+
args: [],
|
|
149
|
+
options: [],
|
|
150
|
+
};
|
|
151
|
+
requiredParamMatch = /<(.*?)>/g;
|
|
152
|
+
optionalParamMatch = /\[(.*?)]/g;
|
|
153
|
+
parseTemplate() {
|
|
154
|
+
const { '0': root, '1': description } = this.template
|
|
155
|
+
.trim()
|
|
156
|
+
.replace(/\s{2,}/g, ' ')
|
|
157
|
+
.split(' - ');
|
|
158
|
+
this.data.description = description;
|
|
159
|
+
const requiredIndex = root.indexOf(' <');
|
|
160
|
+
const optionalIndex = root.indexOf(' [');
|
|
161
|
+
let requiredStr = '';
|
|
162
|
+
let optionalStr = '';
|
|
163
|
+
if (requiredIndex > 0) {
|
|
164
|
+
this.data.root = root.substring(0, requiredIndex);
|
|
165
|
+
requiredStr = root.substring(requiredIndex);
|
|
166
|
+
const newOptionalIndex = requiredStr.indexOf(' [');
|
|
167
|
+
if (newOptionalIndex > 0) {
|
|
168
|
+
optionalStr = requiredStr.substring(newOptionalIndex);
|
|
169
|
+
requiredStr = requiredStr.substring(0, newOptionalIndex);
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else if (optionalIndex > 0) {
|
|
173
|
+
this.data.root = root.substring(0, optionalIndex);
|
|
174
|
+
optionalStr = root.substring(optionalIndex);
|
|
175
|
+
}
|
|
176
|
+
else {
|
|
177
|
+
this.data.root = root;
|
|
178
|
+
}
|
|
179
|
+
[...requiredStr.matchAll(this.requiredParamMatch)].forEach(content => {
|
|
180
|
+
this.data.args.push({ optional: false, rest: false, ...parseTemplateParam(content[1]) });
|
|
181
|
+
});
|
|
182
|
+
[...optionalStr.matchAll(this.optionalParamMatch)].forEach(content => {
|
|
183
|
+
this.data.args.push({ optional: true, rest: false, ...parseTemplateParam(content[1]) });
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
alias(alias) {
|
|
187
|
+
if (typeof alias === 'string')
|
|
188
|
+
this.data.alias.push(alias);
|
|
189
|
+
else
|
|
190
|
+
this.data.alias.push(...alias);
|
|
191
|
+
return this;
|
|
192
|
+
}
|
|
193
|
+
scope(scope) {
|
|
194
|
+
this.data.scope = scope;
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
access(access) {
|
|
198
|
+
this.data.access = access;
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
option(name, template) {
|
|
202
|
+
const { '0': root, '1': description } = template.trim().split(' ');
|
|
203
|
+
const handleData = parseTemplateParam(root);
|
|
204
|
+
this.data.options.push({ realname: handleData.name, description, ...handleData, name });
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
action(callback) {
|
|
208
|
+
this.data.action = callback;
|
|
209
|
+
return this;
|
|
210
|
+
}
|
|
211
|
+
help(text) {
|
|
212
|
+
this.data.help = text;
|
|
213
|
+
return this;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.Command = Command;
|
|
217
|
+
exports.default = Command;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { obj } from '@kotori-bot/tools';
|
|
2
|
+
import { Parser } from 'tsukiko';
|
|
3
|
+
import { type AdapterConstructor, type BaseDir, type GlobalConfig, type GlobalOptions, type KotoriConfig, type PackageInfo } from '../types';
|
|
4
|
+
import type Api from '../components/api';
|
|
5
|
+
export declare const defaultConfig: {
|
|
6
|
+
baseDir: {
|
|
7
|
+
root: string;
|
|
8
|
+
modules: string;
|
|
9
|
+
};
|
|
10
|
+
config: {
|
|
11
|
+
global: {
|
|
12
|
+
lang: "ja_JP" | "en_US" | "zh_TW" | "zh_CN";
|
|
13
|
+
'command-prefix': string;
|
|
14
|
+
};
|
|
15
|
+
adapter: {};
|
|
16
|
+
};
|
|
17
|
+
options: {
|
|
18
|
+
env: string;
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export declare class Core {
|
|
22
|
+
protected readonly adapterStack: obj<[AdapterConstructor, Parser<unknown>?]>;
|
|
23
|
+
protected readonly botStack: obj<Api[]>;
|
|
24
|
+
readonly baseDir: BaseDir;
|
|
25
|
+
readonly config: GlobalConfig;
|
|
26
|
+
readonly options: GlobalOptions;
|
|
27
|
+
readonly package: PackageInfo;
|
|
28
|
+
constructor(config?: KotoriConfig);
|
|
29
|
+
}
|
|
30
|
+
export default Core;
|
package/lib/base/core.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Core = exports.defaultConfig = void 0;
|
|
7
|
+
const tools_1 = require("@kotori-bot/tools");
|
|
8
|
+
const path_1 = __importDefault(require("path"));
|
|
9
|
+
const types_1 = require("../types");
|
|
10
|
+
const errror_1 = require("../utils/errror");
|
|
11
|
+
const consts_1 = require("../consts");
|
|
12
|
+
exports.defaultConfig = {
|
|
13
|
+
baseDir: {
|
|
14
|
+
root: path_1.default.resolve(consts_1.DEFAULT_ROOT_DIR),
|
|
15
|
+
modules: path_1.default.resolve(consts_1.DEFAULT_MODULES_DIR),
|
|
16
|
+
},
|
|
17
|
+
config: {
|
|
18
|
+
global: {
|
|
19
|
+
lang: consts_1.DEFAULT_LANG,
|
|
20
|
+
'command-prefix': consts_1.DEFAULT_COMMAND_PREFIX,
|
|
21
|
+
},
|
|
22
|
+
adapter: {},
|
|
23
|
+
},
|
|
24
|
+
options: {
|
|
25
|
+
env: consts_1.DEFAULT_ENV,
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
class Core {
|
|
29
|
+
adapterStack = {};
|
|
30
|
+
botStack = {};
|
|
31
|
+
baseDir;
|
|
32
|
+
config;
|
|
33
|
+
options;
|
|
34
|
+
package;
|
|
35
|
+
constructor(config) {
|
|
36
|
+
const info = (0, tools_1.loadConfig)(path_1.default.join(__dirname, '../../package.json'));
|
|
37
|
+
if (!info || Object.values(info).length === 0)
|
|
38
|
+
throw new errror_1.CoreError('Cannot find kotori-bot package.json');
|
|
39
|
+
const result = types_1.packageInfoSchema.parseSafe(info);
|
|
40
|
+
if (!result.value)
|
|
41
|
+
throw new errror_1.CoreError(`File package.json format error: ${result.error.message}`);
|
|
42
|
+
this.package = result.data;
|
|
43
|
+
const handle = types_1.kotoriConfigSchema.parseSafe(config);
|
|
44
|
+
if (!handle.value)
|
|
45
|
+
throw new errror_1.CoreError('Unexpected error in parsing config (basedir,kotori,options)');
|
|
46
|
+
this.baseDir = handle.data.baseDir;
|
|
47
|
+
this.config = handle.data.config;
|
|
48
|
+
this.options = handle.data.options;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.Core = Core;
|
|
52
|
+
exports.default = Core;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { EventType, EventCallback } from '../types';
|
|
2
|
+
import Core from './core';
|
|
3
|
+
type EventBeforeKeys<T> = T extends `before_${infer U}` ? U : never;
|
|
4
|
+
export declare class Events extends Core {
|
|
5
|
+
private eventStack;
|
|
6
|
+
emit<T extends keyof EventType>(type: T, data: Omit<EventType[T], 'type'>): void;
|
|
7
|
+
on<T extends keyof EventType>(type: T, callback: EventCallback<T>): void;
|
|
8
|
+
before<T extends EventBeforeKeys<keyof EventType>>(type: T, callback: EventCallback<`before_${T}`>): void;
|
|
9
|
+
once<T extends keyof EventType>(type: T, callback: EventCallback<T>): void;
|
|
10
|
+
off<T extends keyof EventType>(type: T, callback: EventCallback<T>): void;
|
|
11
|
+
offAll<T extends keyof EventType>(type: T): void;
|
|
12
|
+
}
|
|
13
|
+
export default Events;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Events = void 0;
|
|
7
|
+
const core_1 = __importDefault(require("./core"));
|
|
8
|
+
class Events extends core_1.default {
|
|
9
|
+
eventStack = [];
|
|
10
|
+
emit(type, data) {
|
|
11
|
+
const session = Object.assign(data, { type });
|
|
12
|
+
this.eventStack.filter(el => el.type === type).forEach(el => el.callback(session));
|
|
13
|
+
}
|
|
14
|
+
on(type, callback) {
|
|
15
|
+
// if (this.eventStack.filter(el => el.callback === callback && el.type === type).length > 0) return false;
|
|
16
|
+
this.eventStack.push({ type, callback: callback });
|
|
17
|
+
}
|
|
18
|
+
before(type, callback) {
|
|
19
|
+
this.on(`before_${type}`, callback);
|
|
20
|
+
}
|
|
21
|
+
once(type, callback) {
|
|
22
|
+
const removeSelf = data => {
|
|
23
|
+
const handleArr = this.eventStack.filter(el => el.type !== type && el.callback !== removeSelf);
|
|
24
|
+
this.eventStack = handleArr;
|
|
25
|
+
callback(data);
|
|
26
|
+
};
|
|
27
|
+
this.on(type, removeSelf);
|
|
28
|
+
}
|
|
29
|
+
off(type, callback) {
|
|
30
|
+
const handleArr = this.eventStack.filter(el => el.callback !== callback && el.type !== type);
|
|
31
|
+
// if (this.eventStack.length === handleArr.length) return false;
|
|
32
|
+
this.eventStack = handleArr;
|
|
33
|
+
}
|
|
34
|
+
offAll(type) {
|
|
35
|
+
const handleArr = this.eventStack.filter(el => el.type !== type);
|
|
36
|
+
// if (this.eventStack.length === handleArr.length) return false;
|
|
37
|
+
this.eventStack = handleArr;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.Events = Events;
|
|
41
|
+
exports.default = Events;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import Message from './message';
|
|
2
|
+
export declare class Internal extends Message {
|
|
3
|
+
private getModules;
|
|
4
|
+
private setModules;
|
|
5
|
+
private getAdapters;
|
|
6
|
+
private setAdapters;
|
|
7
|
+
private getBots;
|
|
8
|
+
private setBots;
|
|
9
|
+
private getCommands;
|
|
10
|
+
private setCommands;
|
|
11
|
+
private getCommandData;
|
|
12
|
+
private setCommandData;
|
|
13
|
+
private getMidwares;
|
|
14
|
+
private setMidwares;
|
|
15
|
+
private getRegexps;
|
|
16
|
+
private setRegexps;
|
|
17
|
+
get internal(): {
|
|
18
|
+
getModules: () => import("..").ModuleData[];
|
|
19
|
+
setModules: (key: number, value: import("..").ModuleData) => void;
|
|
20
|
+
getAdapters: () => import("@kotori-bot/tools").obj<[import("..").AdapterConstructor, (import("tsukiko").Parser<unknown> | undefined)?]>;
|
|
21
|
+
setAdapters: (key: string, value: [import("..").AdapterConstructor, (import("tsukiko").Parser<unknown> | undefined)?]) => void;
|
|
22
|
+
getBots: () => import("@kotori-bot/tools").obj<import("..").Api[]>;
|
|
23
|
+
setBots: (key: string, value: import("..").Api[]) => void;
|
|
24
|
+
getCommands: () => import("..").CommandStack[];
|
|
25
|
+
setCommands: (key: number, value: import("..").CommandStack) => void;
|
|
26
|
+
getCommandData: () => import("..").CommandData[];
|
|
27
|
+
setCommandData: (key: number, value: import("..").CommandData) => void;
|
|
28
|
+
getMidwares: () => import("..").MidwareStack[];
|
|
29
|
+
setMidwares: (key: number, value: import("..").MidwareStack) => void;
|
|
30
|
+
getRegexps: () => import("..").RegexpStack[];
|
|
31
|
+
setRegexps: (key: number, value: import("..").RegexpStack) => void;
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
export default Internal;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Internal = void 0;
|
|
7
|
+
const tools_1 = require("@kotori-bot/tools");
|
|
8
|
+
const message_1 = __importDefault(require("./message"));
|
|
9
|
+
const command_1 = __importDefault(require("./command"));
|
|
10
|
+
class Internal extends message_1.default {
|
|
11
|
+
getModules() {
|
|
12
|
+
return this.moduleStack;
|
|
13
|
+
}
|
|
14
|
+
setModules(key, value) {
|
|
15
|
+
this.moduleStack[key] = value;
|
|
16
|
+
}
|
|
17
|
+
getAdapters() {
|
|
18
|
+
return this.adapterStack;
|
|
19
|
+
}
|
|
20
|
+
setAdapters(key, value) {
|
|
21
|
+
this.adapterStack[key] = value;
|
|
22
|
+
}
|
|
23
|
+
getBots() {
|
|
24
|
+
return this.botStack;
|
|
25
|
+
}
|
|
26
|
+
setBots(key, value) {
|
|
27
|
+
this.botStack[key] = value;
|
|
28
|
+
}
|
|
29
|
+
getCommands() {
|
|
30
|
+
return this.commandStack;
|
|
31
|
+
}
|
|
32
|
+
setCommands(key, value) {
|
|
33
|
+
this.commandStack[key] = value;
|
|
34
|
+
}
|
|
35
|
+
getCommandData() {
|
|
36
|
+
(0, tools_1.none)(this);
|
|
37
|
+
return command_1.default.dataList;
|
|
38
|
+
}
|
|
39
|
+
setCommandData(key, value) {
|
|
40
|
+
(0, tools_1.none)(this);
|
|
41
|
+
command_1.default.dataList[key] = value;
|
|
42
|
+
}
|
|
43
|
+
getMidwares() {
|
|
44
|
+
return this.midwareStack;
|
|
45
|
+
}
|
|
46
|
+
setMidwares(key, value) {
|
|
47
|
+
this.midwareStack[key] = value;
|
|
48
|
+
}
|
|
49
|
+
getRegexps() {
|
|
50
|
+
return this.regexpStack;
|
|
51
|
+
}
|
|
52
|
+
setRegexps(key, value) {
|
|
53
|
+
this.regexpStack[key] = value;
|
|
54
|
+
}
|
|
55
|
+
get internal() {
|
|
56
|
+
const getModules = () => this.getModules();
|
|
57
|
+
const setModules = (key, value) => this.setModules(key, value);
|
|
58
|
+
const getAdapters = () => this.getAdapters();
|
|
59
|
+
const setAdapters = (key, value) => this.setAdapters(key, value);
|
|
60
|
+
const getBots = () => this.getBots();
|
|
61
|
+
const setBots = (key, value) => this.setBots(key, value);
|
|
62
|
+
const getCommands = () => this.getCommands();
|
|
63
|
+
const setCommands = (key, value) => this.setCommands(key, value);
|
|
64
|
+
const getCommandData = () => this.getCommandData();
|
|
65
|
+
const setCommandData = (key, value) => this.setCommandData(key, value);
|
|
66
|
+
const getMidwares = () => this.getMidwares();
|
|
67
|
+
const setMidwares = (key, value) => this.setMidwares(key, value);
|
|
68
|
+
const getRegexps = () => this.getRegexps();
|
|
69
|
+
const setRegexps = (key, value) => this.setRegexps(key, value);
|
|
70
|
+
return {
|
|
71
|
+
getModules,
|
|
72
|
+
setModules,
|
|
73
|
+
getAdapters,
|
|
74
|
+
setAdapters,
|
|
75
|
+
getBots,
|
|
76
|
+
setBots,
|
|
77
|
+
getCommands,
|
|
78
|
+
setCommands,
|
|
79
|
+
getCommandData,
|
|
80
|
+
setCommandData,
|
|
81
|
+
getMidwares,
|
|
82
|
+
setMidwares,
|
|
83
|
+
getRegexps,
|
|
84
|
+
setRegexps,
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.Internal = Internal;
|
|
89
|
+
exports.default = Internal;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { CommandConfig, MessageRaw, MessageScope, MidwareStack, CommandStack, RegexpStack, MidwareCallback, RegexpCallback } from '../types';
|
|
2
|
+
import Modules from './modules';
|
|
3
|
+
import Command from './command';
|
|
4
|
+
export declare class Message extends Modules {
|
|
5
|
+
protected readonly midwareStack: MidwareStack[];
|
|
6
|
+
protected readonly commandStack: CommandStack[];
|
|
7
|
+
protected readonly regexpStack: RegexpStack[];
|
|
8
|
+
private handleMessageEvent;
|
|
9
|
+
private handleMidwaresEvent;
|
|
10
|
+
private handleUnloadModuleEvent;
|
|
11
|
+
protected registeMessageEvent(): void;
|
|
12
|
+
midware(callback: MidwareCallback, priority?: number): boolean;
|
|
13
|
+
command(template: string, config?: CommandConfig): Command;
|
|
14
|
+
regexp(match: RegExp, callback: RegexpCallback): boolean;
|
|
15
|
+
boardcast(type: MessageScope, message: MessageRaw): void;
|
|
16
|
+
notify(message: MessageRaw): void;
|
|
17
|
+
}
|
|
18
|
+
export default Message;
|