koishi-plugin-oni-wiki-qq 0.6.0 → 0.7.1

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
@@ -10,7 +10,6 @@ declare module "koishi" {
10
10
  export interface WikiPages {
11
11
  id: number;
12
12
  title: string;
13
- redirect: string;
14
13
  }
15
14
  export interface Config {
16
15
  bot_username: string;
package/lib/index.js CHANGED
@@ -44,15 +44,16 @@ var inject = ["database"];
44
44
  var Config = import_koishi.Schema.object({
45
45
  bot_username: import_koishi.Schema.string().description("机器人用户名"),
46
46
  bot_password: import_koishi.Schema.string().description("机器人密码"),
47
- bwiki_session: import_koishi.Schema.string().description("bwiki的session,无法连接到gg时使用")
47
+ bwiki_session: import_koishi.Schema.string().description(
48
+ "bwiki的session,无法连接到gg时使用"
49
+ )
48
50
  });
49
51
  function apply(ctx, config) {
50
52
  const logger = ctx.logger(name);
51
53
  let wikibot;
52
54
  ctx.model.extend("wikipages", {
53
55
  id: "integer",
54
- title: "string",
55
- redirect: "string"
56
+ title: "string"
56
57
  });
57
58
  ctx.on("ready", async () => {
58
59
  wikibot = new import_mwn.Mwn({
@@ -67,12 +68,16 @@ function apply(ctx, config) {
67
68
  ctx.command("x <itemName>", "查询缺氧中文wiki,精准匹配+拼音模糊匹配+序号选择").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
68
69
  if (/教程/.test(itemName)) {
69
70
  return `请点击链接前往站点查看:
70
- 原站点: http://oni.wiki/${encodeURI(`教程`)}?variant=zh
71
- 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
71
+ 原站点: http://oni.wiki/${encodeURI(
72
+ `教程`
73
+ )}?variant=zh
74
+ 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(
75
+ `教程`
76
+ )}`;
72
77
  }
73
78
  const queryKey = itemName.trim();
74
79
  const preciseRes = await ctx.database.get("wikipages", {
75
- $or: [{ title: queryKey }, { redirect: queryKey }]
80
+ $or: [{ title: queryKey }]
76
81
  });
77
82
  if (preciseRes.length > 0) {
78
83
  const pageName = preciseRes[0].title;
@@ -84,34 +89,52 @@ function apply(ctx, config) {
84
89
  if (allPages.length === 0) {
85
90
  return `❌ 本地缓存为空,请联系管理员执行【update】指令更新缓存!`;
86
91
  }
87
- const userPinyin = (0, import_pinyin_pro.pinyin)(queryKey, { toneType: "none", type: "string", separator: "" });
88
- const userFirstLetter = (0, import_pinyin_pro.pinyin)(queryKey, { type: "string", separator: "" }).toLowerCase();
92
+ const userPinyin = (0, import_pinyin_pro.pinyin)(queryKey, {
93
+ toneType: "none",
94
+ type: "string",
95
+ separator: ""
96
+ });
97
+ const userFirstLetter = (0, import_pinyin_pro.pinyin)(queryKey, {
98
+ type: "string",
99
+ separator: ""
100
+ }).toLowerCase();
89
101
  const matchResult = [];
90
102
  allPages.forEach((page) => {
91
103
  const targetTitle = page.title || "";
92
104
  if (!targetTitle) return;
93
- const titlePinyin = (0, import_pinyin_pro.pinyin)(targetTitle, { toneType: "none", type: "string", separator: "" });
94
- const titleFirstLetter = (0, import_pinyin_pro.pinyin)(targetTitle, { type: "string", separator: "" }).toLowerCase();
105
+ const titlePinyin = (0, import_pinyin_pro.pinyin)(targetTitle, {
106
+ toneType: "none",
107
+ type: "string",
108
+ separator: ""
109
+ });
110
+ const titleFirstLetter = (0, import_pinyin_pro.pinyin)(targetTitle, {
111
+ type: "string",
112
+ separator: ""
113
+ }).toLowerCase();
95
114
  let score = 0;
96
- if (titlePinyin.includes(userPinyin) || userPinyin.includes(titlePinyin)) score += 5;
115
+ if (titlePinyin.includes(userPinyin) || userPinyin.includes(titlePinyin))
116
+ score += 5;
97
117
  if (targetTitle.includes(queryKey)) score += 4;
98
- if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter)) score += 3;
118
+ if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter))
119
+ score += 3;
99
120
  if (score > 0) matchResult.push({ title: targetTitle, score });
100
121
  });
101
122
  if (matchResult.length === 0) {
102
123
  return `❌ 未找到【${queryKey}】相关内容,请按游戏内标准名称重新查询!`;
103
124
  }
104
125
  const sortedResult = matchResult.sort((a, b) => b.score - a.score);
105
- const uniqueResult = Array.from(new Map(sortedResult.map((item) => [item.title, item])).values()).slice(0, 5);
126
+ const uniqueResult = Array.from(
127
+ new Map(sortedResult.map((item) => [item.title, item])).values()
128
+ ).slice(0, 5);
106
129
  const resultCount = uniqueResult.length;
107
- let replyMsg = `🔍 未找到精准匹配,为你找到【${resultCount}】个相似结果,请输入序号选择(10秒内有效):
130
+ let replyMsg = `🔍 未找到精准匹配,为你找到【 ${resultCount} 】个相似结果,请输入序号选择(10秒内有效):
108
131
  `;
109
132
  uniqueResult.forEach((item, index) => {
110
133
  replyMsg += `${index + 1}. ${item.title}
111
134
  `;
112
135
  });
113
136
  replyMsg += `
114
- ❗️ 提示:超时将静默结束,无任何回应,没有有待选结果请艾特机器人任意内容结束本轮查询或等待超时后重新发起查询`;
137
+ ❗️ 提示:超时将静默结束,无任何回应`;
115
138
  await session.send(replyMsg);
116
139
  const userInput = await session.prompt(1e4);
117
140
  if (!userInput) return;
@@ -125,11 +148,18 @@ function apply(ctx, config) {
125
148
  镜像站: http://klei.vip/oni/usiz6d/${encodeURI(targetPage)}`;
126
149
  });
127
150
  ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
128
- wikibot.request({ action: "query", list: "allpages", format: "json", aplimit: "max" }).then((res) => {
151
+ wikibot.request({
152
+ action: "query",
153
+ list: "allpages",
154
+ format: "json",
155
+ aplimit: "max"
156
+ }).then((res) => {
129
157
  logger.info("查询成功");
130
158
  const pages = res.query.allpages;
131
159
  pages.forEach((page) => {
132
- ctx.database.upsert("wikipages", () => [{ id: page.pageid, title: page.title }]);
160
+ ctx.database.upsert("wikipages", () => [
161
+ { id: page.pageid, title: page.title }
162
+ ]);
133
163
  });
134
164
  session.send(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
135
165
  logger.info(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
@@ -149,10 +179,16 @@ function apply(ctx, config) {
149
179
  const url = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=0&aplimit=5000&format=json`;
150
180
  ctx.http.get(url, { headers }).then((res) => {
151
181
  res["query"]["allpages"].forEach((page) => {
152
- ctx.database.upsert("wikipages", () => [{ id: page.pageid, title: page.title }]);
182
+ ctx.database.upsert("wikipages", () => [
183
+ { id: page.pageid, title: page.title }
184
+ ]);
153
185
  });
154
- session.send(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
155
- logger.info(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
186
+ session.send(
187
+ `检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`
188
+ );
189
+ logger.info(
190
+ `检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`
191
+ );
156
192
  }).catch((err) => {
157
193
  session.send("更新失败,请联系管理员检查日志");
158
194
  logger.error("更新失败", err);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-oni-wiki-qq",
3
3
  "description": "缺氧wiki查询,自用",
4
- "version": "0.6.0",
4
+ "version": "0.7.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [