koishi-plugin-smmcat-selfhelp 0.1.2 → 0.2.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 -0
- package/lib/index.js +135 -41
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ export interface Config {
|
|
|
4
4
|
mapAddress: string;
|
|
5
5
|
overtime: number;
|
|
6
6
|
debug: boolean;
|
|
7
|
+
scriptMode: boolean;
|
|
7
8
|
}
|
|
8
9
|
export declare const usage = "\n\u901A\u8FC7\u521B\u5EFA\u6587\u4EF6\u5939\u751F\u6210\u5BF9\u5E94\u6620\u5C04\u5173\u7CFB\u7684\u591A\u7EA7\u83DC\u5355\u9009\u9879\u7684\u7B80\u5355\u81EA\u52A9\u83DC\u5355\u63D2\u4EF6\n\n - result.text \u4E2D\u7684\u5185\u5BB9\u4EE3\u8868\u6700\u7EC8\u7684\u56DE\u590D\n - title.text \u4E2D\u7684\u5185\u5BB9\u4EE3\u8868\u8BE5\u5C42\u7EA7\u83DC\u5355\u7684\u6807\u9898\n\n\u53EA\u8981\u4E0A\u8FF0\u6587\u4EF6\u653E\u7F6E\u5728\u5BF9\u5E94\u6587\u4EF6\u5939\u4E2D\uFF0C\u5C31\u4F1A\u6709\u5BF9\u5E94\u7684\u6548\u679C\n\n\u5F53\u542F\u7528[word-core](/market?keyword=word-core)\u4E0E[word-core-grammar-basic](/market?keyword=word-core-grammar-basic)\u63D2\u4EF6\u540E\uFF0C\u53EF\u4EE5\u5C06\u56DE\u590D\u63A5\u5165\u8BCD\u5E93\u89E3\u6790\n";
|
|
9
10
|
export declare const Config: Schema<Config>;
|
package/lib/index.js
CHANGED
|
@@ -101,7 +101,8 @@ var usage = `
|
|
|
101
101
|
var Config = import_koishi.Schema.object({
|
|
102
102
|
mapAddress: import_koishi.Schema.string().default("./data/selfHelp").description("菜单结构放置位置"),
|
|
103
103
|
overtime: import_koishi.Schema.number().default(3e4).description("菜单访问的超时时间"),
|
|
104
|
-
debug: import_koishi.Schema.boolean().default(false).description("日志查看更多信息")
|
|
104
|
+
debug: import_koishi.Schema.boolean().default(false).description("日志查看更多信息"),
|
|
105
|
+
scriptMode: import_koishi.Schema.boolean().default(false).description("开启剧本模式[测试性]:不能主动后退 + 不能返回首页 + 自动保存进度")
|
|
105
106
|
});
|
|
106
107
|
var inject = {
|
|
107
108
|
optional: ["word"]
|
|
@@ -138,7 +139,43 @@ function apply(ctx, config) {
|
|
|
138
139
|
]
|
|
139
140
|
},
|
|
140
141
|
{ name: "3.说明文档", child: "这是 smmcat-helpself 的默认结构,您可以通过 result.text 文件创建最终给定的回复" },
|
|
141
|
-
{ name: "4.更新说明", child: "在 0.1.0 版本后,引入了 word-core 可选服务,并设置了%转义符%,例如下面是获取时间:\n%getTime%\n\n目前提供的转义符只有:getTime -> 获取时间 rollACGImg -> 获取随机动漫图" }
|
|
142
|
+
{ name: "4.更新说明", child: "在 0.1.0 版本后,引入了 word-core 可选服务,并设置了%转义符%,例如下面是获取时间:\n%getTime%\n\n目前提供的转义符只有:getTime -> 获取时间 rollACGImg -> 获取随机动漫图" },
|
|
143
|
+
{
|
|
144
|
+
name: "5.剧本演示",
|
|
145
|
+
child: [
|
|
146
|
+
{
|
|
147
|
+
name: "1.睡一觉",
|
|
148
|
+
child: "一辆马车把你撞战败后,你回到了现实世界..."
|
|
149
|
+
},
|
|
150
|
+
{
|
|
151
|
+
name: "2.冒险去",
|
|
152
|
+
child: [
|
|
153
|
+
{
|
|
154
|
+
name: "1.打特么的 不怂",
|
|
155
|
+
child: [
|
|
156
|
+
{
|
|
157
|
+
name: "1.返回序章",
|
|
158
|
+
child: "%jumpBranch|5%"
|
|
159
|
+
}
|
|
160
|
+
],
|
|
161
|
+
title: "她们把你骗的连裤衩都没了"
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
name: "2.不敢打 委婉拒绝",
|
|
165
|
+
child: [
|
|
166
|
+
{
|
|
167
|
+
name: "1.返回序章",
|
|
168
|
+
child: "%jumpBranch|5%"
|
|
169
|
+
}
|
|
170
|
+
],
|
|
171
|
+
title: "她们把你打了一顿,抢劫跑人"
|
|
172
|
+
}
|
|
173
|
+
],
|
|
174
|
+
title: "你遇到了一个冒险小队。小队里的人物中一个是爆乳法师 42,一个是 女哥布林 Shigma。\r\n她们邀请你讨伐史莱姆。 你决定...\r\n(刚开始你还未了解这个世界,请谨慎选择...)"
|
|
175
|
+
}
|
|
176
|
+
],
|
|
177
|
+
title: import_koishi.h.image("https://forum.koishi.xyz/user_avatar/forum.koishi.xyz/lizard/96/2522_2.png") + "\r\n这是一个异世界,你果然...又被撞到异世界里了。依然到了异世界,那就拿出真本事吧!"
|
|
178
|
+
}
|
|
142
179
|
];
|
|
143
180
|
try {
|
|
144
181
|
await createDirMapByObject(obj, upath);
|
|
@@ -146,16 +183,20 @@ function apply(ctx, config) {
|
|
|
146
183
|
console.log(error);
|
|
147
184
|
}
|
|
148
185
|
}, "addTemplate");
|
|
149
|
-
const fileData = {};
|
|
150
186
|
const transferTool = {
|
|
187
|
+
// 获取当前时间
|
|
151
188
|
getTime: (session) => (/* @__PURE__ */ new Date()).toLocaleString().replaceAll("/", "-"),
|
|
189
|
+
// 获取随机动漫图
|
|
152
190
|
rollACGImg(session) {
|
|
153
191
|
return import_koishi.h.image("https://www.dmoe.cc/random.php");
|
|
154
192
|
},
|
|
155
|
-
|
|
156
|
-
|
|
193
|
+
// 跳转分支
|
|
194
|
+
jumpBranch(session, params, ev) {
|
|
195
|
+
userBranch[session.userId] = params?.split("-") || [];
|
|
196
|
+
ev.change = true;
|
|
157
197
|
}
|
|
158
198
|
};
|
|
199
|
+
const userBranch = {};
|
|
159
200
|
const selfhelpMap = {
|
|
160
201
|
// 基地址
|
|
161
202
|
upath: import_path2.default.join(ctx.baseDir, config.mapAddress),
|
|
@@ -185,8 +226,9 @@ function apply(ctx, config) {
|
|
|
185
226
|
let end = false;
|
|
186
227
|
let indePath = [];
|
|
187
228
|
let PathName = [];
|
|
229
|
+
let change = false;
|
|
188
230
|
if (!goal) {
|
|
189
|
-
callback && callback({ selectMenu, lastPath: "", crumbs: "", end });
|
|
231
|
+
callback && callback({ selectMenu, lastPath: "", change, crumbs: "", end });
|
|
190
232
|
return;
|
|
191
233
|
}
|
|
192
234
|
let title = null;
|
|
@@ -199,48 +241,52 @@ function apply(ctx, config) {
|
|
|
199
241
|
selectMenu = void 0;
|
|
200
242
|
indePath.pop();
|
|
201
243
|
PathName.pop();
|
|
202
|
-
callback && callback({ selectMenu, lastPath: indePath.join("-"), crumbs: PathName.slice(-3).reverse().join("<"), end });
|
|
244
|
+
callback && callback({ selectMenu, lastPath: indePath.join("-"), change, crumbs: PathName.slice(-3).reverse().join("<"), end });
|
|
203
245
|
return true;
|
|
204
246
|
}
|
|
205
247
|
if (selectMenu && typeof selectMenu === "object") {
|
|
206
248
|
selectMenu = selectMenu[item - 1].child;
|
|
207
249
|
if (typeof selectMenu === "string") {
|
|
208
250
|
end = true;
|
|
209
|
-
callback && callback({ selectMenu, lastPath: indePath.join("-"), crumbs: PathName.slice(-3).reverse().join("<"), end });
|
|
251
|
+
callback && callback({ selectMenu, lastPath: indePath.join("-"), change, crumbs: PathName.slice(-3).reverse().join("<"), end });
|
|
210
252
|
return true;
|
|
211
253
|
}
|
|
212
254
|
}
|
|
213
255
|
});
|
|
214
|
-
end || callback && callback({ selectMenu, title, lastPath: indePath.join("-"), crumbs: PathName.reverse().slice(-3).join("<"), end });
|
|
256
|
+
end || callback && callback({ selectMenu, title, lastPath: indePath.join("-"), change, crumbs: PathName.reverse().slice(-3).join("<"), end });
|
|
215
257
|
},
|
|
216
258
|
// 菜单渲染到界面
|
|
217
259
|
markScreen(pathLine, session) {
|
|
218
|
-
let goalItem = {};
|
|
260
|
+
let goalItem = { change: false };
|
|
219
261
|
this.getMenu(pathLine, (ev) => {
|
|
220
262
|
if (ev.end) {
|
|
221
|
-
ev.selectMenu = ev.selectMenu.replace(/%([
|
|
263
|
+
ev.selectMenu = ev.selectMenu.replace(/%([^%]*)%/g, (match, capture) => {
|
|
222
264
|
let result = "";
|
|
223
|
-
|
|
224
|
-
|
|
265
|
+
const temp = capture.split("|");
|
|
266
|
+
if (transferTool[temp[0]]) {
|
|
267
|
+
result = transferTool[temp[0]](session, temp[1], ev) || "";
|
|
225
268
|
}
|
|
226
269
|
return result;
|
|
227
270
|
});
|
|
228
271
|
}
|
|
229
272
|
if (ev.title) {
|
|
230
|
-
ev.title = ev.title.replace(/%([
|
|
273
|
+
ev.title = ev.title.replace(/%([^%]*)%/g, (match, capture) => {
|
|
231
274
|
let result = "";
|
|
232
|
-
|
|
233
|
-
|
|
275
|
+
const temp = capture.split("|");
|
|
276
|
+
if (transferTool[temp[0]]) {
|
|
277
|
+
result = transferTool[temp[0]](session, temp[1], ev) || "";
|
|
234
278
|
}
|
|
235
279
|
return result;
|
|
236
280
|
});
|
|
237
281
|
}
|
|
238
282
|
goalItem = ev;
|
|
239
283
|
});
|
|
240
|
-
return this.format(goalItem);
|
|
284
|
+
return this.format(goalItem, session);
|
|
241
285
|
},
|
|
242
286
|
// 格式化界面输出
|
|
243
|
-
format(goalItem) {
|
|
287
|
+
format(goalItem, session) {
|
|
288
|
+
if (goalItem.change)
|
|
289
|
+
return this.markScreen(userBranch[session.userId].join("-"), session);
|
|
244
290
|
if (!goalItem.selectMenu) {
|
|
245
291
|
return {
|
|
246
292
|
msg: "",
|
|
@@ -248,16 +294,44 @@ function apply(ctx, config) {
|
|
|
248
294
|
};
|
|
249
295
|
}
|
|
250
296
|
if (goalItem.end) {
|
|
251
|
-
|
|
252
|
-
|
|
297
|
+
if (config.scriptMode) {
|
|
298
|
+
return {
|
|
299
|
+
msg: (import_koishi.h.select(goalItem.selectMenu || "", "img").length > 0 ? "" : "【内容】\n") + (goalItem.selectMenu ? `${goalItem.selectMenu.replace(/\\/g, "")}
|
|
253
300
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
301
|
+
` : "") + `
|
|
302
|
+
|
|
303
|
+
0 退出
|
|
304
|
+
----------------------------
|
|
305
|
+
` + (goalItem.crumbs ? `[当前位置]${goalItem.crumbs}
|
|
306
|
+
` : "序章\n"),
|
|
307
|
+
err: false,
|
|
308
|
+
end: goalItem.end
|
|
309
|
+
};
|
|
310
|
+
} else {
|
|
311
|
+
return {
|
|
312
|
+
msg: goalItem.selectMenu.replace(/\\/g, "") + (goalItem.crumbs ? `
|
|
313
|
+
|
|
314
|
+
[当前位置] ${goalItem.crumbs}` : "\n\n主菜单") + "\n\nQ 上页\n\n0 退出",
|
|
315
|
+
err: false,
|
|
316
|
+
end: goalItem.end
|
|
317
|
+
};
|
|
318
|
+
}
|
|
258
319
|
} else {
|
|
259
|
-
|
|
260
|
-
|
|
320
|
+
if (config.scriptMode) {
|
|
321
|
+
return {
|
|
322
|
+
msg: (import_koishi.h.select(goalItem.title || "", "img").length > 0 ? "" : "【内容】\n") + (goalItem.title ? `${goalItem.title.replace(/\\/g, "")}
|
|
323
|
+
|
|
324
|
+
` : "") + `${goalItem.selectMenu.map((item) => item.name).join("\n") + "\n\n0 退出"}
|
|
325
|
+
----------------------------
|
|
326
|
+
` + (goalItem.crumbs ? `[当前位置]
|
|
327
|
+
${goalItem.crumbs}
|
|
328
|
+
` : "序章\n"),
|
|
329
|
+
err: false,
|
|
330
|
+
end: goalItem.end
|
|
331
|
+
};
|
|
332
|
+
} else {
|
|
333
|
+
return {
|
|
334
|
+
msg: (goalItem.crumbs ? `[当前位置]
|
|
261
335
|
${goalItem.crumbs}
|
|
262
336
|
` : "主菜单\n") + `----------------------------
|
|
263
337
|
` + (goalItem.title ? `${goalItem.title}
|
|
@@ -265,9 +339,10 @@ ${goalItem.crumbs}
|
|
|
265
339
|
` : "") + `${goalItem.selectMenu.map((item) => item.name).join("\n") + "\n\nQ 上页\nP 首页\n0 退出"}
|
|
266
340
|
----------------------------
|
|
267
341
|
`,
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
342
|
+
err: false,
|
|
343
|
+
end: goalItem.end
|
|
344
|
+
};
|
|
345
|
+
}
|
|
271
346
|
}
|
|
272
347
|
}
|
|
273
348
|
};
|
|
@@ -275,12 +350,14 @@ ${goalItem.crumbs}
|
|
|
275
350
|
selfhelpMap.init();
|
|
276
351
|
});
|
|
277
352
|
ctx.command("自助菜单").action(async ({ session }) => {
|
|
278
|
-
|
|
353
|
+
if (!userBranch[session.userId]) {
|
|
354
|
+
userBranch[session.userId] = [];
|
|
355
|
+
}
|
|
279
356
|
while (true) {
|
|
280
|
-
|
|
357
|
+
let data = selfhelpMap.markScreen(userBranch[session.userId].join("-"), session);
|
|
281
358
|
if (data.err) {
|
|
282
|
-
|
|
283
|
-
|
|
359
|
+
userBranch[session.userId].pop();
|
|
360
|
+
let data2 = selfhelpMap.markScreen(userBranch[session.userId].join("-"), session);
|
|
284
361
|
await session.send("操作不对,请重新输入:\n注意需要输入指定范围的下标");
|
|
285
362
|
await session.send(data2.msg);
|
|
286
363
|
}
|
|
@@ -294,7 +371,8 @@ ${goalItem.crumbs}
|
|
|
294
371
|
}
|
|
295
372
|
const res = await session.prompt(config.overtime);
|
|
296
373
|
if (res === void 0) {
|
|
297
|
-
|
|
374
|
+
userBranch[session.userId].length = 0;
|
|
375
|
+
await session.send(!config.scriptMode ? "长时间未操作,退出自助服务" : "长时间未操作,退出剧本");
|
|
298
376
|
break;
|
|
299
377
|
}
|
|
300
378
|
if (!res.trim() || isNaN(Number(res)) && res.toLowerCase() !== "q" && res.toLowerCase() !== "p") {
|
|
@@ -302,22 +380,38 @@ ${goalItem.crumbs}
|
|
|
302
380
|
continue;
|
|
303
381
|
}
|
|
304
382
|
if (res == "0") {
|
|
305
|
-
|
|
383
|
+
if (!config.scriptMode) {
|
|
384
|
+
userBranch[session.userId].length = 0;
|
|
385
|
+
}
|
|
386
|
+
res == "0" && await session.send(!config.scriptMode ? "已退出自助服务" : "已退出剧本");
|
|
306
387
|
break;
|
|
307
388
|
}
|
|
308
|
-
if (res.toLowerCase() === "q") {
|
|
309
|
-
|
|
310
|
-
} else if (res.toLowerCase() === "p") {
|
|
311
|
-
|
|
389
|
+
if (!config.scriptMode && res.toLowerCase() === "q") {
|
|
390
|
+
userBranch[session.userId].pop();
|
|
391
|
+
} else if (!config.scriptMode && res.toLowerCase() === "p") {
|
|
392
|
+
userBranch[session.userId].length = 0;
|
|
312
393
|
} else {
|
|
313
|
-
|
|
394
|
+
userBranch[session.userId].push(res);
|
|
314
395
|
if (data.end) {
|
|
315
396
|
await session.send("已经到底了!");
|
|
316
|
-
|
|
397
|
+
userBranch[session.userId].pop();
|
|
317
398
|
}
|
|
318
399
|
}
|
|
319
400
|
}
|
|
320
401
|
});
|
|
402
|
+
if (config.scriptMode) {
|
|
403
|
+
ctx.command("重置进度").action(async ({ session }) => {
|
|
404
|
+
if (!userBranch[session.userId]?.length) {
|
|
405
|
+
await session.send("你的当前进度不需要重置");
|
|
406
|
+
}
|
|
407
|
+
await session.send("是否要重置当前进度?\n 20秒回复:是/否");
|
|
408
|
+
const res = await session.prompt(2e4);
|
|
409
|
+
if (res === "是") {
|
|
410
|
+
userBranch[session.userId] = [];
|
|
411
|
+
await session.send("已重置当前进度");
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
321
415
|
}
|
|
322
416
|
__name(apply, "apply");
|
|
323
417
|
// Annotate the CommonJS export names for ESM import in node:
|