koishi-plugin-oni-wiki-qq 0.2.3 → 0.3.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 CHANGED
@@ -1,22 +1,13 @@
1
1
  import { Context, Schema } from "koishi";
2
2
  export declare const name = "oni-wiki-qq";
3
- export declare const inject: string[];
4
- export declare const usage = "\n - 0.2.3 \u641E\u9519\u4E86,\u91CD\u6765\n - 0.2.2 \u5C1D\u8BD5\u79FB\u9664\u9876\u90E8\u5BFC\u822A\n - 0.2.1 \u4EA4\u6362\u56FE\u7247\u548C\u6D88\u606F\u4F4D\u7F6E\u4EE5\u4F7Fqq\u53D1\u9001\u65F6\u5728\u540C\u4E00\u6D88\u606F\u907F\u514D\u5237\u5C4F\n - 0.2.0 \u5C1D\u8BD5\u6DFB\u52A0 MWN \u5E93\n";
3
+ export declare const usage = "\n - 0.3.1 \u9519\u522B\u5B57\u4FEE\u6539\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";
5
4
  export interface Config {
6
5
  api: string;
7
- imgPath: string;
8
- urlPath: string;
9
- navSelector: string;
10
- navSelector2: string;
11
- contentSelector: string;
12
- loginUrl: string;
13
- userNameSelector: string;
14
- passwordSelector: string;
15
- checkBoxSelector: string;
6
+ originalUrl: string;
7
+ mirrorUrl: string;
8
+ docUrl: string;
16
9
  userName: string;
17
10
  password: string;
18
- mainPage: string;
19
- btnSelector: string;
20
11
  }
21
12
  export declare const Config: Schema<Config>;
22
13
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -1,8 +1,6 @@
1
- var __create = Object.create;
2
1
  var __defProp = Object.defineProperty;
3
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
7
5
  var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
6
  var __export = (target, all) => {
@@ -17,14 +15,6 @@ var __copyProps = (to, from, except, desc) => {
17
15
  }
18
16
  return to;
19
17
  };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
18
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
19
 
30
20
  // src/index.ts
@@ -32,187 +22,72 @@ var src_exports = {};
32
22
  __export(src_exports, {
33
23
  Config: () => Config,
34
24
  apply: () => apply,
35
- inject: () => inject,
36
25
  name: () => name,
37
26
  usage: () => usage
38
27
  });
39
28
  module.exports = __toCommonJS(src_exports);
40
29
  var import_koishi = require("koishi");
41
- var import_fs2 = __toESM(require("fs"));
42
- var import_node_os = __toESM(require("node:os"));
43
-
44
- // src/lib.ts
45
- var import_fs = __toESM(require("fs"));
46
30
  var import_mwn = require("mwn");
47
- function checkFileExists(filePath) {
48
- try {
49
- import_fs.default.accessSync(filePath, import_fs.default.constants.F_OK);
50
- return true;
51
- } catch (err) {
52
- return false;
53
- }
54
- }
55
- __name(checkFileExists, "checkFileExists");
56
- async function getWiki(itemName, config) {
57
- const { api, userName, password } = config;
58
- const bot = await import_mwn.Mwn.init({
59
- apiUrl: api,
60
- username: userName,
61
- password,
62
- userAgent: "queryBot 0.0.3 ([[user:Charles-lf]])",
63
- defaultParams: {
64
- assert: "user"
65
- }
66
- });
67
- return await bot.request({
68
- action: "opensearch",
69
- search: itemName,
70
- namespace: "*",
71
- limit: 3,
72
- redirects: "return",
73
- format: "json"
74
- }).then(async (res) => {
75
- console.log(res);
76
- if (res[1][0] == itemName) {
77
- return res[3][0];
78
- } else {
79
- return "";
80
- }
81
- }).catch(async (err) => console.log(err));
82
- }
83
- __name(getWiki, "getWiki");
84
-
85
- // src/index.ts
86
31
  var name = "oni-wiki-qq";
87
- var inject = ["puppeteer"];
88
32
  var usage = `
89
- - 0.2.3 搞错了,重来
90
- - 0.2.2 尝试移除顶部导航
91
- - 0.2.1 交换图片和消息位置以使qq发送时在同一消息避免刷屏
33
+ - 0.3.1 错别字修改
34
+ - 0.3.0 移除耗内存的截图部分,使用镜像站点网页
92
35
  - 0.2.0 尝试添加 MWN 库
93
36
  `;
94
37
  var Config = import_koishi.Schema.object({
95
38
  api: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/api.php").description("api地址"),
96
- imgPath: import_koishi.Schema.string().default(import_node_os.default.homedir() + "/wikiImg/").description("图片保存路径"),
97
- urlPath: import_koishi.Schema.string().description("图片公网访问路径"),
98
- navSelector: import_koishi.Schema.string().description("导航框类名").default(".navbox"),
99
- navSelector2: import_koishi.Schema.string().description("导航框类名").default("#wikigg-header"),
100
- contentSelector: import_koishi.Schema.string().description("内容区选择器").default("#mw-content-text"),
101
- loginUrl: import_koishi.Schema.string().description("登录页面地址").default(
102
- "https://oxygennotincluded.wiki.gg/zh/index.php?title=Special:%E7%94%A8%E6%88%B7%E7%99%BB%E5%BD%95&returnto=%E9%A6%96%E9%A1%B5"
103
- ),
104
- userNameSelector: import_koishi.Schema.string().description("用户名输入区选择器").default("input[name='wpName']"),
105
- passwordSelector: import_koishi.Schema.string().description("密码输入区选择器").default("input[name='wpPassword']"),
106
- checkBoxSelector: import_koishi.Schema.string().description("总是保持登录复选框").default("inpt[name='wpRemeber']"),
107
- userName: import_koishi.Schema.string().description("用户名"),
108
- password: import_koishi.Schema.string().description("密码"),
109
- mainPage: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/").description("主页地址"),
110
- btnSelector: import_koishi.Schema.string().default(".NN0_TB_DIsNmMHgJWgT7U").description("需要点击的按钮选择器")
39
+ originalUrl: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/").description("原站点网址"),
40
+ mirrorUrl: import_koishi.Schema.string().default("https://wiki.biligame.com/oni/").description("镜像站点网址"),
41
+ docUrl: import_koishi.Schema.string().default("https://www.yuque.com/u25332524/ftq4u7").description("大叔的文档地址"),
42
+ userName: import_koishi.Schema.string().description("机器人用户名"),
43
+ password: import_koishi.Schema.string().description("机器人密码")
111
44
  });
112
45
  function apply(ctx, config) {
113
46
  const logger = ctx.logger;
114
- ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority: 1 }).action(async ({ session, options }, itemName = "电解器") => {
115
- const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
116
- const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
117
- if (options.delete) {
118
- if (checkFileExists(filePath)) {
119
- import_fs2.default.unlinkSync(filePath);
120
- return `已尝试删除${itemName}的缓存...`;
121
- } else {
122
- return `文件不存在.请检查....`;
123
- }
124
- }
125
- if (checkFileExists(filePath)) {
126
- return (0, import_koishi.h)(
127
- "p",
128
- (0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` }),
129
- `图片已保存至:${encodeURI(urlPath)}`
130
- );
131
- }
47
+ ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
132
48
  session.send(`您查询的「${itemName}」进行中,请稍等...`);
133
- const res = await getWiki(itemName, config);
49
+ const res = await getWiki(itemName);
134
50
  if (!res) {
135
51
  return `在Wiki里没找到或API查询超时,如有需要,请按照游戏内名称重新发起查询....`;
136
52
  }
137
- let screenShotRes = await screenShot(res);
138
- if (screenShotRes) {
139
- return (0, import_koishi.h)(
140
- "p",
141
- (0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` }),
142
- `图片已保存至:${encodeURI(urlPath)}`
143
- );
144
- } else {
145
- return `截图发生错误.请稍后重试..`;
146
- }
147
- async function screenShot(url) {
148
- const page = await ctx.puppeteer.page();
149
- await page.goto(url, {
150
- timeout: 0
151
- });
152
- await (0, import_koishi.sleep)(2e3);
153
- await page.addStyleTag({
154
- content: `${config.contentSelector}{padding: 40px}`
155
- });
156
- try {
157
- await page.$eval(config.navSelector, (el) => el.remove());
158
- await page.$eval(config.navSelector2, (el) => el.remove());
159
- } catch (error) {
160
- }
161
- const selector = await page.$(config.contentSelector);
162
- return await selector.screenshot({
163
- type: "jpeg",
164
- quality: 60,
165
- path: filePath
166
- }).then(() => {
167
- return true;
168
- }).catch((err) => {
169
- logger.error(err);
170
- return false;
171
- }).finally(async () => await page.close());
172
- }
173
- __name(screenShot, "screenShot");
53
+ return `请点击链接前往站点查看:
54
+ 原站点: ${encodeURI(
55
+ res
56
+ )}
57
+ 镜像站: ${encodeURI(
58
+ res.replace(config.originalUrl, config.mirrorUrl)
59
+ )}`;
174
60
  });
175
- ctx.command("loginwiki [BotuserName] <BotPassword>", "使用机器人账户登录", {
176
- authority: 4
177
- }).action(async ({ session }, BotuserName = "", BotPassword) => {
178
- const page = await ctx.puppeteer.page();
179
- logger.info(`正在前往登录页:${config.loginUrl}`);
180
- await page.goto(config.loginUrl, {
181
- timeout: 0
61
+ async function getWiki(itemName) {
62
+ const bot = await import_mwn.Mwn.init({
63
+ apiUrl: config.api,
64
+ username: config.userName,
65
+ password: config.password,
66
+ userAgent: "queryBot 0.0.3 ([[user:Charles-lf]])",
67
+ defaultParams: {
68
+ assert: "user"
69
+ }
182
70
  });
183
- await (0, import_koishi.sleep)(4e3);
184
- logger.info(`输入用户名`);
185
- await page.type(config.userNameSelector, BotuserName);
186
- await (0, import_koishi.sleep)(1e3);
187
- logger.info(`输入密码`);
188
- await page.type(config.passwordSelector, BotPassword);
189
- await (0, import_koishi.sleep)(1e3);
190
- logger.info("点击保持登录复选框");
191
- await page.click(config.checkBoxSelector);
192
- await (0, import_koishi.sleep)(1e3);
193
- await page.click(`button[type="submit"]`);
194
- await (0, import_koishi.sleep)(6e3);
195
- const img = await page.screenshot({ type: "jpeg", quality: 50 });
196
- session.send(import_koishi.h.image(img, "jpeg/image"));
197
- await page.close().then(() => logger.info(`页面已经成功关闭`));
198
- return `登录已完成.`;
199
- });
200
- ctx.command("clickBtn", { authority: 4 }).action(async ({ session }) => {
201
- const page = await ctx.puppeteer.page();
202
- await page.goto(config.mainPage, { timeout: 0 });
203
- const selector = await page.$(config.btnSelector);
204
- await (0, import_koishi.sleep)(8e3);
205
- await selector.click().then(() => logger.info(`成功点击了按钮`)).catch((err) => logger.info(`出错啦,${err}`));
206
- await (0, import_koishi.sleep)(8e3);
207
- await page.click(`button[type="submit"]`).then(() => logger.info(`点击了按钮`)).catch((err) => logger.error(`出错了,${err}`));
208
- await (0, import_koishi.sleep)(5e3);
209
- session.send(
210
- import_koishi.h.image(
211
- await page.screenshot({ type: "jpeg", quality: 75 }),
212
- "jpeg/image"
213
- )
214
- );
215
- page.close;
71
+ return await bot.request({
72
+ action: "opensearch",
73
+ search: itemName,
74
+ namespace: "*",
75
+ limit: 3,
76
+ redirects: "return",
77
+ format: "json"
78
+ }).then(async (res) => {
79
+ logger.info(res);
80
+ if (res[1][0] == itemName) {
81
+ return res[3][0];
82
+ } else {
83
+ return "";
84
+ }
85
+ }).catch(async (err) => console.log(err));
86
+ }
87
+ __name(getWiki, "getWiki");
88
+ ctx.command("doc", "大叔的文档链接").alias("/大叔文档").action(async () => {
89
+ return `大叔的文档链接:
90
+ ${config.docUrl}`;
216
91
  });
217
92
  }
218
93
  __name(apply, "apply");
@@ -220,7 +95,6 @@ __name(apply, "apply");
220
95
  0 && (module.exports = {
221
96
  Config,
222
97
  apply,
223
- inject,
224
98
  name,
225
99
  usage
226
100
  });
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.2.3",
4
+ "version": "0.3.1",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
package/lib/lib.d.ts DELETED
@@ -1,3 +0,0 @@
1
- import { Config } from ".";
2
- export declare function checkFileExists(filePath: string): boolean;
3
- export declare function getWiki(itemName: string, config: Config): Promise<string>;