koishi-plugin-oni-wiki-qq 0.4.7 → 0.4.9

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.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,40 @@ 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.4.9 添加重定向功能
35
+ - 0.4.8 重启bwiki更新
34
36
  - 0.4.6 移除没必要的功能
35
37
  - 0.4.5 检测教程页面
36
38
  `;
37
39
  var inject = ["database"];
38
40
  var Config = import_koishi.Schema.object({
39
41
  bot_username: import_koishi.Schema.string().description("机器人用户名"),
40
- bot_password: import_koishi.Schema.string().description("机器人密码")
42
+ bot_password: import_koishi.Schema.string().description("机器人密码"),
43
+ bwiki_session: import_koishi.Schema.string().description("bwiki的session,无法连接到gg时使用")
41
44
  });
42
45
  function apply(ctx, config) {
43
46
  const logger = ctx.logger;
44
47
  let wikibot;
45
48
  ctx.model.extend("wikipages", {
46
49
  id: "integer",
47
- title: "string"
50
+ title: "string",
51
+ redirect: "string"
52
+ });
53
+ ctx.on("ready", async () => {
54
+ wikibot = new import_mwn.Mwn({
55
+ apiUrl: "https://oxygennotincluded.wiki.gg/zh/api.php",
56
+ username: config.bot_username,
57
+ password: config.bot_password,
58
+ userAgent: "Charles`Bot/2.1",
59
+ defaultParams: {
60
+ assert: "user"
61
+ }
62
+ });
63
+ wikibot.login().then(() => {
64
+ logger.info("Wiki机器人登录成功");
65
+ }).catch((err) => {
66
+ logger.error("Wiki机器人登录失败", err);
67
+ });
48
68
  });
49
69
  ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
50
70
  if (/教程/.test(itemName)) {
@@ -55,31 +75,58 @@ function apply(ctx, config) {
55
75
  镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
56
76
  }
57
77
  const res = await ctx.database.get("wikipages", {
58
- title: [`${itemName}`]
78
+ $or: [
79
+ {
80
+ title: itemName
81
+ },
82
+ {
83
+ redirect: itemName
84
+ }
85
+ ]
59
86
  });
60
87
  if (res.length == 0) {
61
88
  return `在Wiki里没找到,如有需要,请按照游戏内名称重新发起查询....`;
62
89
  }
90
+ const pageName = res[0].title;
63
91
  return `请点击链接前往站点查看:
64
92
  原站点: http://oni.wiki/${encodeURI(
65
- itemName
93
+ pageName
66
94
  )}
67
- 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(itemName)}`;
95
+ 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(pageName)}`;
68
96
  });
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
- }
97
+ ctx.command("x.redirect <itemName:string> <redirect:string>", "物品重定向", { authority: 2 }).alias("重定向").action(async ({ session }, itemName, redirect) => {
98
+ if (!itemName || !redirect) {
99
+ return `请提供物品名称或重定向链接,格式如下:
100
+ 重定向 页面名称 重定向到页面物品名称`;
101
+ }
102
+ const database_res = await ctx.database.get("wikipages", {
103
+ $or: [
104
+ {
105
+ title: itemName
106
+ },
107
+ {
108
+ redirect: itemName
109
+ }
110
+ ]
78
111
  });
79
- wikibot.login().then(() => {
80
- logger.info("Wiki机器人登录成功");
81
- }).catch((err) => {
82
- logger.error("Wiki机器人登录失败", err);
112
+ if (database_res.length == 0) {
113
+ return `在数据库里没找到 ${itemName},如有需要,请按照游戏内名称重新发起重定向或联系管理员`;
114
+ }
115
+ if (database_res[0].redirect) {
116
+ return `${itemName} 已存在重定向,如需修改请联系管理员`;
117
+ }
118
+ await ctx.database.upsert("wikipages", [{
119
+ id: database_res[0].id,
120
+ title: itemName,
121
+ redirect
122
+ }]).then(() => {
123
+ wikibot.save(`${itemName}`, `#REDIRECT [[${redirect}]]`).then(() => {
124
+ session.send(`已成功将 ${itemName} 重定向至 ${redirect}并写入GG原站点`);
125
+ }).catch((err) => {
126
+ logger.error("写入重定向至原站点失败:", err);
127
+ session.send("写入重定向至原站点失败,请联系管理员检查日志或自行前往原站点编辑");
128
+ });
129
+ return `已成功将 ${itemName} 重定向至 ${redirect} 并写入数据库`;
83
130
  });
84
131
  });
85
132
  ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
@@ -107,6 +154,31 @@ function apply(ctx, config) {
107
154
  session.send(`已删除 ${count.removed} 条本地缓存`);
108
155
  logger.info(`已删除 ${count.removed} 条本地缓存`);
109
156
  });
157
+ ctx.command("update.bwiki", "使用bwiki的session更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
158
+ const headers = {
159
+ "Content-Type": "application/json",
160
+ "user-agent": "Charles'queryBot",
161
+ Cookie: `SESSDATA=${config.bwiki_session}`
162
+ };
163
+ const url = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=0&aplimit=5000&format=json`;
164
+ ctx.http.get(url, { headers }).then((res) => {
165
+ res["query"]["allpages"].forEach((page) => {
166
+ ctx.database.upsert("wikipages", () => [
167
+ { id: page.pageid, title: page.title }
168
+ ]);
169
+ });
170
+ session.send(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
171
+ logger.info(`检索到 ${res["query"]["allpages"].length} 个页面,已尝试更新至数据库`);
172
+ }).catch((err) => {
173
+ session.send("更新失败,请联系管理员检查日志");
174
+ logger.error("更新失败", err);
175
+ });
176
+ });
177
+ ctx.command("update.status", "查询本地页面缓存数量", { authority: 1 }).action(async ({ session }) => {
178
+ const count = await ctx.database.get("wikipages", {});
179
+ session.send(`数据库中缓存了 ${count.length} 条页面`);
180
+ logger.info(`数据库中缓存了 ${count.length} 条页面`);
181
+ });
110
182
  }
111
183
  __name(apply, "apply");
112
184
  // 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.4.9",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [