@meteorstream/koishi-plugin-auto-reply 0.0.2 → 0.0.4
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 +103 -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,103 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Config: () => Config,
|
|
34
|
+
apply: () => apply,
|
|
35
|
+
name: () => name
|
|
36
|
+
});
|
|
37
|
+
module.exports = __toCommonJS(src_exports);
|
|
38
|
+
var import_koishi = require("koishi");
|
|
39
|
+
var import_url = require("url");
|
|
40
|
+
var fs = __toESM(require("fs/promises"));
|
|
41
|
+
var path = __toESM(require("path"));
|
|
42
|
+
var name = "auto-reply";
|
|
43
|
+
var Config = import_koishi.Schema.intersect([
|
|
44
|
+
import_koishi.Schema.object({
|
|
45
|
+
replyList: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
46
|
+
command: import_koishi.Schema.string().description("指令"),
|
|
47
|
+
type: import_koishi.Schema.union(["完全匹配", "模糊匹配"]).description("指令匹配模式").default("模糊匹配"),
|
|
48
|
+
mode: import_koishi.Schema.union(["顺序", "随机"]).description("响应模式").default("随机"),
|
|
49
|
+
address: import_koishi.Schema.array(import_koishi.Schema.object({
|
|
50
|
+
source: import_koishi.Schema.union(["本地", "url"]).description("来源").default("url"),
|
|
51
|
+
link: import_koishi.Schema.string().description("路径")
|
|
52
|
+
})).description("响应情况").role("table")
|
|
53
|
+
})).description("响应指令").role("table")
|
|
54
|
+
// exitCommandList: Schema.array(String).role('table').description('退出选择指令。<br>一行一个指令(此指令 在歌单内容中默认没有使用提示)').default(["0", "不听了"]),
|
|
55
|
+
}),
|
|
56
|
+
import_koishi.Schema.object({
|
|
57
|
+
debugger: import_koishi.Schema.boolean().default(false).description("日志调试模式")
|
|
58
|
+
}).description("开发者选项")
|
|
59
|
+
]);
|
|
60
|
+
var lastUserIndexMap = /* @__PURE__ */ new Map();
|
|
61
|
+
function apply(ctx, config) {
|
|
62
|
+
ctx.on("ready", async () => {
|
|
63
|
+
const logger = ctx.logger("auto-reply");
|
|
64
|
+
const root = path.join(ctx.baseDir, "data", name);
|
|
65
|
+
await fs.mkdir(root, { recursive: true });
|
|
66
|
+
ctx.on("message", (session) => {
|
|
67
|
+
logInfo(root);
|
|
68
|
+
const matchList = config.replyList.filter((item) => {
|
|
69
|
+
return item.type == "完全匹配" ? session.content == item.command : session.content.indexOf(item.command) > -1;
|
|
70
|
+
});
|
|
71
|
+
if (!matchList || matchList.length == 0) {
|
|
72
|
+
logInfo("没有匹配到指令");
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let link = "";
|
|
76
|
+
let index = 0;
|
|
77
|
+
if (matchList[0].mode == "随机") {
|
|
78
|
+
index = Math.floor(Math.random() * matchList[0].address.length);
|
|
79
|
+
} else {
|
|
80
|
+
lastUserIndexMap.set(matchList[0].command, lastUserIndexMap.get(matchList[0].command) ? lastUserIndexMap.get(matchList[0].command) : 0);
|
|
81
|
+
index = lastUserIndexMap.get(matchList[0].command);
|
|
82
|
+
index = ++index > matchList[0].address.length - 1 ? 0 : index;
|
|
83
|
+
lastUserIndexMap.set(matchList[0].command, index);
|
|
84
|
+
}
|
|
85
|
+
link = matchList[0].address[index].source == "本地" ? (0, import_url.pathToFileURL)(path.join(root, matchList[0].address[index].link)).href : matchList[0].address[index].link;
|
|
86
|
+
logInfo(`匹配到指令[${matchList[0].command}]${matchList[0].mode}[${index}]:${link}`);
|
|
87
|
+
session.send(import_koishi.h.audio(link));
|
|
88
|
+
});
|
|
89
|
+
function logInfo(...args) {
|
|
90
|
+
if (config.debugger) {
|
|
91
|
+
logger.info(...args);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
__name(logInfo, "logInfo");
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
__name(apply, "apply");
|
|
98
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
99
|
+
0 && (module.exports = {
|
|
100
|
+
Config,
|
|
101
|
+
apply,
|
|
102
|
+
name
|
|
103
|
+
});
|