koishi-plugin-smmcat-selfhelp 0.1.1 → 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 +136 -38
- 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);
|
|
@@ -147,11 +184,19 @@ function apply(ctx, config) {
|
|
|
147
184
|
}
|
|
148
185
|
}, "addTemplate");
|
|
149
186
|
const transferTool = {
|
|
187
|
+
// 获取当前时间
|
|
150
188
|
getTime: (session) => (/* @__PURE__ */ new Date()).toLocaleString().replaceAll("/", "-"),
|
|
189
|
+
// 获取随机动漫图
|
|
151
190
|
rollACGImg(session) {
|
|
152
191
|
return import_koishi.h.image("https://www.dmoe.cc/random.php");
|
|
192
|
+
},
|
|
193
|
+
// 跳转分支
|
|
194
|
+
jumpBranch(session, params, ev) {
|
|
195
|
+
userBranch[session.userId] = params?.split("-") || [];
|
|
196
|
+
ev.change = true;
|
|
153
197
|
}
|
|
154
198
|
};
|
|
199
|
+
const userBranch = {};
|
|
155
200
|
const selfhelpMap = {
|
|
156
201
|
// 基地址
|
|
157
202
|
upath: import_path2.default.join(ctx.baseDir, config.mapAddress),
|
|
@@ -181,8 +226,9 @@ function apply(ctx, config) {
|
|
|
181
226
|
let end = false;
|
|
182
227
|
let indePath = [];
|
|
183
228
|
let PathName = [];
|
|
229
|
+
let change = false;
|
|
184
230
|
if (!goal) {
|
|
185
|
-
callback && callback({ selectMenu, lastPath: "", crumbs: "", end });
|
|
231
|
+
callback && callback({ selectMenu, lastPath: "", change, crumbs: "", end });
|
|
186
232
|
return;
|
|
187
233
|
}
|
|
188
234
|
let title = null;
|
|
@@ -195,48 +241,52 @@ function apply(ctx, config) {
|
|
|
195
241
|
selectMenu = void 0;
|
|
196
242
|
indePath.pop();
|
|
197
243
|
PathName.pop();
|
|
198
|
-
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 });
|
|
199
245
|
return true;
|
|
200
246
|
}
|
|
201
247
|
if (selectMenu && typeof selectMenu === "object") {
|
|
202
248
|
selectMenu = selectMenu[item - 1].child;
|
|
203
249
|
if (typeof selectMenu === "string") {
|
|
204
250
|
end = true;
|
|
205
|
-
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 });
|
|
206
252
|
return true;
|
|
207
253
|
}
|
|
208
254
|
}
|
|
209
255
|
});
|
|
210
|
-
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 });
|
|
211
257
|
},
|
|
212
258
|
// 菜单渲染到界面
|
|
213
259
|
markScreen(pathLine, session) {
|
|
214
|
-
let goalItem = {};
|
|
260
|
+
let goalItem = { change: false };
|
|
215
261
|
this.getMenu(pathLine, (ev) => {
|
|
216
262
|
if (ev.end) {
|
|
217
|
-
ev.selectMenu = ev.selectMenu.replace(/%([
|
|
263
|
+
ev.selectMenu = ev.selectMenu.replace(/%([^%]*)%/g, (match, capture) => {
|
|
218
264
|
let result = "";
|
|
219
|
-
|
|
220
|
-
|
|
265
|
+
const temp = capture.split("|");
|
|
266
|
+
if (transferTool[temp[0]]) {
|
|
267
|
+
result = transferTool[temp[0]](session, temp[1], ev) || "";
|
|
221
268
|
}
|
|
222
269
|
return result;
|
|
223
270
|
});
|
|
224
271
|
}
|
|
225
272
|
if (ev.title) {
|
|
226
|
-
ev.title = ev.title.replace(/%([
|
|
273
|
+
ev.title = ev.title.replace(/%([^%]*)%/g, (match, capture) => {
|
|
227
274
|
let result = "";
|
|
228
|
-
|
|
229
|
-
|
|
275
|
+
const temp = capture.split("|");
|
|
276
|
+
if (transferTool[temp[0]]) {
|
|
277
|
+
result = transferTool[temp[0]](session, temp[1], ev) || "";
|
|
230
278
|
}
|
|
231
279
|
return result;
|
|
232
280
|
});
|
|
233
281
|
}
|
|
234
282
|
goalItem = ev;
|
|
235
283
|
});
|
|
236
|
-
return this.format(goalItem);
|
|
284
|
+
return this.format(goalItem, session);
|
|
237
285
|
},
|
|
238
286
|
// 格式化界面输出
|
|
239
|
-
format(goalItem) {
|
|
287
|
+
format(goalItem, session) {
|
|
288
|
+
if (goalItem.change)
|
|
289
|
+
return this.markScreen(userBranch[session.userId].join("-"), session);
|
|
240
290
|
if (!goalItem.selectMenu) {
|
|
241
291
|
return {
|
|
242
292
|
msg: "",
|
|
@@ -244,16 +294,44 @@ function apply(ctx, config) {
|
|
|
244
294
|
};
|
|
245
295
|
}
|
|
246
296
|
if (goalItem.end) {
|
|
247
|
-
|
|
248
|
-
|
|
297
|
+
if (config.scriptMode) {
|
|
298
|
+
return {
|
|
299
|
+
msg: (import_koishi.h.select(goalItem.selectMenu || "", "img").length > 0 ? "" : "【内容】\n") + (goalItem.selectMenu ? `${goalItem.selectMenu.replace(/\\/g, "")}
|
|
249
300
|
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
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
|
+
}
|
|
254
319
|
} else {
|
|
255
|
-
|
|
256
|
-
|
|
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 ? `[当前位置]
|
|
257
335
|
${goalItem.crumbs}
|
|
258
336
|
` : "主菜单\n") + `----------------------------
|
|
259
337
|
` + (goalItem.title ? `${goalItem.title}
|
|
@@ -261,9 +339,10 @@ ${goalItem.crumbs}
|
|
|
261
339
|
` : "") + `${goalItem.selectMenu.map((item) => item.name).join("\n") + "\n\nQ 上页\nP 首页\n0 退出"}
|
|
262
340
|
----------------------------
|
|
263
341
|
`,
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
342
|
+
err: false,
|
|
343
|
+
end: goalItem.end
|
|
344
|
+
};
|
|
345
|
+
}
|
|
267
346
|
}
|
|
268
347
|
}
|
|
269
348
|
};
|
|
@@ -271,12 +350,14 @@ ${goalItem.crumbs}
|
|
|
271
350
|
selfhelpMap.init();
|
|
272
351
|
});
|
|
273
352
|
ctx.command("自助菜单").action(async ({ session }) => {
|
|
274
|
-
|
|
353
|
+
if (!userBranch[session.userId]) {
|
|
354
|
+
userBranch[session.userId] = [];
|
|
355
|
+
}
|
|
275
356
|
while (true) {
|
|
276
|
-
|
|
357
|
+
let data = selfhelpMap.markScreen(userBranch[session.userId].join("-"), session);
|
|
277
358
|
if (data.err) {
|
|
278
|
-
|
|
279
|
-
|
|
359
|
+
userBranch[session.userId].pop();
|
|
360
|
+
let data2 = selfhelpMap.markScreen(userBranch[session.userId].join("-"), session);
|
|
280
361
|
await session.send("操作不对,请重新输入:\n注意需要输入指定范围的下标");
|
|
281
362
|
await session.send(data2.msg);
|
|
282
363
|
}
|
|
@@ -290,7 +371,8 @@ ${goalItem.crumbs}
|
|
|
290
371
|
}
|
|
291
372
|
const res = await session.prompt(config.overtime);
|
|
292
373
|
if (res === void 0) {
|
|
293
|
-
|
|
374
|
+
userBranch[session.userId].length = 0;
|
|
375
|
+
await session.send(!config.scriptMode ? "长时间未操作,退出自助服务" : "长时间未操作,退出剧本");
|
|
294
376
|
break;
|
|
295
377
|
}
|
|
296
378
|
if (!res.trim() || isNaN(Number(res)) && res.toLowerCase() !== "q" && res.toLowerCase() !== "p") {
|
|
@@ -298,22 +380,38 @@ ${goalItem.crumbs}
|
|
|
298
380
|
continue;
|
|
299
381
|
}
|
|
300
382
|
if (res == "0") {
|
|
301
|
-
|
|
383
|
+
if (!config.scriptMode) {
|
|
384
|
+
userBranch[session.userId].length = 0;
|
|
385
|
+
}
|
|
386
|
+
res == "0" && await session.send(!config.scriptMode ? "已退出自助服务" : "已退出剧本");
|
|
302
387
|
break;
|
|
303
388
|
}
|
|
304
|
-
if (res.toLowerCase() === "q") {
|
|
305
|
-
|
|
306
|
-
} else if (res.toLowerCase() === "p") {
|
|
307
|
-
|
|
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;
|
|
308
393
|
} else {
|
|
309
|
-
|
|
394
|
+
userBranch[session.userId].push(res);
|
|
310
395
|
if (data.end) {
|
|
311
396
|
await session.send("已经到底了!");
|
|
312
|
-
|
|
397
|
+
userBranch[session.userId].pop();
|
|
313
398
|
}
|
|
314
399
|
}
|
|
315
400
|
}
|
|
316
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
|
+
}
|
|
317
415
|
}
|
|
318
416
|
__name(apply, "apply");
|
|
319
417
|
// Annotate the CommonJS export names for ESM import in node:
|