koishi-plugin-oni-wiki-qq 0.4.5 → 0.4.7
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 +3 -8
- package/lib/index.js +41 -51
- package/package.json +6 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { Context, Schema } from "koishi";
|
|
2
2
|
export declare const name = "oni-wiki-qq";
|
|
3
|
-
export declare const usage = "\n - 0.4.
|
|
3
|
+
export declare const usage = "\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 {
|
|
7
7
|
wikipages: WikiPages;
|
|
8
|
-
searchpages: searchPages;
|
|
9
8
|
}
|
|
10
9
|
}
|
|
11
10
|
export interface WikiPages {
|
|
12
11
|
id: number;
|
|
13
12
|
title: string;
|
|
14
13
|
}
|
|
15
|
-
export interface searchPages {
|
|
16
|
-
id: number;
|
|
17
|
-
title: string;
|
|
18
|
-
time: string;
|
|
19
|
-
}
|
|
20
14
|
export interface Config {
|
|
21
|
-
|
|
15
|
+
bot_username: string;
|
|
16
|
+
bot_password: string;
|
|
22
17
|
}
|
|
23
18
|
export declare const Config: Schema<Config>;
|
|
24
19
|
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
CHANGED
|
@@ -28,55 +28,35 @@ __export(src_exports, {
|
|
|
28
28
|
});
|
|
29
29
|
module.exports = __toCommonJS(src_exports);
|
|
30
30
|
var import_koishi = require("koishi");
|
|
31
|
+
var import_mwn = require("mwn");
|
|
31
32
|
var name = "oni-wiki-qq";
|
|
32
33
|
var usage = `
|
|
34
|
+
- 0.4.6 移除没必要的功能
|
|
33
35
|
- 0.4.5 检测教程页面
|
|
34
|
-
- 0.4.4 加入用户页面
|
|
35
|
-
- 0.4.3 收集搜索的词汇频率
|
|
36
|
-
- 0.4.2 修改/ 的使用方式,改为 >
|
|
37
|
-
- 0.4.1 增加/的处理
|
|
38
|
-
- 0.4.0 移除MWN.将查询处理改至查询数据库
|
|
39
|
-
- 0.3.0 移除耗内存的截图部分,使用镜像站点网页
|
|
40
|
-
- 0.2.0 尝试添加 MWN 库
|
|
41
36
|
`;
|
|
42
37
|
var inject = ["database"];
|
|
43
38
|
var Config = import_koishi.Schema.object({
|
|
44
|
-
|
|
39
|
+
bot_username: import_koishi.Schema.string().description("机器人用户名"),
|
|
40
|
+
bot_password: import_koishi.Schema.string().description("机器人密码")
|
|
45
41
|
});
|
|
46
42
|
function apply(ctx, config) {
|
|
47
43
|
const logger = ctx.logger;
|
|
44
|
+
let wikibot;
|
|
48
45
|
ctx.model.extend("wikipages", {
|
|
49
46
|
id: "integer",
|
|
50
47
|
title: "string"
|
|
51
48
|
});
|
|
52
|
-
ctx.model.extend(
|
|
53
|
-
"searchpages",
|
|
54
|
-
{
|
|
55
|
-
id: "unsigned",
|
|
56
|
-
title: "string",
|
|
57
|
-
time: "string"
|
|
58
|
-
},
|
|
59
|
-
{
|
|
60
|
-
primary: "id",
|
|
61
|
-
autoInc: true
|
|
62
|
-
}
|
|
63
|
-
);
|
|
64
49
|
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
|
|
65
50
|
if (/教程/.test(itemName)) {
|
|
66
51
|
return `请点击链接前往站点查看:
|
|
67
52
|
原站点: http://oni.wiki/${encodeURI(
|
|
68
53
|
`教程`
|
|
69
54
|
)}
|
|
70
|
-
镜像站:
|
|
55
|
+
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
|
|
71
56
|
}
|
|
72
|
-
await ctx.database.create("searchpages", {
|
|
73
|
-
title: itemName,
|
|
74
|
-
time: import_koishi.Time.template("yyyy-MM-dd hh:mm:ss", /* @__PURE__ */ new Date())
|
|
75
|
-
});
|
|
76
57
|
const res = await ctx.database.get("wikipages", {
|
|
77
58
|
title: [`${itemName}`]
|
|
78
59
|
});
|
|
79
|
-
logger.info(res);
|
|
80
60
|
if (res.length == 0) {
|
|
81
61
|
return `在Wiki里没找到,如有需要,请按照游戏内名称重新发起查询....`;
|
|
82
62
|
}
|
|
@@ -84,38 +64,48 @@ function apply(ctx, config) {
|
|
|
84
64
|
原站点: http://oni.wiki/${encodeURI(
|
|
85
65
|
itemName
|
|
86
66
|
)}
|
|
87
|
-
镜像站:
|
|
67
|
+
镜像站: http://klei.vip/oni/usiz6d/${encodeURI(itemName)}`;
|
|
88
68
|
});
|
|
89
|
-
ctx.
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
69
|
+
ctx.on("ready", async () => {
|
|
70
|
+
wikibot = new import_mwn.Mwn({
|
|
71
|
+
apiUrl: "https://oxygennotincluded.wiki.gg/zh/api.php",
|
|
72
|
+
username: config.bot_username,
|
|
73
|
+
password: config.bot_password,
|
|
74
|
+
userAgent: "Charles`Bot/2.1",
|
|
75
|
+
defaultParams: {
|
|
76
|
+
assert: "user"
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
wikibot.login().then(() => {
|
|
80
|
+
logger.info("Wiki机器人登录成功");
|
|
81
|
+
}).catch((err) => {
|
|
82
|
+
logger.error("Wiki机器人登录失败", err);
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
|
|
86
|
+
wikibot.request({
|
|
87
|
+
action: "query",
|
|
88
|
+
list: "allpages",
|
|
89
|
+
format: "json",
|
|
90
|
+
aplimit: "max"
|
|
98
91
|
}).then((res) => {
|
|
99
|
-
|
|
100
|
-
res
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
{ id:
|
|
92
|
+
logger.info("查询成功");
|
|
93
|
+
const pages = res.query.allpages;
|
|
94
|
+
pages.forEach((page) => {
|
|
95
|
+
ctx.database.upsert("wikipages", () => [
|
|
96
|
+
{ id: page.pageid, title: page.title }
|
|
104
97
|
]);
|
|
105
98
|
});
|
|
106
|
-
|
|
99
|
+
session.send(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
|
|
100
|
+
logger.info(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
|
|
107
101
|
}).catch((err) => {
|
|
108
|
-
|
|
109
|
-
return `出现了一点点问题`;
|
|
102
|
+
logger.error("查询失败", err);
|
|
110
103
|
});
|
|
111
104
|
});
|
|
112
|
-
ctx.command("
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
ctx.command("RocketCalculator", "火箭计算器").alias("火箭计算器").action(async () => {
|
|
117
|
-
return `火箭计算器链接:
|
|
118
|
-
https://klei.vip/oni/t93o56`;
|
|
105
|
+
ctx.command("update.delete", " 删除本地页面缓存", { authority: 4 }).action(async ({ session }) => {
|
|
106
|
+
const count = await ctx.database.remove("wikipages", {});
|
|
107
|
+
session.send(`已删除 ${count.removed} 条本地缓存`);
|
|
108
|
+
logger.info(`已删除 ${count.removed} 条本地缓存`);
|
|
119
109
|
});
|
|
120
110
|
}
|
|
121
111
|
__name(apply, "apply");
|
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.
|
|
4
|
+
"version": "0.4.7",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"typings": "lib/index.d.ts",
|
|
7
7
|
"files": [
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
"plugin"
|
|
16
16
|
],
|
|
17
17
|
"peerDependencies": {
|
|
18
|
-
"koishi": "^4.
|
|
18
|
+
"koishi": "^4.18.9"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"mwn": "^3.0.1"
|
|
19
22
|
}
|
|
20
|
-
}
|
|
23
|
+
}
|