koishi-plugin-oni-wiki-qq 0.7.1 → 0.7.4
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 +4 -1
- package/lib/index.js +56 -20
- 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.4 \u6DFB\u52A0\u91CD\u5B9A\u5411\u6307\u4EE4\n - 0.7.3 \u4F18\u5316\u77ED\u94FE\u63A5\u53D1\u9001\u6D88\u606F\u683C\u5F0F\n - 0.7.2 \u5C1D\u8BD5\u4FEE\u590D\u77ED\u94FE\u63A5\u8DF3\u8F6C\u95EE\u9898\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 {
|
|
@@ -15,6 +15,9 @@ export interface Config {
|
|
|
15
15
|
bot_username: string;
|
|
16
16
|
bot_password: string;
|
|
17
17
|
bwiki_session: string;
|
|
18
|
+
domain: string;
|
|
19
|
+
main_site: string;
|
|
20
|
+
mirror_site: string;
|
|
18
21
|
}
|
|
19
22
|
export declare const Config: Schema<Config>;
|
|
20
23
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -32,7 +32,11 @@ 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.4 添加重定向指令
|
|
36
|
+
- 0.7.3 优化短链接发送消息格式
|
|
37
|
+
- 0.7.2 尝试修复短链接跳转问题
|
|
38
|
+
- 0.7.0 实现短链路由转发,链接改为klei.vip/ggwiki或者bwiki+页面ID
|
|
39
|
+
- 0.6.1 模糊匹配返回最多5条结果+序号等待交互,超时无输入则静默结束
|
|
36
40
|
- 0.6.0 集成pinyin-pro拼音模糊匹配,精准匹配优先
|
|
37
41
|
- 0.5.0 移除重定向功能 GG站点已修复,保留bwiki更新功能
|
|
38
42
|
- 0.4.9 添加重定向功能
|
|
@@ -40,13 +44,16 @@ var usage = `
|
|
|
40
44
|
- 0.4.6 移除没必要的功能
|
|
41
45
|
- 0.4.5 检测教程页面
|
|
42
46
|
`;
|
|
43
|
-
var inject = ["database"];
|
|
47
|
+
var inject = ["database", "server"];
|
|
44
48
|
var Config = import_koishi.Schema.object({
|
|
45
49
|
bot_username: import_koishi.Schema.string().description("机器人用户名"),
|
|
46
50
|
bot_password: import_koishi.Schema.string().description("机器人密码"),
|
|
47
51
|
bwiki_session: import_koishi.Schema.string().description(
|
|
48
52
|
"bwiki的session,无法连接到gg时使用"
|
|
49
|
-
)
|
|
53
|
+
),
|
|
54
|
+
domain: import_koishi.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip"),
|
|
55
|
+
main_site: import_koishi.Schema.string().description("主站域名(必填,如:oxygennotincluded.wiki.gg)").default("oxygennotincluded.wiki.gg/zh"),
|
|
56
|
+
mirror_site: import_koishi.Schema.string().description("镜像站域名(必填,如:wiki.biligame.com)").default("wiki.biligame.com/oni")
|
|
50
57
|
});
|
|
51
58
|
function apply(ctx, config) {
|
|
52
59
|
const logger = ctx.logger(name);
|
|
@@ -55,6 +62,28 @@ function apply(ctx, config) {
|
|
|
55
62
|
id: "integer",
|
|
56
63
|
title: "string"
|
|
57
64
|
});
|
|
65
|
+
ctx.server.get("/ggwiki/:id", async (router) => {
|
|
66
|
+
const pageId = Number(router.params.id);
|
|
67
|
+
if (isNaN(pageId)) return router.body = "❌ 无效的页面ID,必须为数字!";
|
|
68
|
+
const [page] = await ctx.database.get("wikipages", { id: pageId });
|
|
69
|
+
if (!page)
|
|
70
|
+
return router.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
|
|
71
|
+
const targetUrl = `https://${config.main_site}/${encodeURIComponent(
|
|
72
|
+
page.title
|
|
73
|
+
)}?variant=zh`;
|
|
74
|
+
router.redirect(targetUrl);
|
|
75
|
+
});
|
|
76
|
+
ctx.server.get("/bwiki/:id", async (router) => {
|
|
77
|
+
const pageId = Number(router.params.id);
|
|
78
|
+
if (isNaN(pageId)) return router.body = "❌ 无效的页面ID,必须为数字!";
|
|
79
|
+
const [page] = await ctx.database.get("wikipages", { id: pageId });
|
|
80
|
+
if (!page)
|
|
81
|
+
return router.body = `❌ 未找到ID为【${pageId}】的页面,请联系管理员更新缓存!`;
|
|
82
|
+
const targetUrl = `https://${config.mirror_site}/${encodeURIComponent(
|
|
83
|
+
page.title
|
|
84
|
+
)}`;
|
|
85
|
+
router.redirect(targetUrl);
|
|
86
|
+
});
|
|
58
87
|
ctx.on("ready", async () => {
|
|
59
88
|
wikibot = new import_mwn.Mwn({
|
|
60
89
|
apiUrl: "https://oxygennotincluded.wiki.gg/zh/api.php",
|
|
@@ -66,24 +95,15 @@ function apply(ctx, config) {
|
|
|
66
95
|
wikibot.login().then(() => logger.info("Wiki机器人登录成功")).catch((err) => logger.error("Wiki机器人登录失败", err));
|
|
67
96
|
});
|
|
68
97
|
ctx.command("x <itemName>", "查询缺氧中文wiki,精准匹配+拼音模糊匹配+序号选择").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
|
|
69
|
-
if (/教程/.test(itemName)) {
|
|
70
|
-
return `请点击链接前往站点查看:
|
|
71
|
-
原站点: http://oni.wiki/${encodeURI(
|
|
72
|
-
`教程`
|
|
73
|
-
)}?variant=zh
|
|
74
|
-
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(
|
|
75
|
-
`教程`
|
|
76
|
-
)}`;
|
|
77
|
-
}
|
|
78
98
|
const queryKey = itemName.trim();
|
|
79
99
|
const preciseRes = await ctx.database.get("wikipages", {
|
|
80
|
-
|
|
100
|
+
title: queryKey
|
|
81
101
|
});
|
|
82
102
|
if (preciseRes.length > 0) {
|
|
83
|
-
const
|
|
103
|
+
const { id: id2 } = preciseRes[0];
|
|
84
104
|
return `✅ 精准匹配成功
|
|
85
|
-
原站点:
|
|
86
|
-
镜像站:
|
|
105
|
+
原站点: http://${config.domain}/ggwiki/${id2}
|
|
106
|
+
镜像站: http://${config.domain}/bwiki/${id2}`;
|
|
87
107
|
}
|
|
88
108
|
const allPages = await ctx.database.get("wikipages", {});
|
|
89
109
|
if (allPages.length === 0) {
|
|
@@ -117,7 +137,8 @@ function apply(ctx, config) {
|
|
|
117
137
|
if (targetTitle.includes(queryKey)) score += 4;
|
|
118
138
|
if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter))
|
|
119
139
|
score += 3;
|
|
120
|
-
if (score > 0)
|
|
140
|
+
if (score > 0)
|
|
141
|
+
matchResult.push({ id: page.id, title: targetTitle, score });
|
|
121
142
|
});
|
|
122
143
|
if (matchResult.length === 0) {
|
|
123
144
|
return `❌ 未找到【${queryKey}】相关内容,请按游戏内标准名称重新查询!`;
|
|
@@ -142,10 +163,10 @@ function apply(ctx, config) {
|
|
|
142
163
|
if (isNaN(selectNum) || selectNum < 1 || selectNum > resultCount) {
|
|
143
164
|
return `❌ 输入无效!请输入 1-${resultCount} 之间的数字序号`;
|
|
144
165
|
}
|
|
145
|
-
const
|
|
166
|
+
const { id } = uniqueResult[selectNum - 1];
|
|
146
167
|
return `✅ 选择成功
|
|
147
|
-
原站点:
|
|
148
|
-
镜像站:
|
|
168
|
+
原站点: http://${config.domain}/ggwiki/${id}
|
|
169
|
+
镜像站: http://${config.domain}/bwiki/${id}`;
|
|
149
170
|
});
|
|
150
171
|
ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
|
|
151
172
|
wikibot.request({
|
|
@@ -199,6 +220,21 @@ function apply(ctx, config) {
|
|
|
199
220
|
session.send(`数据库中缓存了 ${count.length} 条页面`);
|
|
200
221
|
logger.info(`数据库中缓存了 ${count.length} 条页面`);
|
|
201
222
|
});
|
|
223
|
+
ctx.command("redirect <pageName> <targetPageName>", "添加原站点重定向", {
|
|
224
|
+
authority: 2
|
|
225
|
+
}).alias("重定向").action(async ({ session }, pageName, targetPageName) => {
|
|
226
|
+
await wikibot.create(
|
|
227
|
+
pageName,
|
|
228
|
+
`#REDIRECT [[${targetPageName}]]`,
|
|
229
|
+
"来自qq机器人的添加重定向页面请求"
|
|
230
|
+
).then(() => {
|
|
231
|
+
logger.info(`已为 ${pageName} 添加重定向至 ${targetPageName}`);
|
|
232
|
+
session.send(`已尝试添加重定向 ${pageName} -> ${targetPageName}`);
|
|
233
|
+
session.execute(`update`);
|
|
234
|
+
}).catch((err) => {
|
|
235
|
+
logger.error(`添加重定向 ${pageName} -> ${targetPageName} 失败`, err);
|
|
236
|
+
});
|
|
237
|
+
});
|
|
202
238
|
}
|
|
203
239
|
__name(apply, "apply");
|
|
204
240
|
// Annotate the CommonJS export names for ESM import in node:
|