koishi-plugin-oni-wiki-qq 0.6.0 → 0.7.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 +2 -2
- package/lib/index.js +83 -31
- package/package.json +1 -1
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.6.1 \
|
|
3
|
+
export declare const usage = "\n - 0.7.0 \u5B9E\u73B0\u77ED\u94FE\u8DEF\u7531\u8F6C\u53D1\uFF0C\u94FE\u63A5\u6539\u4E3Aklei.vip/ggwiki\u6216\u8005bwiki+\u9875\u9762ID\n - 0.6.1 \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 {
|
|
@@ -10,12 +10,12 @@ 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;
|
|
17
16
|
bot_password: string;
|
|
18
17
|
bwiki_session: string;
|
|
18
|
+
domain: string;
|
|
19
19
|
}
|
|
20
20
|
export declare const Config: Schema<Config>;
|
|
21
21
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,8 @@ var import_mwn = require("mwn");
|
|
|
32
32
|
var import_pinyin_pro = require("pinyin-pro");
|
|
33
33
|
var name = "oni-wiki-qq";
|
|
34
34
|
var usage = `
|
|
35
|
-
- 0.
|
|
35
|
+
- 0.7.0 实现短链路由转发,链接改为klei.vip/ggwiki或者bwiki+页面ID
|
|
36
|
+
- 0.6.1 模糊匹配返回最多5条结果+序号等待交互,超时无输入则静默结束
|
|
36
37
|
- 0.6.0 集成pinyin-pro拼音模糊匹配,精准匹配优先
|
|
37
38
|
- 0.5.0 移除重定向功能 GG站点已修复,保留bwiki更新功能
|
|
38
39
|
- 0.4.9 添加重定向功能
|
|
@@ -40,19 +41,43 @@ var usage = `
|
|
|
40
41
|
- 0.4.6 移除没必要的功能
|
|
41
42
|
- 0.4.5 检测教程页面
|
|
42
43
|
`;
|
|
43
|
-
var inject = ["database"];
|
|
44
|
+
var inject = ["database", "server"];
|
|
44
45
|
var Config = import_koishi.Schema.object({
|
|
45
46
|
bot_username: import_koishi.Schema.string().description("机器人用户名"),
|
|
46
47
|
bot_password: import_koishi.Schema.string().description("机器人密码"),
|
|
47
|
-
bwiki_session: import_koishi.Schema.string().description(
|
|
48
|
+
bwiki_session: import_koishi.Schema.string().description(
|
|
49
|
+
"bwiki的session,无法连接到gg时使用"
|
|
50
|
+
),
|
|
51
|
+
domain: import_koishi.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip")
|
|
48
52
|
});
|
|
49
53
|
function apply(ctx, config) {
|
|
50
54
|
const logger = ctx.logger(name);
|
|
51
55
|
let wikibot;
|
|
52
56
|
ctx.model.extend("wikipages", {
|
|
53
57
|
id: "integer",
|
|
54
|
-
title: "string"
|
|
55
|
-
|
|
58
|
+
title: "string"
|
|
59
|
+
});
|
|
60
|
+
ctx.server.get("/ggwiki/:id", async (ctx2) => {
|
|
61
|
+
const pageId = Number(ctx2.params.id);
|
|
62
|
+
if (isNaN(pageId)) return ctx2.body = "❌ 无效的页面ID,必须为数字!";
|
|
63
|
+
const [page] = await ctx2.database.get("wikipages", { id: pageId });
|
|
64
|
+
if (!page)
|
|
65
|
+
return ctx2.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
|
|
66
|
+
const targetUrl = `https://oni.wiki/${encodeURIComponent(
|
|
67
|
+
page.title
|
|
68
|
+
)}?variant=zh`;
|
|
69
|
+
ctx2.redirect(targetUrl);
|
|
70
|
+
});
|
|
71
|
+
ctx.server.get("/bwiki/:id", async (ctx2) => {
|
|
72
|
+
const pageId = Number(ctx2.params.id);
|
|
73
|
+
if (isNaN(pageId)) return ctx2.body = "❌ 无效的页面ID,必须为数字!";
|
|
74
|
+
const [page] = await ctx2.database.get("wikipages", { id: pageId });
|
|
75
|
+
if (!page)
|
|
76
|
+
return ctx2.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
|
|
77
|
+
const targetUrl = `https://wiki.biligame.com/oni/${encodeURIComponent(
|
|
78
|
+
page.title
|
|
79
|
+
)}`;
|
|
80
|
+
ctx2.redirect(targetUrl);
|
|
56
81
|
});
|
|
57
82
|
ctx.on("ready", async () => {
|
|
58
83
|
wikibot = new import_mwn.Mwn({
|
|
@@ -65,44 +90,58 @@ function apply(ctx, config) {
|
|
|
65
90
|
wikibot.login().then(() => logger.info("Wiki机器人登录成功")).catch((err) => logger.error("Wiki机器人登录失败", err));
|
|
66
91
|
});
|
|
67
92
|
ctx.command("x <itemName>", "查询缺氧中文wiki,精准匹配+拼音模糊匹配+序号选择").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
|
|
68
|
-
if (/教程/.test(itemName)) {
|
|
69
|
-
return `请点击链接前往站点查看:
|
|
70
|
-
原站点: http://oni.wiki/${encodeURI(`教程`)}?variant=zh
|
|
71
|
-
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
|
|
72
|
-
}
|
|
73
93
|
const queryKey = itemName.trim();
|
|
74
94
|
const preciseRes = await ctx.database.get("wikipages", {
|
|
75
|
-
|
|
95
|
+
title: queryKey
|
|
76
96
|
});
|
|
77
97
|
if (preciseRes.length > 0) {
|
|
78
|
-
const
|
|
98
|
+
const { id: id2 } = preciseRes[0];
|
|
79
99
|
return `✅ 精准匹配成功
|
|
80
|
-
原站点: http
|
|
81
|
-
镜像站: http
|
|
100
|
+
原站点: http://${config.domain}/ggwiki/${id2}
|
|
101
|
+
镜像站: http://${config.domain}/bwiki/${id2}`;
|
|
82
102
|
}
|
|
83
103
|
const allPages = await ctx.database.get("wikipages", {});
|
|
84
104
|
if (allPages.length === 0) {
|
|
85
105
|
return `❌ 本地缓存为空,请联系管理员执行【update】指令更新缓存!`;
|
|
86
106
|
}
|
|
87
|
-
const userPinyin = (0, import_pinyin_pro.pinyin)(queryKey, {
|
|
88
|
-
|
|
107
|
+
const userPinyin = (0, import_pinyin_pro.pinyin)(queryKey, {
|
|
108
|
+
toneType: "none",
|
|
109
|
+
type: "string",
|
|
110
|
+
separator: ""
|
|
111
|
+
});
|
|
112
|
+
const userFirstLetter = (0, import_pinyin_pro.pinyin)(queryKey, {
|
|
113
|
+
type: "string",
|
|
114
|
+
separator: ""
|
|
115
|
+
}).toLowerCase();
|
|
89
116
|
const matchResult = [];
|
|
90
117
|
allPages.forEach((page) => {
|
|
91
118
|
const targetTitle = page.title || "";
|
|
92
119
|
if (!targetTitle) return;
|
|
93
|
-
const titlePinyin = (0, import_pinyin_pro.pinyin)(targetTitle, {
|
|
94
|
-
|
|
120
|
+
const titlePinyin = (0, import_pinyin_pro.pinyin)(targetTitle, {
|
|
121
|
+
toneType: "none",
|
|
122
|
+
type: "string",
|
|
123
|
+
separator: ""
|
|
124
|
+
});
|
|
125
|
+
const titleFirstLetter = (0, import_pinyin_pro.pinyin)(targetTitle, {
|
|
126
|
+
type: "string",
|
|
127
|
+
separator: ""
|
|
128
|
+
}).toLowerCase();
|
|
95
129
|
let score = 0;
|
|
96
|
-
if (titlePinyin.includes(userPinyin) || userPinyin.includes(titlePinyin))
|
|
130
|
+
if (titlePinyin.includes(userPinyin) || userPinyin.includes(titlePinyin))
|
|
131
|
+
score += 5;
|
|
97
132
|
if (targetTitle.includes(queryKey)) score += 4;
|
|
98
|
-
if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter))
|
|
99
|
-
|
|
133
|
+
if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter))
|
|
134
|
+
score += 3;
|
|
135
|
+
if (score > 0)
|
|
136
|
+
matchResult.push({ id: page.id, title: targetTitle, score });
|
|
100
137
|
});
|
|
101
138
|
if (matchResult.length === 0) {
|
|
102
139
|
return `❌ 未找到【${queryKey}】相关内容,请按游戏内标准名称重新查询!`;
|
|
103
140
|
}
|
|
104
141
|
const sortedResult = matchResult.sort((a, b) => b.score - a.score);
|
|
105
|
-
const uniqueResult = Array.from(
|
|
142
|
+
const uniqueResult = Array.from(
|
|
143
|
+
new Map(sortedResult.map((item) => [item.title, item])).values()
|
|
144
|
+
).slice(0, 5);
|
|
106
145
|
const resultCount = uniqueResult.length;
|
|
107
146
|
let replyMsg = `🔍 未找到精准匹配,为你找到【${resultCount}】个相似结果,请输入序号选择(10秒内有效):
|
|
108
147
|
`;
|
|
@@ -111,7 +150,7 @@ function apply(ctx, config) {
|
|
|
111
150
|
`;
|
|
112
151
|
});
|
|
113
152
|
replyMsg += `
|
|
114
|
-
❗️
|
|
153
|
+
❗️ 提示:超时将静默结束,无任何回应,没有待选结果请艾特机器人任意内容结束本轮查询`;
|
|
115
154
|
await session.send(replyMsg);
|
|
116
155
|
const userInput = await session.prompt(1e4);
|
|
117
156
|
if (!userInput) return;
|
|
@@ -119,17 +158,24 @@ function apply(ctx, config) {
|
|
|
119
158
|
if (isNaN(selectNum) || selectNum < 1 || selectNum > resultCount) {
|
|
120
159
|
return `❌ 输入无效!请输入 1-${resultCount} 之间的数字序号`;
|
|
121
160
|
}
|
|
122
|
-
const
|
|
161
|
+
const { id } = uniqueResult[selectNum - 1];
|
|
123
162
|
return `✅ 选择成功
|
|
124
|
-
原站点: http
|
|
125
|
-
镜像站: http
|
|
163
|
+
原站点: http://${config.domain}/ggwiki/${id}
|
|
164
|
+
镜像站: http://${config.domain}/bwiki/${id}`;
|
|
126
165
|
});
|
|
127
166
|
ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
|
|
128
|
-
wikibot.request({
|
|
167
|
+
wikibot.request({
|
|
168
|
+
action: "query",
|
|
169
|
+
list: "allpages",
|
|
170
|
+
format: "json",
|
|
171
|
+
aplimit: "max"
|
|
172
|
+
}).then((res) => {
|
|
129
173
|
logger.info("查询成功");
|
|
130
174
|
const pages = res.query.allpages;
|
|
131
175
|
pages.forEach((page) => {
|
|
132
|
-
ctx.database.upsert("wikipages", () => [
|
|
176
|
+
ctx.database.upsert("wikipages", () => [
|
|
177
|
+
{ id: page.pageid, title: page.title }
|
|
178
|
+
]);
|
|
133
179
|
});
|
|
134
180
|
session.send(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
|
|
135
181
|
logger.info(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
|
|
@@ -149,10 +195,16 @@ function apply(ctx, config) {
|
|
|
149
195
|
const url = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=0&aplimit=5000&format=json`;
|
|
150
196
|
ctx.http.get(url, { headers }).then((res) => {
|
|
151
197
|
res["query"]["allpages"].forEach((page) => {
|
|
152
|
-
ctx.database.upsert("wikipages", () => [
|
|
198
|
+
ctx.database.upsert("wikipages", () => [
|
|
199
|
+
{ id: page.pageid, title: page.title }
|
|
200
|
+
]);
|
|
153
201
|
});
|
|
154
|
-
session.send(
|
|
155
|
-
|
|
202
|
+
session.send(
|
|
203
|
+
`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`
|
|
204
|
+
);
|
|
205
|
+
logger.info(
|
|
206
|
+
`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`
|
|
207
|
+
);
|
|
156
208
|
}).catch((err) => {
|
|
157
209
|
session.send("更新失败,请联系管理员检查日志");
|
|
158
210
|
logger.error("更新失败", err);
|