@meteorstream/koishi-plugin-auto-reply 0.0.2 → 0.0.3
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 +47 -0
- package/lib/index.js +89 -0
- package/package.json +3 -1
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Context, Schema } from 'koishi';
|
|
2
|
+
export declare const name = "auto-reply";
|
|
3
|
+
export interface Config {
|
|
4
|
+
}
|
|
5
|
+
export declare const Config: Schema<Schemastery.ObjectS<{
|
|
6
|
+
debugger: Schema<boolean, boolean>;
|
|
7
|
+
}> | Schemastery.ObjectS<{
|
|
8
|
+
replyList: Schema<Schemastery.ObjectS<{
|
|
9
|
+
command: Schema<string, string>;
|
|
10
|
+
type: Schema<"完全匹配" | "模糊匹配", "完全匹配" | "模糊匹配">;
|
|
11
|
+
mode: Schema<"顺序" | "随机", "顺序" | "随机">;
|
|
12
|
+
address: Schema<Schemastery.ObjectS<{
|
|
13
|
+
source: Schema<"本地" | "url", "本地" | "url">;
|
|
14
|
+
link: Schema<string, string>;
|
|
15
|
+
}>[], Schemastery.ObjectT<{
|
|
16
|
+
source: Schema<"本地" | "url", "本地" | "url">;
|
|
17
|
+
link: Schema<string, string>;
|
|
18
|
+
}>[]>;
|
|
19
|
+
}>[], Schemastery.ObjectT<{
|
|
20
|
+
command: Schema<string, string>;
|
|
21
|
+
type: Schema<"完全匹配" | "模糊匹配", "完全匹配" | "模糊匹配">;
|
|
22
|
+
mode: Schema<"顺序" | "随机", "顺序" | "随机">;
|
|
23
|
+
address: Schema<Schemastery.ObjectS<{
|
|
24
|
+
source: Schema<"本地" | "url", "本地" | "url">;
|
|
25
|
+
link: Schema<string, string>;
|
|
26
|
+
}>[], Schemastery.ObjectT<{
|
|
27
|
+
source: Schema<"本地" | "url", "本地" | "url">;
|
|
28
|
+
link: Schema<string, string>;
|
|
29
|
+
}>[]>;
|
|
30
|
+
}>[]>;
|
|
31
|
+
}>, {
|
|
32
|
+
debugger: boolean;
|
|
33
|
+
} & import("cosmokit").Dict & {
|
|
34
|
+
replyList: Schemastery.ObjectT<{
|
|
35
|
+
command: Schema<string, string>;
|
|
36
|
+
type: Schema<"完全匹配" | "模糊匹配", "完全匹配" | "模糊匹配">;
|
|
37
|
+
mode: Schema<"顺序" | "随机", "顺序" | "随机">;
|
|
38
|
+
address: Schema<Schemastery.ObjectS<{
|
|
39
|
+
source: Schema<"本地" | "url", "本地" | "url">;
|
|
40
|
+
link: Schema<string, string>;
|
|
41
|
+
}>[], Schemastery.ObjectT<{
|
|
42
|
+
source: Schema<"本地" | "url", "本地" | "url">;
|
|
43
|
+
link: Schema<string, string>;
|
|
44
|
+
}>[]>;
|
|
45
|
+
}>[];
|
|
46
|
+
}>;
|
|
47
|
+
export declare function apply(ctx: Context, config: any): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Config: () => Config,
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
name: () => name
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(src_exports);
|
|
28
|
+
var import_koishi = require("koishi");
|
|
29
|
+
var import_url = require("url");
|
|
30
|
+
var import_path = require("path");
|
|
31
|
+
var name = "auto-reply";
|
|
32
|
+
var Config = import_koishi.Schema.intersect([
|
|
33
|
+
import_koishi.Schema.object({
|
|
34
|
+
replyList: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
35
|
+
command: import_koishi.Schema.string().description("指令"),
|
|
36
|
+
type: import_koishi.Schema.union(["完全匹配", "模糊匹配"]).description("指令匹配模式").default("模糊匹配"),
|
|
37
|
+
mode: import_koishi.Schema.union(["顺序", "随机"]).description("响应模式").default("随机"),
|
|
38
|
+
address: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
39
|
+
source: import_koishi.Schema.union(["本地", "url"]).description("来源").default("url"),
|
|
40
|
+
link: import_koishi.Schema.string().description("路径")
|
|
41
|
+
})).description("响应情况").role("table")
|
|
42
|
+
})).description("响应指令").role("table")
|
|
43
|
+
// exitCommandList: Schema.array(String).role('table').description('退出选择指令。<br>一行一个指令(此指令 在歌单内容中默认没有使用提示)').default(["0", "不听了"]),
|
|
44
|
+
}),
|
|
45
|
+
import_koishi.Schema.object({
|
|
46
|
+
debugger: import_koishi.Schema.boolean().default(false).description("日志调试模式")
|
|
47
|
+
}).description("开发者选项")
|
|
48
|
+
]);
|
|
49
|
+
function apply(ctx, config) {
|
|
50
|
+
ctx.on("ready", async () => {
|
|
51
|
+
const logger = ctx.logger("auto-reply");
|
|
52
|
+
const lastUserIndexMap = /* @__PURE__ */ new Map();
|
|
53
|
+
ctx.on("message", (session) => {
|
|
54
|
+
logInfo((0, import_url.pathToFileURL)((0, import_path.resolve)(__dirname, "logo.png")).href);
|
|
55
|
+
const matchList = config.replyList.filter((item) => {
|
|
56
|
+
return item.type == "完全匹配" ? session.content == item.command : session.content.indexOf(item.command) > -1;
|
|
57
|
+
});
|
|
58
|
+
if (!matchList || matchList.length == 0) {
|
|
59
|
+
logInfo("没有匹配到指令");
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (matchList[0].mode == "随机") {
|
|
63
|
+
const randomIndex = Math.floor(Math.random() * matchList[0].address.length);
|
|
64
|
+
logger.info("匹配到指令", matchList[0].command, ",随机[" + randomIndex + "]:", matchList[0].address[randomIndex].link);
|
|
65
|
+
session.send(import_koishi.h.audio(matchList[0].address[randomIndex].link));
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
lastUserIndexMap.set(matchList[0].command, lastUserIndexMap.get(matchList[0].command) ? lastUserIndexMap.get(matchList[0].command) : 0);
|
|
69
|
+
let index = lastUserIndexMap.get(matchList[0].command);
|
|
70
|
+
index = index > matchList.length - 1 ? 0 : index;
|
|
71
|
+
logInfo(`匹配到指令[${matchList[0].command}]顺序[${index}]:${matchList[0].address[index].link}`);
|
|
72
|
+
session.send(import_koishi.h.audio(matchList[0].address[index].link));
|
|
73
|
+
lastUserIndexMap.set(matchList[0].command, ++index);
|
|
74
|
+
});
|
|
75
|
+
function logInfo(...args) {
|
|
76
|
+
if (config.debugger) {
|
|
77
|
+
logger.info(...args);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
__name(logInfo, "logInfo");
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
__name(apply, "apply");
|
|
84
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
85
|
+
0 && (module.exports = {
|
|
86
|
+
Config,
|
|
87
|
+
apply,
|
|
88
|
+
name
|
|
89
|
+
});
|