koishi-plugin-oni-wiki-qq 0.7.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 +1 -2
- package/lib/index.js +22 -38
- 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.
|
|
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 {
|
|
@@ -15,7 +15,6 @@ export interface Config {
|
|
|
15
15
|
bot_username: string;
|
|
16
16
|
bot_password: string;
|
|
17
17
|
bwiki_session: string;
|
|
18
|
-
domain: string;
|
|
19
18
|
}
|
|
20
19
|
export declare const Config: Schema<Config>;
|
|
21
20
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -32,8 +32,7 @@ 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.
|
|
36
|
-
- 0.6.1 模糊匹配返回最多5条结果+序号等待交互,超时无输入则静默结束
|
|
35
|
+
- 0.6.1 ✅ 模糊匹配返回最多5条结果+序号等待交互,超时无输入则静默结束
|
|
37
36
|
- 0.6.0 集成pinyin-pro拼音模糊匹配,精准匹配优先
|
|
38
37
|
- 0.5.0 移除重定向功能 GG站点已修复,保留bwiki更新功能
|
|
39
38
|
- 0.4.9 添加重定向功能
|
|
@@ -41,14 +40,13 @@ var usage = `
|
|
|
41
40
|
- 0.4.6 移除没必要的功能
|
|
42
41
|
- 0.4.5 检测教程页面
|
|
43
42
|
`;
|
|
44
|
-
var inject = ["database"
|
|
43
|
+
var inject = ["database"];
|
|
45
44
|
var Config = import_koishi.Schema.object({
|
|
46
45
|
bot_username: import_koishi.Schema.string().description("机器人用户名"),
|
|
47
46
|
bot_password: import_koishi.Schema.string().description("机器人密码"),
|
|
48
47
|
bwiki_session: import_koishi.Schema.string().description(
|
|
49
48
|
"bwiki的session,无法连接到gg时使用"
|
|
50
|
-
)
|
|
51
|
-
domain: import_koishi.Schema.string().description("你的短链域名(必填,如:klei.vip)").default("klei.vip")
|
|
49
|
+
)
|
|
52
50
|
});
|
|
53
51
|
function apply(ctx, config) {
|
|
54
52
|
const logger = ctx.logger(name);
|
|
@@ -57,28 +55,6 @@ function apply(ctx, config) {
|
|
|
57
55
|
id: "integer",
|
|
58
56
|
title: "string"
|
|
59
57
|
});
|
|
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);
|
|
81
|
-
});
|
|
82
58
|
ctx.on("ready", async () => {
|
|
83
59
|
wikibot = new import_mwn.Mwn({
|
|
84
60
|
apiUrl: "https://oxygennotincluded.wiki.gg/zh/api.php",
|
|
@@ -90,15 +66,24 @@ function apply(ctx, config) {
|
|
|
90
66
|
wikibot.login().then(() => logger.info("Wiki机器人登录成功")).catch((err) => logger.error("Wiki机器人登录失败", err));
|
|
91
67
|
});
|
|
92
68
|
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
|
+
}
|
|
93
78
|
const queryKey = itemName.trim();
|
|
94
79
|
const preciseRes = await ctx.database.get("wikipages", {
|
|
95
|
-
title: queryKey
|
|
80
|
+
$or: [{ title: queryKey }]
|
|
96
81
|
});
|
|
97
82
|
if (preciseRes.length > 0) {
|
|
98
|
-
const
|
|
83
|
+
const pageName = preciseRes[0].title;
|
|
99
84
|
return `✅ 精准匹配成功
|
|
100
|
-
原站点: http
|
|
101
|
-
镜像站: http
|
|
85
|
+
原站点: http://oni.wiki/${encodeURI(pageName)}?variant=zh
|
|
86
|
+
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(pageName)}`;
|
|
102
87
|
}
|
|
103
88
|
const allPages = await ctx.database.get("wikipages", {});
|
|
104
89
|
if (allPages.length === 0) {
|
|
@@ -132,8 +117,7 @@ function apply(ctx, config) {
|
|
|
132
117
|
if (targetTitle.includes(queryKey)) score += 4;
|
|
133
118
|
if (titleFirstLetter.includes(userFirstLetter) || userFirstLetter.includes(titleFirstLetter))
|
|
134
119
|
score += 3;
|
|
135
|
-
if (score > 0)
|
|
136
|
-
matchResult.push({ id: page.id, title: targetTitle, score });
|
|
120
|
+
if (score > 0) matchResult.push({ title: targetTitle, score });
|
|
137
121
|
});
|
|
138
122
|
if (matchResult.length === 0) {
|
|
139
123
|
return `❌ 未找到【${queryKey}】相关内容,请按游戏内标准名称重新查询!`;
|
|
@@ -143,14 +127,14 @@ function apply(ctx, config) {
|
|
|
143
127
|
new Map(sortedResult.map((item) => [item.title, item])).values()
|
|
144
128
|
).slice(0, 5);
|
|
145
129
|
const resultCount = uniqueResult.length;
|
|
146
|
-
let replyMsg = `🔍
|
|
130
|
+
let replyMsg = `🔍 未找到精准匹配,为你找到【 ${resultCount} 】个相似结果,请输入序号选择(10秒内有效):
|
|
147
131
|
`;
|
|
148
132
|
uniqueResult.forEach((item, index) => {
|
|
149
133
|
replyMsg += `${index + 1}. ${item.title}
|
|
150
134
|
`;
|
|
151
135
|
});
|
|
152
136
|
replyMsg += `
|
|
153
|
-
❗️
|
|
137
|
+
❗️ 提示:超时将静默结束,无任何回应`;
|
|
154
138
|
await session.send(replyMsg);
|
|
155
139
|
const userInput = await session.prompt(1e4);
|
|
156
140
|
if (!userInput) return;
|
|
@@ -158,10 +142,10 @@ function apply(ctx, config) {
|
|
|
158
142
|
if (isNaN(selectNum) || selectNum < 1 || selectNum > resultCount) {
|
|
159
143
|
return `❌ 输入无效!请输入 1-${resultCount} 之间的数字序号`;
|
|
160
144
|
}
|
|
161
|
-
const
|
|
145
|
+
const targetPage = uniqueResult[selectNum - 1].title;
|
|
162
146
|
return `✅ 选择成功
|
|
163
|
-
原站点: http
|
|
164
|
-
镜像站: http
|
|
147
|
+
原站点: http://oni.wiki/${encodeURI(targetPage)}?variant=zh
|
|
148
|
+
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(targetPage)}`;
|
|
165
149
|
});
|
|
166
150
|
ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
|
|
167
151
|
wikibot.request({
|