@meteorstream/koishi-plugin-auto-reply 0.0.4 → 0.0.5
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.js +15 -17
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -64,27 +64,25 @@ function apply(ctx, config) {
|
|
|
64
64
|
const root = path.join(ctx.baseDir, "data", name);
|
|
65
65
|
await fs.mkdir(root, { recursive: true });
|
|
66
66
|
ctx.on("message", (session) => {
|
|
67
|
-
logInfo(root);
|
|
68
67
|
const matchList = config.replyList.filter((item) => {
|
|
69
68
|
return item.type == "完全匹配" ? session.content == item.command : session.content.indexOf(item.command) > -1;
|
|
70
69
|
});
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
70
|
+
if (matchList && matchList.length > 0) {
|
|
71
|
+
let match = matchList[0];
|
|
72
|
+
let link = "";
|
|
73
|
+
let index = 0;
|
|
74
|
+
if (match.mode == "随机") {
|
|
75
|
+
index = Math.floor(Math.random() * match.address.length);
|
|
76
|
+
} else {
|
|
77
|
+
lastUserIndexMap.set(match.command, lastUserIndexMap.get(match.command) ? lastUserIndexMap.get(match.command) : 0);
|
|
78
|
+
index = lastUserIndexMap.get(match.command);
|
|
79
|
+
index = ++index > match.address.length - 1 ? 0 : index;
|
|
80
|
+
lastUserIndexMap.set(match.command, index);
|
|
81
|
+
}
|
|
82
|
+
link = match.address[index].source == "本地" ? (0, import_url.pathToFileURL)(path.join(root, match.address[index].link)).href : match.address[index].link;
|
|
83
|
+
logInfo(`匹配到指令[${match.command}]${match.mode}[${index}]:${link}`);
|
|
84
|
+
session.send(import_koishi.h.audio(link));
|
|
74
85
|
}
|
|
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
86
|
});
|
|
89
87
|
function logInfo(...args) {
|
|
90
88
|
if (config.debugger) {
|