koishi-plugin-oni-wiki-qq 0.5.1 → 0.6.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 -1
- package/lib/index.js +68 -51
- package/package.json +5 -4
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Context, Schema } from "koishi";
|
|
2
2
|
export declare const name = "oni-wiki-qq";
|
|
3
|
-
export declare const usage = "\n - 0.
|
|
3
|
+
export declare const usage = "\n - 0.6.1 \u2705 \u6A21\u7CCA\u5339\u914D\u8FD4\u56DE\u6700\u591A5\u6761\u7ED3\u679C+\u5E8F\u53F7\u7B49\u5F85\u4EA4\u4E92\uFF0C\u8D85\u65F6\u65E0\u8F93\u5165\u5219\u9759\u9ED8\u7ED3\u675F\n - 0.6.0 \u96C6\u6210pinyin-pro\u62FC\u97F3\u6A21\u7CCA\u5339\u914D\uFF0C\u7CBE\u51C6\u5339\u914D\u4F18\u5148\n - 0.5.0 \u79FB\u9664\u91CD\u5B9A\u5411\u529F\u80FD GG\u7AD9\u70B9\u5DF2\u4FEE\u590D\uFF0C\u4FDD\u7559bwiki\u66F4\u65B0\u529F\u80FD\n - 0.4.9 \u6DFB\u52A0\u91CD\u5B9A\u5411\u529F\u80FD\n - 0.4.8 \u91CD\u542Fbwiki\u66F4\u65B0\n - 0.4.6 \u79FB\u9664\u6CA1\u5FC5\u8981\u7684\u529F\u80FD\n - 0.4.5 \u68C0\u6D4B\u6559\u7A0B\u9875\u9762\n";
|
|
4
4
|
export declare const inject: string[];
|
|
5
5
|
declare module "koishi" {
|
|
6
6
|
interface Tables {
|
package/lib/index.js
CHANGED
|
@@ -29,10 +29,12 @@ __export(src_exports, {
|
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
var import_koishi = require("koishi");
|
|
31
31
|
var import_mwn = require("mwn");
|
|
32
|
+
var import_pinyin_pro = require("pinyin-pro");
|
|
32
33
|
var name = "oni-wiki-qq";
|
|
33
34
|
var usage = `
|
|
34
|
-
- 0.
|
|
35
|
-
- 0.
|
|
35
|
+
- 0.6.1 ✅ 模糊匹配返回最多5条结果+序号等待交互,超时无输入则静默结束
|
|
36
|
+
- 0.6.0 集成pinyin-pro拼音模糊匹配,精准匹配优先
|
|
37
|
+
- 0.5.0 移除重定向功能 GG站点已修复,保留bwiki更新功能
|
|
36
38
|
- 0.4.9 添加重定向功能
|
|
37
39
|
- 0.4.8 重启bwiki更新
|
|
38
40
|
- 0.4.6 移除没必要的功能
|
|
@@ -42,10 +44,10 @@ var inject = ["database"];
|
|
|
42
44
|
var Config = import_koishi.Schema.object({
|
|
43
45
|
bot_username: import_koishi.Schema.string().description("机器人用户名"),
|
|
44
46
|
bot_password: import_koishi.Schema.string().description("机器人密码"),
|
|
45
|
-
bwiki_session: import_koishi.Schema.string().description("bwiki的session
|
|
47
|
+
bwiki_session: import_koishi.Schema.string().description("bwiki的session,无法连接到gg时使用")
|
|
46
48
|
});
|
|
47
49
|
function apply(ctx, config) {
|
|
48
|
-
const logger = ctx.logger;
|
|
50
|
+
const logger = ctx.logger(name);
|
|
49
51
|
let wikibot;
|
|
50
52
|
ctx.model.extend("wikipages", {
|
|
51
53
|
id: "integer",
|
|
@@ -58,70 +60,87 @@ function apply(ctx, config) {
|
|
|
58
60
|
username: config.bot_username,
|
|
59
61
|
password: config.bot_password,
|
|
60
62
|
userAgent: "Charles`Bot/2.1",
|
|
61
|
-
defaultParams: {
|
|
62
|
-
assert: "user"
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
wikibot.login().then(() => {
|
|
66
|
-
logger.info("Wiki机器人登录成功");
|
|
67
|
-
}).catch((err) => {
|
|
68
|
-
logger.error("Wiki机器人登录失败", err);
|
|
63
|
+
defaultParams: { assert: "user" }
|
|
69
64
|
});
|
|
65
|
+
wikibot.login().then(() => logger.info("Wiki机器人登录成功")).catch((err) => logger.error("Wiki机器人登录失败", err));
|
|
70
66
|
});
|
|
71
|
-
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
|
|
67
|
+
ctx.command("x <itemName>", "查询缺氧中文wiki,精准匹配+拼音模糊匹配+序号选择").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
|
|
72
68
|
if (/教程/.test(itemName)) {
|
|
73
69
|
return `请点击链接前往站点查看:
|
|
74
|
-
原站点: http://oni.wiki/${encodeURI(
|
|
75
|
-
`教程`
|
|
76
|
-
)}?variant=zh
|
|
70
|
+
原站点: http://oni.wiki/${encodeURI(`教程`)}?variant=zh
|
|
77
71
|
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
|
|
78
72
|
}
|
|
79
|
-
const
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
title: itemName
|
|
83
|
-
},
|
|
84
|
-
{
|
|
85
|
-
redirect: itemName
|
|
86
|
-
}
|
|
87
|
-
]
|
|
73
|
+
const queryKey = itemName.trim();
|
|
74
|
+
const preciseRes = await ctx.database.get("wikipages", {
|
|
75
|
+
$or: [{ title: queryKey }, { redirect: queryKey }]
|
|
88
76
|
});
|
|
89
|
-
if (
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
return `请点击链接前往站点查看:
|
|
94
|
-
原站点: http://oni.wiki/${encodeURI(
|
|
95
|
-
pageName
|
|
96
|
-
)}?variant=zh
|
|
77
|
+
if (preciseRes.length > 0) {
|
|
78
|
+
const pageName = preciseRes[0].title;
|
|
79
|
+
return `✅ 精准匹配成功
|
|
80
|
+
原站点: http://oni.wiki/${encodeURI(pageName)}?variant=zh
|
|
97
81
|
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(pageName)}`;
|
|
82
|
+
}
|
|
83
|
+
const allPages = await ctx.database.get("wikipages", {});
|
|
84
|
+
if (allPages.length === 0) {
|
|
85
|
+
return `❌ 本地缓存为空,请联系管理员执行【update】指令更新缓存!`;
|
|
86
|
+
}
|
|
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();
|
|
89
|
+
const matchResult = [];
|
|
90
|
+
allPages.forEach((page) => {
|
|
91
|
+
const targetTitle = page.title || "";
|
|
92
|
+
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();
|
|
95
|
+
let score = 0;
|
|
96
|
+
if (titlePinyin.includes(userPinyin) || userPinyin.includes(titlePinyin)) score += 5;
|
|
97
|
+
if (targetTitle.includes(queryKey)) score += 4;
|
|
98
|
+
if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter)) score += 3;
|
|
99
|
+
if (score > 0) matchResult.push({ title: targetTitle, score });
|
|
100
|
+
});
|
|
101
|
+
if (matchResult.length === 0) {
|
|
102
|
+
return `❌ 未找到【${queryKey}】相关内容,请按游戏内标准名称重新查询!`;
|
|
103
|
+
}
|
|
104
|
+
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);
|
|
106
|
+
const resultCount = uniqueResult.length;
|
|
107
|
+
let replyMsg = `🔍 未找到精准匹配,为你找到【${resultCount}】个相似结果,请输入序号选择(10秒内有效):
|
|
108
|
+
`;
|
|
109
|
+
uniqueResult.forEach((item, index) => {
|
|
110
|
+
replyMsg += `${index + 1}. ${item.title}
|
|
111
|
+
`;
|
|
112
|
+
});
|
|
113
|
+
replyMsg += `
|
|
114
|
+
❗️ 提示:超时将静默结束,无任何回应,没有有待选结果请艾特机器人任意内容结束本轮查询或等待超时后重新发起查询`;
|
|
115
|
+
await session.send(replyMsg);
|
|
116
|
+
const userInput = await session.prompt(1e4);
|
|
117
|
+
if (!userInput) return;
|
|
118
|
+
const selectNum = parseInt(userInput.trim());
|
|
119
|
+
if (isNaN(selectNum) || selectNum < 1 || selectNum > resultCount) {
|
|
120
|
+
return `❌ 输入无效!请输入 1-${resultCount} 之间的数字序号`;
|
|
121
|
+
}
|
|
122
|
+
const targetPage = uniqueResult[selectNum - 1].title;
|
|
123
|
+
return `✅ 选择成功
|
|
124
|
+
原站点: http://oni.wiki/${encodeURI(targetPage)}?variant=zh
|
|
125
|
+
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(targetPage)}`;
|
|
98
126
|
});
|
|
99
127
|
ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
|
|
100
|
-
wikibot.request({
|
|
101
|
-
action: "query",
|
|
102
|
-
list: "allpages",
|
|
103
|
-
format: "json",
|
|
104
|
-
aplimit: "max"
|
|
105
|
-
}).then((res) => {
|
|
128
|
+
wikibot.request({ action: "query", list: "allpages", format: "json", aplimit: "max" }).then((res) => {
|
|
106
129
|
logger.info("查询成功");
|
|
107
130
|
const pages = res.query.allpages;
|
|
108
131
|
pages.forEach((page) => {
|
|
109
|
-
ctx.database.upsert("wikipages", () => [
|
|
110
|
-
{ id: page.pageid, title: page.title }
|
|
111
|
-
]);
|
|
132
|
+
ctx.database.upsert("wikipages", () => [{ id: page.pageid, title: page.title }]);
|
|
112
133
|
});
|
|
113
134
|
session.send(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
|
|
114
135
|
logger.info(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
|
|
115
|
-
}).catch((err) =>
|
|
116
|
-
logger.error("查询失败", err);
|
|
117
|
-
});
|
|
136
|
+
}).catch((err) => logger.error("查询失败", err));
|
|
118
137
|
});
|
|
119
|
-
ctx.command("update.delete", "
|
|
138
|
+
ctx.command("update.delete", "删除本地页面缓存", { authority: 4 }).action(async ({ session }) => {
|
|
120
139
|
const count = await ctx.database.remove("wikipages", {});
|
|
121
140
|
session.send(`已删除 ${count.removed} 条本地缓存`);
|
|
122
141
|
logger.info(`已删除 ${count.removed} 条本地缓存`);
|
|
123
142
|
});
|
|
124
|
-
ctx.command("update.bwiki", "使用bwiki的session
|
|
143
|
+
ctx.command("update.bwiki", "使用bwiki的session更新缓存", { authority: 2 }).action(async ({ session }) => {
|
|
125
144
|
const headers = {
|
|
126
145
|
"Content-Type": "application/json",
|
|
127
146
|
"user-agent": "Charles'queryBot",
|
|
@@ -130,9 +149,7 @@ function apply(ctx, config) {
|
|
|
130
149
|
const url = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=0&aplimit=5000&format=json`;
|
|
131
150
|
ctx.http.get(url, { headers }).then((res) => {
|
|
132
151
|
res["query"]["allpages"].forEach((page) => {
|
|
133
|
-
ctx.database.upsert("wikipages", () => [
|
|
134
|
-
{ id: page.pageid, title: page.title }
|
|
135
|
-
]);
|
|
152
|
+
ctx.database.upsert("wikipages", () => [{ id: page.pageid, title: page.title }]);
|
|
136
153
|
});
|
|
137
154
|
session.send(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
|
|
138
155
|
logger.info(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
|
|
@@ -141,7 +158,7 @@ function apply(ctx, config) {
|
|
|
141
158
|
logger.error("更新失败", err);
|
|
142
159
|
});
|
|
143
160
|
});
|
|
144
|
-
ctx.command("update.status", "
|
|
161
|
+
ctx.command("update.status", "查询本地缓存数量", { authority: 1 }).action(async ({ session }) => {
|
|
145
162
|
const count = await ctx.database.get("wikipages", {});
|
|
146
163
|
session.send(`数据库中缓存了 ${count.length} 条页面`);
|
|
147
164
|
logger.info(`数据库中缓存了 ${count.length} 条页面`);
|
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.
|
|
4
|
+
"version": "0.6.0",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -15,9 +15,10 @@
|
|
|
15
15
|
"plugin"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"koishi": "^4.18.
|
|
18
|
+
"koishi": "^4.18.10"
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"mwn": "^3.0.1"
|
|
21
|
+
"mwn": "^3.0.1",
|
|
22
|
+
"pinyin-pro": "^3.27.0"
|
|
22
23
|
}
|
|
23
|
-
}
|
|
24
|
+
}
|