koishi-plugin-smmcat-selfhelp 0.1.0 → 0.1.2

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 CHANGED
@@ -5,6 +5,9 @@ export interface Config {
5
5
  overtime: number;
6
6
  debug: boolean;
7
7
  }
8
- 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";
8
+ 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
9
  export declare const Config: Schema<Config>;
10
+ export declare const inject: {
11
+ optional: string[];
12
+ };
10
13
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -32,6 +32,7 @@ var src_exports = {};
32
32
  __export(src_exports, {
33
33
  Config: () => Config,
34
34
  apply: () => apply,
35
+ inject: () => inject,
35
36
  name: () => name,
36
37
  usage: () => usage
37
38
  });
@@ -94,12 +95,17 @@ var usage = `
94
95
  - title.text 中的内容代表该层级菜单的标题
95
96
 
96
97
  只要上述文件放置在对应文件夹中,就会有对应的效果
98
+
99
+ 当启用[word-core](/market?keyword=word-core)与[word-core-grammar-basic](/market?keyword=word-core-grammar-basic)插件后,可以将回复接入词库解析
97
100
  `;
98
101
  var Config = import_koishi.Schema.object({
99
102
  mapAddress: import_koishi.Schema.string().default("./data/selfHelp").description("菜单结构放置位置"),
100
103
  overtime: import_koishi.Schema.number().default(3e4).description("菜单访问的超时时间"),
101
104
  debug: import_koishi.Schema.boolean().default(false).description("日志查看更多信息")
102
105
  });
106
+ var inject = {
107
+ optional: ["word"]
108
+ };
103
109
  function apply(ctx, config) {
104
110
  const addTemplate = /* @__PURE__ */ __name(async (upath) => {
105
111
  const obj = [
@@ -131,7 +137,8 @@ function apply(ctx, config) {
131
137
  }
132
138
  ]
133
139
  },
134
- { name: "3.说明文档", child: "这是 smmcat-helpself 的默认结构,您可以通过 result.text 文件创建最终给定的回复" }
140
+ { name: "3.说明文档", child: "这是 smmcat-helpself 的默认结构,您可以通过 result.text 文件创建最终给定的回复" },
141
+ { name: "4.更新说明", child: "在 0.1.0 版本后,引入了 word-core 可选服务,并设置了%转义符%,例如下面是获取时间:\n%getTime%\n\n目前提供的转义符只有:getTime -> 获取时间 rollACGImg -> 获取随机动漫图" }
135
142
  ];
136
143
  try {
137
144
  await createDirMapByObject(obj, upath);
@@ -139,6 +146,16 @@ function apply(ctx, config) {
139
146
  console.log(error);
140
147
  }
141
148
  }, "addTemplate");
149
+ const fileData = {};
150
+ const transferTool = {
151
+ getTime: (session) => (/* @__PURE__ */ new Date()).toLocaleString().replaceAll("/", "-"),
152
+ rollACGImg(session) {
153
+ return import_koishi.h.image("https://www.dmoe.cc/random.php");
154
+ },
155
+ jumpAonther(session) {
156
+ fileData[session.userId] = "1-1-1-1-1-2";
157
+ }
158
+ };
142
159
  const selfhelpMap = {
143
160
  // 基地址
144
161
  upath: import_path2.default.join(ctx.baseDir, config.mapAddress),
@@ -197,9 +214,27 @@ function apply(ctx, config) {
197
214
  end || callback && callback({ selectMenu, title, lastPath: indePath.join("-"), crumbs: PathName.reverse().slice(-3).join("<"), end });
198
215
  },
199
216
  // 菜单渲染到界面
200
- markScreen(pathLine) {
217
+ markScreen(pathLine, session) {
201
218
  let goalItem = {};
202
219
  this.getMenu(pathLine, (ev) => {
220
+ if (ev.end) {
221
+ ev.selectMenu = ev.selectMenu.replace(/%([a-z|A-Z]+)%/g, (match, capture) => {
222
+ let result = "";
223
+ if (transferTool[capture]) {
224
+ result = transferTool[capture](session) || "";
225
+ }
226
+ return result;
227
+ });
228
+ }
229
+ if (ev.title) {
230
+ ev.title = ev.title.replace(/%([a-z|A-Z]+)%/g, (match, capture) => {
231
+ let result = "";
232
+ if (transferTool[capture]) {
233
+ result = transferTool[capture](session) || "";
234
+ }
235
+ return result;
236
+ });
237
+ }
203
238
  goalItem = ev;
204
239
  });
205
240
  return this.format(goalItem);
@@ -242,17 +277,24 @@ ${goalItem.crumbs}
242
277
  ctx.command("自助菜单").action(async ({ session }) => {
243
278
  const proce = [];
244
279
  while (true) {
245
- const data = selfhelpMap.markScreen(proce.join("-"));
280
+ const data = selfhelpMap.markScreen(proce.join("-"), session);
246
281
  if (data.err) {
247
282
  proce.pop();
248
- const data2 = selfhelpMap.markScreen(proce.join("-"));
283
+ const data2 = selfhelpMap.markScreen(proce.join("-"), session);
249
284
  await session.send("操作不对,请重新输入:\n注意需要输入指定范围的下标");
250
285
  await session.send(data2.msg);
251
286
  }
252
- await session.send(data.msg);
287
+ if (ctx.word) {
288
+ const msg = await ctx.word.driver.parMsg(data.msg, { saveDB: "smm" }, session);
289
+ if (msg) {
290
+ await session.send(msg);
291
+ }
292
+ } else {
293
+ await session.send(data.msg);
294
+ }
253
295
  const res = await session.prompt(config.overtime);
254
296
  if (res === void 0) {
255
- res == "0" && await session.send("长时间未操作,退出自助服务");
297
+ await session.send("长时间未操作,退出自助服务");
256
298
  break;
257
299
  }
258
300
  if (!res.trim() || isNaN(Number(res)) && res.toLowerCase() !== "q" && res.toLowerCase() !== "p") {
@@ -282,6 +324,7 @@ __name(apply, "apply");
282
324
  0 && (module.exports = {
283
325
  Config,
284
326
  apply,
327
+ inject,
285
328
  name,
286
329
  usage
287
330
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-smmcat-selfhelp",
3
3
  "description": "用户自助服务系统",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [