koishi-plugin-oni-wiki-qq 0.4.4 → 0.4.6

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,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.4 \u52A0\u5165\u7528\u6237\u9875\u9762\n - 0.4.3 \u6536\u96C6\u641C\u7D22\u7684\u8BCD\u6C47\u9891\u7387\n - 0.4.2 \u4FEE\u6539/ \u7684\u4F7F\u7528\u65B9\u5F0F,\u6539\u4E3A >\n - 0.4.1 \u589E\u52A0/\u7684\u5904\u7406\n - 0.4.0 \u79FB\u9664MWN.\u5C06\u67E5\u8BE2\u5904\u7406\u6539\u81F3\u67E5\u8BE2\u6570\u636E\u5E93\n - 0.3.0 \u79FB\u9664\u8017\u5185\u5B58\u7684\u622A\u56FE\u90E8\u5206,\u4F7F\u7528\u955C\u50CF\u7AD9\u70B9\u7F51\u9875\n - 0.2.0 \u5C1D\u8BD5\u6DFB\u52A0 MWN \u5E93\n";
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
- SESSDATA: string;
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,19 +28,16 @@ __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 = `
33
- - 0.4.4 加入用户页面
34
- - 0.4.3 收集搜索的词汇频率
35
- - 0.4.2 修改/ 的使用方式,改为 >
36
- - 0.4.1 增加/的处理
37
- - 0.4.0 移除MWN.将查询处理改至查询数据库
38
- - 0.3.0 移除耗内存的截图部分,使用镜像站点网页
39
- - 0.2.0 尝试添加 MWN 库
34
+ - 0.4.6 移除没必要的功能
35
+ - 0.4.5 检测教程页面
40
36
  `;
41
37
  var inject = ["database"];
42
38
  var Config = import_koishi.Schema.object({
43
- SESSDATA: import_koishi.Schema.string().description("SESSDATA")
39
+ bot_username: import_koishi.Schema.string().description("机器人用户名"),
40
+ bot_password: import_koishi.Schema.string().description("机器人密码")
44
41
  });
45
42
  function apply(ctx, config) {
46
43
  const logger = ctx.logger;
@@ -48,27 +45,17 @@ function apply(ctx, config) {
48
45
  id: "integer",
49
46
  title: "string"
50
47
  });
51
- ctx.model.extend(
52
- "searchpages",
53
- {
54
- id: "unsigned",
55
- title: "string",
56
- time: "string"
57
- },
58
- {
59
- primary: "id",
60
- autoInc: true
61
- }
62
- );
63
48
  ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
64
- await ctx.database.create("searchpages", {
65
- title: itemName,
66
- time: import_koishi.Time.template("yyyy-MM-dd hh:mm:ss", /* @__PURE__ */ new Date())
67
- });
49
+ if (/教程/.test(itemName)) {
50
+ return `请点击链接前往站点查看:
51
+ 原站点: http://oni.wiki/${encodeURI(
52
+ `教程`
53
+ )}
54
+ 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(`教程`)}`;
55
+ }
68
56
  const res = await ctx.database.get("wikipages", {
69
57
  title: [`${itemName}`]
70
58
  });
71
- logger.info(res);
72
59
  if (res.length == 0) {
73
60
  return `在Wiki里没找到,如有需要,请按照游戏内名称重新发起查询....`;
74
61
  }
@@ -76,48 +63,42 @@ function apply(ctx, config) {
76
63
  原站点: http://oni.wiki/${encodeURI(
77
64
  itemName
78
65
  )}
79
- 镜像站: https://klei.vip/oni/usiz6d/${encodeURI(itemName)}`;
66
+ 镜像站: http://klei.vip/oni/usiz6d/${encodeURI(itemName)}`;
80
67
  });
81
- ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async () => {
82
- const headers = {
83
- "Content-Type": "application/json",
84
- "user-agent": "Charles'queryBot",
85
- Cookie: `SESSDATA=${config.SESSDATA}`
86
- };
87
- const url = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=0&aplimit=5000&format=json`;
88
- const user = `https://wiki.biligame.com/oni/api.php?action=query&list=allpages&apnamespace=2&aplimit=5000&format=json`;
89
- await ctx.http.get(user, { headers }).then((res) => {
90
- res["query"]["allpages"].forEach(async (element) => {
91
- console.log(element.title);
92
- await ctx.database.upsert("wikipages", () => [
93
- { id: element.pageid, title: element.title }
94
- ]);
95
- });
68
+ ctx.command("update", "更新本地页面缓存", { authority: 2 }).action(async ({ session }) => {
69
+ const bot = new import_mwn.Mwn({
70
+ apiUrl: "https://oxygennotincluded.wiki.gg/zh/api.php",
71
+ username: config.bot_username,
72
+ password: config.bot_password,
73
+ userAgent: "Charles`Bot/2.1 Charles@klei.vip",
74
+ defaultParams: {
75
+ assert: "user"
76
+ }
96
77
  });
97
- return await ctx.http.get(url, {
98
- headers
99
- }).then((res) => {
100
- console.log(res["query"]["allpages"]);
101
- res["query"]["allpages"].forEach(async (element) => {
102
- console.log(element.title);
103
- await ctx.database.upsert("wikipages", () => [
104
- { id: element.pageid, title: element.title }
105
- ]);
78
+ bot.login().then(async () => {
79
+ logger.info("登录成功");
80
+ bot.request({
81
+ action: "query",
82
+ list: "allpages",
83
+ format: "json",
84
+ aplimit: "max"
85
+ }).then((res) => {
86
+ logger.info("查询成功");
87
+ const pages = res.query.allpages;
88
+ pages.forEach((page) => {
89
+ ctx.database.upsert("wikipages", () => [
90
+ { id: page.pageid, title: page.title }
91
+ ]);
92
+ });
93
+ session.send(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
94
+ logger.info(`检索到 ${pages.length} 个页面,已尝试更新至数据库`);
95
+ }).catch((err) => {
96
+ logger.error("查询失败", err);
106
97
  });
107
- return `更新已完成,已尝试写入数据库}`;
108
98
  }).catch((err) => {
109
- console.log(err);
110
- return `出现了一点点问题`;
99
+ logger.error("登录失败", err);
111
100
  });
112
101
  });
113
- ctx.command("doc", "大叔的文档链接").alias("/大叔文档").action(async () => {
114
- return `大叔的文档链接:
115
- https://klei.vip/oni/926f8b`;
116
- });
117
- ctx.command("RocketCalculator", "火箭计算器").alias("火箭计算器").action(async () => {
118
- return `火箭计算器链接:
119
- https://klei.vip/oni/t93o56`;
120
- });
121
102
  }
122
103
  __name(apply, "apply");
123
104
  // 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.4",
4
+ "version": "0.4.6",
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.17.12"
18
+ "koishi": "^4.18.9"
19
+ },
20
+ "dependencies": {
21
+ "mwn": "^3.0.1"
19
22
  }
20
23
  }