koishi-plugin-oni-wiki-qq 0.4.7 → 0.5.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 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.4.6 \u79FB\u9664\u6CA1\u5FC5\u8981\u7684\u529F\u80FD\n - 0.4.5 \u68C0\u6D4B\u6559\u7A0B\u9875\u9762\n";
3
+ export declare const usage = "\n - 0.5.0 \u79FB\u9664\u91CD\u5B9A\u5411\u529F\u80FD GG\u7AD9\u70B9\u5DF2\u4FEE\u590D\uFF0C\u4FDD\u9669\u8D77\u89C1\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,10 +10,12 @@ declare module "koishi" {
10
10
  export interface WikiPages {
11
11
  id: number;
12
12
  title: string;
13
+ redirect: string;
13
14
  }
14
15
  export interface Config {
15
16
  bot_username: string;
16
17
  bot_password: string;
18
+ bwiki_session: string;
17
19
  }
18
20
  export declare const Config: Schema<Config>;
19
21
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -31,20 +31,41 @@ var import_koishi = require("koishi");
31
31
  var import_mwn = require("mwn");
32
32
  var name = "oni-wiki-qq";
33
33
  var usage = `
34
+ - 0.5.0 移除重定向功能 GG站点已修复,保险起见保留bwiki更新功能
35
+ - 0.4.9 添加重定向功能
36
+ - 0.4.8 重启bwiki更新
34
37
  - 0.4.6 移除没必要的功能
35
38
  - 0.4.5 检测教程页面
36
39
  `;
37
40
  var inject = ["database"];
38
41
  var Config = import_koishi.Schema.object({
39
42
  bot_username: import_koishi.Schema.string().description("机器人用户名"),
40
- bot_password: import_koishi.Schema.string().description("机器人密码")
43
+ bot_password: import_koishi.Schema.string().description("机器人密码"),
44
+ bwiki_session: import_koishi.Schema.string().description("bwiki的session,无法连接到gg时使用")
41
45
  });
42
46
  function apply(ctx, config) {
43
47
  const logger = ctx.logger;
44
48
  let wikibot;
45
49
  ctx.model.extend("wikipages", {
46
50
  id: "integer",
47
- title: "string"
51
+ title: "string",
52
+ redirect: "string"
53
+ });
54
+ ctx.on("ready", async () => {
55
+ wikibot = new import_mwn.Mwn({
56
+ apiUrl: "https://oxygennotincluded.wiki.gg/zh/api.php",
57
+ username: config.bot_username,
58
+ password: config.bot_password,
59
+ userAgent: "Charles`Bot/2.1",
60
+ defaultParams: {
61
+ assert: "user"
62
+ }
63
+ });
64
+ wikibot.login().then(() => {
65
+ logger.info("Wiki机器人登录成功");
66
+ }).catch((err) => {
67
+ logger.error("Wiki机器人登录失败", err);
68
+ });
48
69
  });
49
70
  ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
50
71
  if (/教程/.test(itemName)) {
@@ -55,32 +76,24 @@ function apply(ctx, config) {
55
76
  镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
56
77
  }
57
78
  const res = await ctx.database.get("wikipages", {
58
- title: [`${itemName}`]
79
+ $or: [
80
+ {
81
+ title: itemName
82
+ },
83
+ {
84
+ redirect: itemName
85
+ }
86
+ ]
59
87
  });
60
88
  if (res.length == 0) {
61
89
  return `在Wiki里没找到,如有需要,请按照游戏内名称重新发起查询....`;
62
90
  }
91
+ const pageName = res[0].title;
63
92
  return `请点击链接前往站点查看:
64
93
  原站点: http://oni.wiki/${encodeURI(
65
- itemName
94
+ pageName
66
95
  )}
67
- 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(itemName)}`;
68
- });
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
- });
96
+ 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(pageName)}`;
84
97
  });
85
98
  ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
86
99
  wikibot.request({
@@ -107,6 +120,31 @@ function apply(ctx, config) {
107
120
  session.send(`已删除 ${count.removed} 条本地缓存`);
108
121
  logger.info(`已删除 ${count.removed} 条本地缓存`);
109
122
  });
123
+ ctx.command("update.bwiki", "使用bwiki的session更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
124
+ const headers = {
125
+ "Content-Type": "application/json",
126
+ "user-agent": "Charles'queryBot",
127
+ Cookie: `SESSDATA=${config.bwiki_session}`
128
+ };
129
+ const url = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=0&aplimit=5000&format=json`;
130
+ ctx.http.get(url, { headers }).then((res) => {
131
+ res["query"]["allpages"].forEach((page) => {
132
+ ctx.database.upsert("wikipages", () => [
133
+ { id: page.pageid, title: page.title }
134
+ ]);
135
+ });
136
+ session.send(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
137
+ logger.info(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
138
+ }).catch((err) => {
139
+ session.send("更新失败,请联系管理员检查日志");
140
+ logger.error("更新失败", err);
141
+ });
142
+ });
143
+ ctx.command("update.status", "查询本地页面缓存数量", { authority: 1 }).action(async ({ session }) => {
144
+ const count = await ctx.database.get("wikipages", {});
145
+ session.send(`数据库中缓存了 ${count.length} 条页面`);
146
+ logger.info(`数据库中缓存了 ${count.length} 条页面`);
147
+ });
110
148
  }
111
149
  __name(apply, "apply");
112
150
  // Annotate the CommonJS export names for ESM import in node:
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.7",
4
+ "version": "0.5.0",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [