kotori-plugin-testing 1.2.0 → 1.3.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 +13 -10
- package/lib/index.js +97 -46
- package/package.json +3 -6
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
import { Tsu, type CommandAction, type Session, KotoriPlugin } from 'kotori-bot';
|
|
2
|
+
export declare class TestingPlugin extends KotoriPlugin<Tsu.infer<typeof TestingPlugin.schema>> {
|
|
3
|
+
static schema: import("kotori-bot").ObjectParser<{
|
|
4
|
+
config1: import("kotori-bot").Parser<number | undefined>;
|
|
5
|
+
config2: import("kotori-bot").Parser<boolean | undefined>;
|
|
6
|
+
config3: import("kotori-bot").Parser<"on" | "off" | undefined>;
|
|
7
|
+
}>;
|
|
8
|
+
onReady(): Promise<void>;
|
|
9
|
+
echo(data: Parameters<CommandAction>[0], session: Session): string;
|
|
10
|
+
eval({ args }: Parameters<CommandAction>[0], session: Session): Promise<string | import("kotori-bot").SendMessageResponse>;
|
|
11
|
+
static print(match: RegExpExecArray): string;
|
|
12
|
+
task(): void;
|
|
13
|
+
}
|
package/lib/index.js
CHANGED
|
@@ -1,48 +1,99 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* @Package kotori-plugin-testing
|
|
4
|
+
* @Version 1.3.0
|
|
5
|
+
* @Author Hotaru <me@hotaru.icu>
|
|
6
|
+
* @Copyright 2024 Hotaru. All rights reserved.
|
|
7
|
+
* @License GPL-3.0
|
|
8
|
+
* @Link https://github.com/kotorijs/kotori
|
|
9
|
+
* @Date 2024/8/8 20:54:15
|
|
10
|
+
*/
|
|
11
|
+
|
|
1
12
|
"use strict";
|
|
2
|
-
Object.defineProperty
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
13
|
+
var __defProp = Object.defineProperty;
|
|
14
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
15
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
16
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
17
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
18
|
+
var __export = (target, all) => {
|
|
19
|
+
for (var name in all)
|
|
20
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
21
|
+
};
|
|
22
|
+
var __copyProps = (to, from, except, desc) => {
|
|
23
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
24
|
+
for (let key of __getOwnPropNames(from))
|
|
25
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
26
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
27
|
+
}
|
|
28
|
+
return to;
|
|
29
|
+
};
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
var __decorateClass = (decorators, target, key, kind) => {
|
|
32
|
+
var result2 = kind > 1 ? void 0 : kind ? __getOwnPropDesc(target, key) : target;
|
|
33
|
+
for (var i = decorators.length - 1, decorator; i >= 0; i--)
|
|
34
|
+
if (decorator = decorators[i])
|
|
35
|
+
result2 = (kind ? decorator(target, key, result2) : decorator(result2)) || result2;
|
|
36
|
+
if (kind && result2) __defProp(target, key, result2);
|
|
37
|
+
return result2;
|
|
38
|
+
};
|
|
39
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
40
|
+
var src_exports = {};
|
|
41
|
+
__export(src_exports, {
|
|
42
|
+
TestingPlugin: () => TestingPlugin
|
|
43
|
+
});
|
|
44
|
+
module.exports = __toCommonJS(src_exports);
|
|
45
|
+
var import_kotori_bot = require("kotori-bot");
|
|
46
|
+
const plugin = (0, import_kotori_bot.plugins)([__dirname, "../"]);
|
|
47
|
+
let TestingPlugin = class extends import_kotori_bot.KotoriPlugin {
|
|
48
|
+
async onReady() {
|
|
49
|
+
}
|
|
50
|
+
echo(data, session2) {
|
|
51
|
+
this.ctx.logger.debug(data);
|
|
52
|
+
this.ctx.logger.debug(session2);
|
|
53
|
+
return data.args.join(" ");
|
|
54
|
+
}
|
|
55
|
+
async eval({ args }, session) {
|
|
56
|
+
let code = args.join(" ");
|
|
57
|
+
if (!code.trim()) code = (await session.prompt("Input the code:")).toString();
|
|
58
|
+
try {
|
|
59
|
+
const result = eval(code);
|
|
60
|
+
return session.json(result);
|
|
61
|
+
} catch (error) {
|
|
62
|
+
return session.format("eval error:~\n{0}", [error instanceof Error ? error.message : String(error)]);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
static print(match) {
|
|
66
|
+
return match[1];
|
|
67
|
+
}
|
|
68
|
+
// @plugin.task({ cron: '0/10 * * * * *' })
|
|
69
|
+
task() {
|
|
70
|
+
this.ctx.logger.info("task run!");
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
__publicField(TestingPlugin, "schema", import_kotori_bot.Tsu.Object({
|
|
74
|
+
config1: import_kotori_bot.Tsu.Number().range(0, 10).optional(),
|
|
75
|
+
config2: import_kotori_bot.Tsu.Boolean().optional(),
|
|
76
|
+
config3: import_kotori_bot.Tsu.Union(import_kotori_bot.Tsu.Literal("on"), import_kotori_bot.Tsu.Literal("off")).optional()
|
|
77
|
+
}));
|
|
78
|
+
__decorateClass([
|
|
79
|
+
plugin.on({ type: "ready" })
|
|
80
|
+
], TestingPlugin.prototype, "onReady", 1);
|
|
81
|
+
__decorateClass([
|
|
82
|
+
plugin.command({ template: "echo <...content>" })
|
|
83
|
+
], TestingPlugin.prototype, "echo", 1);
|
|
84
|
+
__decorateClass([
|
|
85
|
+
plugin.command({ template: "eval [...code]", access: import_kotori_bot.UserAccess.ADMIN })
|
|
86
|
+
], TestingPlugin.prototype, "eval", 1);
|
|
87
|
+
__decorateClass([
|
|
88
|
+
plugin.schema
|
|
89
|
+
], TestingPlugin, "schema", 2);
|
|
90
|
+
__decorateClass([
|
|
91
|
+
plugin.regexp({ match: /^(.*)#print$/ })
|
|
92
|
+
], TestingPlugin, "print", 1);
|
|
93
|
+
TestingPlugin = __decorateClass([
|
|
94
|
+
plugin.import
|
|
95
|
+
], TestingPlugin);
|
|
96
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
97
|
+
0 && (module.exports = {
|
|
98
|
+
TestingPlugin
|
|
12
99
|
});
|
|
13
|
-
/* 设置依赖服务 */
|
|
14
|
-
exports.inject = ['database'];
|
|
15
|
-
/* 插件入口 */
|
|
16
|
-
function main(ctx, config) {
|
|
17
|
-
/* 事件监听 */
|
|
18
|
-
ctx.on('on_group_decrease', (session) => {
|
|
19
|
-
session.quick([
|
|
20
|
-
session.userId === session.operatorId ? '%target% 默默的退出了群聊' : '%target% 被 %target% 制裁了...',
|
|
21
|
-
{
|
|
22
|
-
target: session.userId,
|
|
23
|
-
operator: session.operatorId
|
|
24
|
-
}
|
|
25
|
-
]);
|
|
26
|
-
});
|
|
27
|
-
/* 中间件注册 */
|
|
28
|
-
ctx.midware((next, session) => {
|
|
29
|
-
const s = session;
|
|
30
|
-
if (s.message.startsWith('说') || s.message.includes('说')) {
|
|
31
|
-
s.message = `${s.api.adapter.config['command-prefix']}echo`;
|
|
32
|
-
}
|
|
33
|
-
next();
|
|
34
|
-
}, 10);
|
|
35
|
-
/* 指令注册 */
|
|
36
|
-
ctx
|
|
37
|
-
.command('echo <content> [num:number=3]')
|
|
38
|
-
.action((data, session) => {
|
|
39
|
-
ctx.logger.debug(data, data.args[0]);
|
|
40
|
-
ctx.logger.debug(session.message);
|
|
41
|
-
return [`返回消息:~%message%`, { message: data.args[0] }];
|
|
42
|
-
})
|
|
43
|
-
.alias('print')
|
|
44
|
-
.scope(kotori_bot_1.MessageScope.GROUP);
|
|
45
|
-
/* 正则注册 */
|
|
46
|
-
ctx.regexp(/^(.*)#print$/, (match) => match[1]);
|
|
47
|
-
}
|
|
48
|
-
exports.main = main;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "kotori-plugin-testing",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "testing plugin",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"keywords": [
|
|
@@ -15,11 +15,8 @@
|
|
|
15
15
|
"LICENSE",
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
|
-
"author": "Hotaru <
|
|
18
|
+
"author": "Hotaru <me@hotaru.icu>",
|
|
19
19
|
"peerDependencies": {
|
|
20
|
-
"kotori-bot": "^
|
|
21
|
-
},
|
|
22
|
-
"scripts": {
|
|
23
|
-
"build": "tsc --build"
|
|
20
|
+
"kotori-bot": "^1.6.0-rc.1"
|
|
24
21
|
}
|
|
25
22
|
}
|