@kotori-bot/kotori-plugin-core 1.3.1 → 1.4.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/index.d.ts +1 -1
- package/lib/index.js +87 -90
- package/locales/en_US.json +3 -2
- package/locales/ja_JP.json +2 -1
- package/locales/zh_CN.json +3 -2
- package/locales/zh_TW.json +2 -1
- package/package.json +3 -3
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
3
|
* @Package @kotori-bot/kotori-plugin-core
|
|
4
|
-
* @Version 1.
|
|
5
|
-
* @Author Hotaru <
|
|
4
|
+
* @Version 1.4.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
6
|
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
7
|
* @License GPL-3.0
|
|
8
8
|
* @Link https://github.com/kotorijs/kotori
|
|
9
|
-
* @Date 2024/
|
|
9
|
+
* @Date 2024/8/8 20:54:06
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
"use strict";
|
|
@@ -36,18 +36,18 @@ module.exports = __toCommonJS(src_exports);
|
|
|
36
36
|
var import_kotori_bot = require("kotori-bot");
|
|
37
37
|
const lang = [__dirname, "../locales"];
|
|
38
38
|
function main(ctx) {
|
|
39
|
-
ctx.on("
|
|
40
|
-
const
|
|
39
|
+
ctx.on("before_command", (data) => {
|
|
40
|
+
const quick = data.session.quick.bind(data.session);
|
|
41
41
|
if (!(data.result instanceof import_kotori_bot.CommandError)) {
|
|
42
42
|
const { scope, access } = data.command.meta;
|
|
43
43
|
if (scope && scope !== "all" && data.session.type !== scope) {
|
|
44
44
|
quick("corei18n.template.scope");
|
|
45
45
|
data.cancel();
|
|
46
|
-
} else if (data.session.userId !== data.session.api.adapter.config.master) {
|
|
47
|
-
if (access === import_kotori_bot.
|
|
46
|
+
} else if (String(data.session.userId) !== String(data.session.api.adapter.config.master)) {
|
|
47
|
+
if (access === import_kotori_bot.UserAccess.ADMIN) {
|
|
48
48
|
quick("corei18n.template.no_access_admin");
|
|
49
49
|
data.cancel();
|
|
50
|
-
} else if (access === import_kotori_bot.
|
|
50
|
+
} else if (access === import_kotori_bot.UserAccess.MANGER && (data.session.type === import_kotori_bot.MessageScope.PRIVATE || data.session.type === import_kotori_bot.MessageScope.GROUP && !["owner", "admin"].includes(data.session.sender.role))) {
|
|
51
51
|
quick("corei18n.template.no_access_manger");
|
|
52
52
|
data.cancel();
|
|
53
53
|
}
|
|
@@ -72,17 +72,17 @@ function main(ctx) {
|
|
|
72
72
|
case "syntax":
|
|
73
73
|
quick(["corei18n.template.syntax", [value.index, value.char]]);
|
|
74
74
|
break;
|
|
75
|
-
case "unknown":
|
|
76
|
-
quick(["corei18n.template.unknown", [value.input]]);
|
|
77
|
-
break;
|
|
78
75
|
default:
|
|
79
76
|
}
|
|
80
77
|
});
|
|
81
|
-
ctx.on("command", (
|
|
82
|
-
if (!(
|
|
83
|
-
const { value } =
|
|
84
|
-
const
|
|
78
|
+
ctx.on("command", ({ result, session }) => {
|
|
79
|
+
if (!(result instanceof import_kotori_bot.CommandError)) return;
|
|
80
|
+
const { value } = result;
|
|
81
|
+
const quick = session.quick.bind(session);
|
|
85
82
|
switch (value.type) {
|
|
83
|
+
case "unknown":
|
|
84
|
+
quick(["corei18n.template.unknown", [value.input]]);
|
|
85
|
+
break;
|
|
86
86
|
case "res_error":
|
|
87
87
|
quick(["corei18n.template.res_error", [value.error.message]]);
|
|
88
88
|
break;
|
|
@@ -105,7 +105,7 @@ function main(ctx) {
|
|
|
105
105
|
quick(["corei18n.template.no_exists", [value.target]]);
|
|
106
106
|
break;
|
|
107
107
|
case "error":
|
|
108
|
-
ctx.
|
|
108
|
+
ctx.emit("error", value.error instanceof Error ? value.error : new import_kotori_bot.ModuleError(String(value.error)));
|
|
109
109
|
if (value.error instanceof import_kotori_bot.TsuError) {
|
|
110
110
|
quick(["corei18n.template.res_error", [value.error.message]]);
|
|
111
111
|
return;
|
|
@@ -121,99 +121,96 @@ function main(ctx) {
|
|
|
121
121
|
quick(["corei18n.template.error", [String(value.error)]]);
|
|
122
122
|
break;
|
|
123
123
|
case "data_error":
|
|
124
|
-
quick([
|
|
125
|
-
`corei18n.template.data_error.${typeof value.target === "string" ? "options" : "args"}`,
|
|
126
|
-
[value.target]
|
|
127
|
-
]);
|
|
124
|
+
quick([`corei18n.template.data_error.${typeof value.target === "string" ? "options" : "args"}`, [value.target]]);
|
|
128
125
|
break;
|
|
129
126
|
default:
|
|
130
127
|
}
|
|
131
128
|
});
|
|
132
|
-
ctx.
|
|
129
|
+
ctx.filter({
|
|
130
|
+
test: import_kotori_bot.FilterTestList.USER_ID,
|
|
131
|
+
operator: "==",
|
|
132
|
+
value: "114514"
|
|
133
|
+
}).command("core - core.descr.core").action((_, session) => {
|
|
133
134
|
const { config, baseDir, options } = session.api.adapter.ctx;
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
modules: ctx[import_kotori_bot.Symbols.modules] ? ctx[import_kotori_bot.Symbols.modules].size : 0,
|
|
147
|
-
services: ctx[import_kotori_bot.Symbols.adapter].size,
|
|
148
|
-
bots: botsLength,
|
|
149
|
-
midwares: ctx[import_kotori_bot.Symbols.midware].size,
|
|
150
|
-
commands: ctx[import_kotori_bot.Symbols.command].size,
|
|
151
|
-
regexps: ctx[import_kotori_bot.Symbols.regexp].size
|
|
152
|
-
}
|
|
153
|
-
];
|
|
135
|
+
const botsLength = Array.from(ctx[import_kotori_bot.Symbols.bot].values()).map((set) => Array.from(set.values()).length).reduce((a, b) => a + b, 0);
|
|
136
|
+
return session.format("core.msg.core", {
|
|
137
|
+
lang: config.global.lang,
|
|
138
|
+
root: baseDir.root,
|
|
139
|
+
mode: options.mode,
|
|
140
|
+
modules: ctx[import_kotori_bot.Symbols.modules] ? ctx[import_kotori_bot.Symbols.modules].size : 0,
|
|
141
|
+
services: ctx[import_kotori_bot.Symbols.adapter].size,
|
|
142
|
+
bots: botsLength,
|
|
143
|
+
midwares: ctx[import_kotori_bot.Symbols.midware].size,
|
|
144
|
+
commands: ctx[import_kotori_bot.Symbols.command].size,
|
|
145
|
+
regexps: ctx[import_kotori_bot.Symbols.regexp].size
|
|
146
|
+
});
|
|
154
147
|
});
|
|
155
148
|
ctx.command("bot - core.descr.bot").action((_, session) => {
|
|
156
149
|
const { identity, platform, selfId, config, status } = session.api.adapter;
|
|
157
|
-
return
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
offline_times: status.offlineTimes
|
|
169
|
-
}
|
|
170
|
-
];
|
|
171
|
-
});
|
|
172
|
-
ctx.command("bots - core.descr.bots").action((_, session) => {
|
|
173
|
-
let list = "";
|
|
174
|
-
ctx[import_kotori_bot.Symbols.bot].forEach(
|
|
175
|
-
(bots) => bots.forEach((bot) => {
|
|
176
|
-
const { identity, platform, config, status } = bot.adapter;
|
|
177
|
-
list += session.format("core.msg.bots.list", {
|
|
178
|
-
identity,
|
|
179
|
-
lang: config.lang,
|
|
180
|
-
platform,
|
|
181
|
-
status: status.value
|
|
182
|
-
});
|
|
183
|
-
})
|
|
184
|
-
);
|
|
185
|
-
return ["core.msg.bots", { list }];
|
|
150
|
+
return session.format("core.msg.bot", {
|
|
151
|
+
identity,
|
|
152
|
+
lang: config.lang,
|
|
153
|
+
platform,
|
|
154
|
+
self_id: selfId,
|
|
155
|
+
create_time: session.i18n.time(status.createTime),
|
|
156
|
+
last_msg_time: status.lastMsgTime ? session.i18n.time(status.lastMsgTime) : "",
|
|
157
|
+
received_msg: status.receivedMsg,
|
|
158
|
+
sent_msg: status.sentMsg,
|
|
159
|
+
offline_times: status.offlineTimes
|
|
160
|
+
});
|
|
186
161
|
});
|
|
187
|
-
ctx.command("
|
|
188
|
-
|
|
189
|
-
|
|
162
|
+
ctx.command("bots - core.descr.bots").action(
|
|
163
|
+
(_, session) => session.format("core.msg.bots", {
|
|
164
|
+
list: Array.from(ctx[import_kotori_bot.Symbols.bot].values()).map(
|
|
165
|
+
(bots) => Array.from(bots.values()).map(
|
|
166
|
+
({ adapter: { identity, platform, config, status } }) => session.format("core.msg.bots.list", {
|
|
167
|
+
identity,
|
|
168
|
+
lang: config.lang,
|
|
169
|
+
platform,
|
|
170
|
+
status: status.value
|
|
171
|
+
})
|
|
172
|
+
).join("")
|
|
173
|
+
).join("")
|
|
174
|
+
})
|
|
175
|
+
);
|
|
176
|
+
ctx.command("about - core.descr.about").alias("version").shortcut(["\u5C0F\u9E1F", "\u5C0F\u9CE5", "\u3053\u3068\u308A", "kotori", "Kotori"]).hide().action((_, session) => {
|
|
177
|
+
const { version, license, coreVersion, loaderVersion } = session.api.adapter.ctx.meta;
|
|
178
|
+
return session.format("core.msg.about", {
|
|
179
|
+
version,
|
|
180
|
+
license,
|
|
181
|
+
core_version: coreVersion,
|
|
182
|
+
loader_version: loaderVersion,
|
|
183
|
+
node_version: process.version
|
|
184
|
+
});
|
|
190
185
|
});
|
|
191
|
-
ctx.command("locale <lang> - core.descr.locale").option("G", "global:boolean
|
|
186
|
+
ctx.command("locale <lang> - core.descr.locale").option("G", "global:boolean core.option.locale.global").action(({ args: [lang2], options: { global } }, session) => {
|
|
192
187
|
const { adapter } = session.api;
|
|
193
188
|
if (!["en_US", "ja_JP", "zh_CN", "zh_TW"].includes(lang2)) return "core.msg.locale.invalid";
|
|
194
189
|
if (global) {
|
|
195
190
|
adapter.ctx.root.config.global.lang = lang2;
|
|
196
|
-
adapter.ctx[import_kotori_bot.Symbols.bot].
|
|
197
|
-
(
|
|
198
|
-
|
|
199
|
-
adapter2.config.lang = lang2;
|
|
200
|
-
})
|
|
201
|
-
);
|
|
191
|
+
for (const apis of adapter.ctx[import_kotori_bot.Symbols.bot].values()) {
|
|
192
|
+
for (const { adapter: adapter2 } of apis.values()) adapter2.config.lang = lang2;
|
|
193
|
+
}
|
|
202
194
|
} else {
|
|
203
195
|
adapter.config.lang = lang2;
|
|
204
196
|
}
|
|
205
|
-
return session.
|
|
197
|
+
return session.format(`core.msg.locale${global ? ".global" : ""}`, { lang: lang2 });
|
|
206
198
|
});
|
|
207
|
-
ctx.command("module - core.descr.module").action((
|
|
208
|
-
let
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
199
|
+
ctx.command("module [name] - core.descr.module").action(({ args: [name] }, session) => {
|
|
200
|
+
let modulesList = Array.from(ctx[import_kotori_bot.Symbols.modules].values());
|
|
201
|
+
if (name) {
|
|
202
|
+
modulesList = modulesList.filter(([{ pkg }]) => pkg.name.startsWith(name));
|
|
203
|
+
if (modulesList.length === 0) return session.format("core.msg.module.not_found", { name });
|
|
204
|
+
}
|
|
205
|
+
return session.format("core.msg.module", {
|
|
206
|
+
list: modulesList.map(
|
|
207
|
+
([{ pkg }]) => session.format("core.msg.module.list", {
|
|
208
|
+
name: pkg.name,
|
|
209
|
+
version: pkg.version,
|
|
210
|
+
description: pkg.description
|
|
211
|
+
})
|
|
212
|
+
).join("")
|
|
215
213
|
});
|
|
216
|
-
return ["core.msg.module", { list }];
|
|
217
214
|
});
|
|
218
215
|
}
|
|
219
216
|
// Annotate the CommonJS export names for ESM import in node:
|
package/locales/en_US.json
CHANGED
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
"core.msg.core": "Global language: %lang%\nInstance directory: %root%\nRunning mode: %mode%\nNumber of modules: %modules%\nNumber of services: %services%\nNumber of bot instances: %bots%\nNumber of middlewares: %midwares%\nNumber of commands: %commands%\nNumber of regular expressions: %regexps%",
|
|
32
32
|
"core.msg.bots": "Instance list: %list%",
|
|
33
33
|
"core.msg.bots.list": "\n----------\nID: %identity%\nLanguage: %lang%\nPlatform: %platform%\nStatus: %status%",
|
|
34
|
-
"core.msg.about": "Kotori version: %version%\nLicense: %license%\nNodeJS version: %node_version%",
|
|
34
|
+
"core.msg.about": "Kotori version: %version%\nCore version: %core_version%\n%Loader version: %loader_version%%\nLicense: %license%\nNodeJS version: %node_version%",
|
|
35
35
|
"core.msg.locale": "Successfully set the display language for the current instance to: %lang%",
|
|
36
36
|
"core.msg.locale.global": "Successfully set the global display language to: %lang%",
|
|
37
37
|
"core.msg.locale.invalid": "Parameter is invalid, must be one of the following values: en_US, ja_JP, zh_CN, zh_TW",
|
|
38
38
|
"core.msg.module": "Module list: %list%",
|
|
39
|
-
"core.msg.module.list": "\n----------\nName: %name%\nDescription: %description%\nVersion: %version%"
|
|
39
|
+
"core.msg.module.list": "\n----------\nName: %name%\nDescription: %description%\nVersion: %version%",
|
|
40
|
+
"core.msg.module.not_found": "Module %name% not found"
|
|
40
41
|
}
|
package/locales/ja_JP.json
CHANGED
|
@@ -36,5 +36,6 @@
|
|
|
36
36
|
"core.msg.locale.global": "グローバル表示言語を %lang% に設定しました",
|
|
37
37
|
"core.msg.locale.invalid": "パラメータが無効です。以下の値のいずれかでなければなりません:en_US、ja_JP、zh_CN、zh_TW",
|
|
38
38
|
"core.msg.module": "モジュールリスト:%list%",
|
|
39
|
-
"core.msg.module.list": "\n----------\n名前:%name%\n説明:%description%\nバージョン:%version%"
|
|
39
|
+
"core.msg.module.list": "\n----------\n名前:%name%\n説明:%description%\nバージョン:%version%",
|
|
40
|
+
"core.msg.module.not_found": "%name% モジュールが見つかりませんでした"
|
|
40
41
|
}
|
package/locales/zh_CN.json
CHANGED
|
@@ -31,10 +31,11 @@
|
|
|
31
31
|
"core.msg.core": "全局语言:%lang%\n实例目录:%root%\n运行模式:%mode%\n模块数量:%modules%\n服务数量:%services%\nbot 实例数量:%bots%\n中间件数量:%midwares%\n指令数量:%commands%\n正则数量:%regexps%",
|
|
32
32
|
"core.msg.bots": "实例列表:%list%",
|
|
33
33
|
"core.msg.bots.list": "\n----------\nID:%identity%\n语言:%lang%\n平台:%platform%\n状态:%status%",
|
|
34
|
-
"core.msg.about": "Kotori 版本:%version%\n协议:%license%\nNodeJS 版本:%node_version%",
|
|
34
|
+
"core.msg.about": "Kotori 版本:%version%\n核心版本:%core_version%\n加载器版本:%loader_version%\n协议:%license%\nNodeJS 版本:%node_version%",
|
|
35
35
|
"core.msg.locale": "成功将当前实例显示语言设置为:%lang%",
|
|
36
36
|
"core.msg.locale.global": "成功将全局显示语言设置为:%lang%",
|
|
37
37
|
"core.msg.locale.invalid": "参数无效,必须是以下中的一个值:en_US、ja_JP、zh_CN、zh_TW",
|
|
38
38
|
"core.msg.module": "模块列表:%list%",
|
|
39
|
-
"core.msg.module.list": "\n----------\n名称:%name%\n描述:%description%\n版本:%version%"
|
|
39
|
+
"core.msg.module.list": "\n----------\n名称:%name%\n描述:%description%\n版本:%version%",
|
|
40
|
+
"core.msg.module.not_found": "未找到模块:%name%"
|
|
40
41
|
}
|
package/locales/zh_TW.json
CHANGED
|
@@ -36,5 +36,6 @@
|
|
|
36
36
|
"core.msg.locale.global": "成功將全局顯示語言設置爲:%lang%",
|
|
37
37
|
"core.msg.locale.invalid": "參數無效,必須是以下中的壹個值:en_US、ja_JP、zh_CN、zh_TW",
|
|
38
38
|
"core.msg.module": "模塊列表:%list%",
|
|
39
|
-
"core.msg.module.list": "\n----------\n名稱:%name%\n描述:%description%\n版本:%version%"
|
|
39
|
+
"core.msg.module.list": "\n----------\n名稱:%name%\n描述:%description%\n版本:%version%",
|
|
40
|
+
"core.msg.module.not_found": "未找到模塊"
|
|
40
41
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kotori-bot/kotori-plugin-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"description": "core plugin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -15,9 +15,9 @@
|
|
|
15
15
|
"LICENSE",
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
|
-
"author": "Hotaru <
|
|
18
|
+
"author": "Hotaru <me@hotaru.icu>",
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"kotori-bot": "^1.
|
|
20
|
+
"kotori-bot": "^1.6.0-rc.1"
|
|
21
21
|
},
|
|
22
22
|
"kotori": {
|
|
23
23
|
"meta": {
|