koishi-plugin-oni-wiki-qq 0.0.3 → 0.0.5

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,12 +1,11 @@
1
1
  import { Context, Schema } from "koishi";
2
2
  export declare const name = "oni-wiki-qq";
3
3
  export declare const inject: string[];
4
- export declare const usage = "\n - 0.0.3 \u5C06\u94FE\u63A5\u6539\u4E3Amd\u53D1\u9001\u4EE5\u7ED5\u8FC7\u6C9F\u817E\u8BAF\u7684\u94FE\u63A5\u62E6\u622A\n - 0.0.2 \u57FA\u672C\u529F\u80FD\u5B8C\u6210\n - 0.0.1 \u521D\u59CB\u5316\uFF0C\u660E\u5929\u518D\u6162\u6162\u5199\u4E86\uFF08\n";
4
+ export declare const usage = "\n - 0.0.5 \u592A\u4E45\u6CA1\u5199\u5FD8\u8BB0build\u4E86...\n - 0.0.4 \u715E\u7B14\u817E\u8BAF\u4E0D\u7ED9\u53D1md\u4E86\u8279\n - 0.0.3 \u5C06\u94FE\u63A5\u6539\u4E3Amd\u53D1\u9001\u4EE5\u7ED5\u8FC7\u6C9F\u817E\u8BAF\u7684\u94FE\u63A5\u62E6\u622A\n - 0.0.2 \u57FA\u672C\u529F\u80FD\u5B8C\u6210\n - 0.0.1 \u521D\u59CB\u5316\uFF0C\u660E\u5929\u518D\u6162\u6162\u5199\u4E86\uFF08\n";
5
5
  export interface Config {
6
- mdId: string;
7
6
  api: string;
8
7
  imgPath: string;
9
- publicUrl: string;
8
+ urlPath: string;
10
9
  }
11
10
  export declare const Config: Schema<Config>;
12
11
  export declare function apply(ctx: Context, config: Config): void;
package/lib/index.js CHANGED
@@ -1,450 +1,174 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
8
+ var __export = (target, all) => {
9
+ for (var name2 in all)
10
+ __defProp(target, name2, { get: all[name2], enumerable: true });
24
11
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
27
19
  };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Config = exports.usage = exports.inject = exports.name = void 0;
30
- exports.apply = apply;
31
- const koishi_1 = require("koishi");
32
- const fs_1 = __importDefault(require("fs"));
33
- const os_1 = __importDefault(require("os"));
34
- const lib = __importStar(require("./lib"));
35
- exports.name = "oni-wiki-qq";
36
- exports.inject = ["puppeteer"];
37
- exports.usage = `
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
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ Config: () => Config,
34
+ apply: () => apply,
35
+ inject: () => inject,
36
+ name: () => name,
37
+ usage: () => usage
38
+ });
39
+ module.exports = __toCommonJS(src_exports);
40
+ var import_koishi = require("koishi");
41
+ var import_fs = __toESM(require("fs"));
42
+ var import_node_os = __toESM(require("node:os"));
43
+ var name = "oni-wiki-qq";
44
+ var inject = ["puppeteer"];
45
+ var usage = `
46
+ - 0.0.5 太久没写忘记build了...
47
+ - 0.0.4 煞笔腾讯不给发md了艹
38
48
  - 0.0.3 将链接改为md发送以绕过沟腾讯的链接拦截
39
49
  - 0.0.2 基本功能完成
40
50
  - 0.0.1 初始化,明天再慢慢写了(
41
51
  `;
42
- exports.Config = koishi_1.Schema.object({
43
- mdId: koishi_1.Schema.string().description("模板ID").default("102019091_1708758661"),
44
- api: koishi_1.Schema.string()
45
- .description("api地址")
46
- .default("https://oxygennotincluded.fandom.com/zh/api.php"),
47
- imgPath: koishi_1.Schema.string()
48
- .description("图片保存路径")
49
- .default(os_1.default.homedir() + "\\wikiImg\\"),
50
- publicUrl: koishi_1.Schema.string().description("图片公网访问路径"),
52
+ var Config = import_koishi.Schema.object({
53
+ api: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/api.php").description("api地址"),
54
+ imgPath: import_koishi.Schema.string().default(import_node_os.default.homedir() + "/wikiImg/").description("图片保存路径"),
55
+ urlPath: import_koishi.Schema.string().description("图片公网访问路径")
51
56
  });
52
57
  function apply(ctx, config) {
53
- const logger = ctx.logger(exports.name);
54
- // 注册指令
55
- ctx
56
- .command("c <itemName>", "查询缺氧中文wiki")
57
- .alias("/查wiki")
58
- .option("update", "-u 更新本地缓存", { authority: 2 })
59
- .option("delete", "-d 删除本地缓存", { authority: 2 })
60
- .option("rename", "-r <newName> 重命名本地缓存", { authority: 2 })
61
- .action(async ({ session, options }, itemName = "电解器") => {
62
- let filePath = config.imgPath +
63
- itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") +
64
- ".jpeg";
65
- if (options.update) {
66
- let url = "https://oxygennotincluded.fandom.com/zh/wiki/" + encodeURI(itemName);
67
- await lib.screenShot(url, ctx, itemName, config);
68
- return `已尝试为您更新${itemName}的缓存...}`;
69
- }
70
- if (options.delete) {
71
- let filePath = config.imgPath + itemName + ".jpeg";
72
- if (lib.checkFileExists(filePath)) {
73
- fs_1.default.unlinkSync(filePath);
74
- return `已尝试删除${itemName}的缓存...`;
75
- }
76
- else {
77
- return `文件不存在...`;
78
- }
79
- }
80
- if (options.rename) {
81
- if (lib.checkFileExists(filePath)) {
82
- fs_1.default.renameSync(filePath, config.imgPath + options.rename + ".jpeg");
83
- return `已尝试重命名文件...`;
84
- }
85
- else {
86
- return `文件不存在...`;
87
- }
88
- }
89
- // 主流程
90
- session.send("正在查询中,请稍后...");
91
- await lib.delay(1000);
92
- // 判断文件是否在本地
93
- if (lib.checkFileExists(filePath)) {
94
- await session.bot.internal.sendMessage(session.guildId, {
95
- content: "111",
96
- msg_type: 2,
97
- markdown: {
98
- custom_template_id: config.mdId,
99
- params: [
100
- {
101
- key: "text1",
102
- values: [
103
- `文件缓存已命中,缓存时间为:${lib.getFileModifyTime(filePath)} 请前往以下网址查看:[🔗${itemName}`,
104
- ],
105
- },
106
- {
107
- key: "text2",
108
- values: [
109
- `](${config.publicUrl +
110
- itemName
111
- .replace(/\//g, "-")
112
- .replace(/:/g, "-")
113
- .replace(/'/g, "-")}.jpeg)`,
114
- ],
115
- },
116
- ],
117
- },
118
- keyboard: {
119
- content: {
120
- rows: [
121
- {
122
- buttons: [
123
- {
124
- id: "1",
125
- render_data: {
126
- label: "我也要查wiki",
127
- visited_label: "我也要查wiki",
128
- },
129
- action: {
130
- type: 2,
131
- permission: {
132
- type: 2,
133
- },
134
- unsupport_tips: "兼容文本",
135
- data: "/查wiki ",
136
- enter: false,
137
- },
138
- },
139
- ],
140
- },
141
- ],
142
- },
143
- },
144
- msg_id: session.messageId,
145
- timestamp: session.timestamp,
146
- msg_seq: Math.floor(Math.random() * 500),
147
- });
148
- return;
58
+ const logger = ctx.logger;
59
+ ctx.command("t <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority: 2 }).action(async ({ session, options }, itemName = "电解器") => {
60
+ logger.info(session.guildId);
61
+ const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
62
+ const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
63
+ if (options.delete) {
64
+ if (checkFileExists(filePath)) {
65
+ import_fs.default.unlinkSync(filePath);
66
+ return `已尝试删除${itemName}的缓存...`;
67
+ } else {
68
+ return `文件不存在.请检查....`;
69
+ }
70
+ }
71
+ if (checkFileExists(filePath)) {
72
+ return (0, import_koishi.h)("img", { src: `${urlPath}` });
73
+ }
74
+ session.send(`您查询的「${itemName}」进行中,请稍等...`);
75
+ await (0, import_koishi.sleep)(2e3);
76
+ const res = await getWiki(config.api);
77
+ if (res.length == 0) {
78
+ return `在Wiki里没找到或API查询超时或....`;
79
+ }
80
+ const title = [...res[0]];
81
+ let itemUrl = [...res[1]];
82
+ logger.info(`API返回的数据为: ${title}`);
83
+ if (title[0] === itemName) {
84
+ let res2 = await screenShot(itemUrl[0]);
85
+ if (res2) {
86
+ return (0, import_koishi.h)("img", { src: `${urlPath}` });
87
+ } else {
88
+ return `截图发生错误.请稍后重试..`;
89
+ }
90
+ } else {
91
+ let [one = "萌新的骨头汤", two = "托德的女装", three = "鮟鱇鱼"] = title;
92
+ session.send(
93
+ `wiki里没有找到,你可以看看底下有没有你需要的,有,回复数字序号,没有,请等待查询超时减轻服务器压力.
94
+ 1.${one}
95
+ 2.${two}
96
+ 3.${three}`
97
+ );
98
+ const awlist = [1, 2, 3];
99
+ const awser = +(await session.prompt(50 * 1e3))?.replace(/\s+/g, "")?.slice(-1) || NaN;
100
+ if (awlist.includes(awser)) {
101
+ let res2 = await screenShot(itemUrl[awser - 1]);
102
+ if (res2) {
103
+ return (0, import_koishi.h)("img", { src: `${urlPath}` });
104
+ } else {
105
+ return `截图发生错误.请稍后重试..`;
149
106
  }
150
- else {
151
- // 没有缓存
152
- let res = await lib.getFromFandom(config.api, ctx, itemName);
153
- if (res.length === 0) {
154
- // session.send()
155
- return `在Wiki里没找到或API查询超时或....`;
156
- }
157
- else {
158
- const title = [...res[0]];
159
- let res_url = [...res[1]];
160
- logger.info(`API返回的数据为: ${title}`);
161
- if (title[0] === itemName) {
162
- let res = await lib.screenShot(res_url[0], ctx, itemName, config);
163
- if (res) {
164
- await session.bot.internal.sendMessage(session.guildId, {
165
- content: "111",
166
- msg_type: 2,
167
- markdown: {
168
- custom_template_id: config.mdId,
169
- params: [
170
- {
171
- key: "text1",
172
- values: [
173
- `文件缓存已命中,缓存时间为:${lib.getFileModifyTime(filePath)} 请前往以下网址查看:[🔗${itemName}`,
174
- ],
175
- },
176
- {
177
- key: "text2",
178
- values: [
179
- `](${config.publicUrl +
180
- itemName
181
- .replace(/\//g, "-")
182
- .replace(/:/g, "-")
183
- .replace(/'/g, "-")}.jpeg)`,
184
- ],
185
- },
186
- ],
187
- },
188
- keyboard: {
189
- content: {
190
- rows: [
191
- {
192
- buttons: [
193
- {
194
- id: "1",
195
- render_data: {
196
- label: "我也要查wiki",
197
- visited_label: "我也要查wiki",
198
- },
199
- action: {
200
- type: 2,
201
- permission: {
202
- type: 2,
203
- },
204
- unsupport_tips: "兼容文本",
205
- data: "/查wiki ",
206
- enter: false,
207
- },
208
- },
209
- ],
210
- },
211
- ],
212
- },
213
- },
214
- msg_id: session.messageId,
215
- timestamp: session.timestamp,
216
- msg_seq: Math.floor(Math.random() * 500),
217
- });
218
- }
219
- }
220
- else {
221
- let [one = "曼德拉草汤", two = "火龙果派", three = "大肉汤", four = "饺子", five = "萌新骨头汤",] = title;
222
- // 发送md消息
223
- let btn_list = [["①", "1", "②", "2", "③", "④", "4", "⑤", "5"]];
224
- await session.bot.internal.sendMessage(session.guildId, {
225
- content: "111",
226
- msg_type: 2,
227
- markdown: {
228
- custom_template_id: config.mdId,
229
- params: [
230
- {
231
- key: "text1",
232
- values: ["Oh,No,出现了一丢丢问题"],
233
- },
234
- {
235
- key: "text2",
236
- values: [
237
- "没有找到您查询的关键字,以下是自主搜索的结果,你康康有没有需要的,点击按钮选择,没有的话,请等待超时结束本轮查询以减轻服务器压力",
238
- ],
239
- },
240
- {
241
- key: "text3",
242
- values: [`占位`],
243
- },
244
- {
245
- key: "text4",
246
- values: [`1- ${one}`],
247
- },
248
- {
249
- key: "text5",
250
- values: [`2- ${two}`],
251
- },
252
- {
253
- key: "text6",
254
- values: [`3- ${three}`],
255
- },
256
- {
257
- key: "text7",
258
- values: [`4- ${four}`],
259
- },
260
- {
261
- key: "text8",
262
- values: [`5- ${five}`],
263
- },
264
- ],
265
- },
266
- keyboard: {
267
- content: {
268
- rows: [
269
- {
270
- buttons: [
271
- {
272
- id: "1",
273
- render_data: {
274
- label: `①`,
275
- visited_label: `①`,
276
- },
277
- action: {
278
- type: 2,
279
- permission: {
280
- type: 2,
281
- },
282
- unsupport_tips: "兼容文本",
283
- data: "1",
284
- enter: true,
285
- },
286
- },
287
- {
288
- id: "2",
289
- render_data: {
290
- label: `②`,
291
- visited_label: `②`,
292
- },
293
- action: {
294
- type: 2,
295
- permission: {
296
- type: 2,
297
- },
298
- unsupport_tips: "兼容文本",
299
- data: "2",
300
- enter: true,
301
- },
302
- },
303
- {
304
- id: "3",
305
- render_data: {
306
- label: `③`,
307
- visited_label: `③`,
308
- },
309
- action: {
310
- type: 2,
311
- permission: {
312
- type: 2,
313
- },
314
- unsupport_tips: "兼容文本",
315
- data: "3",
316
- enter: true,
317
- },
318
- },
319
- {
320
- id: "4",
321
- render_data: {
322
- label: `④`,
323
- visited_label: `④`,
324
- },
325
- action: {
326
- type: 2,
327
- permission: {
328
- type: 2,
329
- },
330
- unsupport_tips: "兼容文本",
331
- data: "4",
332
- enter: true,
333
- },
334
- },
335
- {
336
- id: "5",
337
- render_data: {
338
- label: `⑤`,
339
- visited_label: `⑤`,
340
- },
341
- action: {
342
- type: 2,
343
- permission: {
344
- type: 2,
345
- },
346
- unsupport_tips: "兼容文本",
347
- data: "5",
348
- enter: true,
349
- },
350
- },
351
- ],
352
- },
353
- {
354
- buttons: [
355
- {
356
- id: "1",
357
- render_data: {
358
- label: "我也要查wiki",
359
- visited_label: "我也要查wiki",
360
- },
361
- action: {
362
- type: 2,
363
- permission: {
364
- type: 2,
365
- },
366
- unsupport_tips: "兼容文本",
367
- data: "/查wiki ",
368
- enter: false,
369
- },
370
- },
371
- ],
372
- },
373
- ],
374
- },
375
- },
376
- msg_id: session.messageId,
377
- timestamp: session.timestamp,
378
- msg_seq: Math.floor(Math.random() * 500),
379
- });
380
- const awlist = [1, 2, 3, 4, 5];
381
- const awser = +(await session.prompt(50 * 1000))
382
- ?.replace(/\s+/g, "")
383
- ?.slice(-1) || NaN;
384
- if (awlist.includes(awser)) {
385
- let res = await lib.screenShot(res_url[awser - 1], ctx, itemName, config);
386
- if (res) {
387
- await session.bot.internal.sendMessage(session.guildId, {
388
- content: "111",
389
- msg_type: 2,
390
- markdown: {
391
- custom_template_id: config.mdId,
392
- params: [
393
- {
394
- key: "text1",
395
- values: [
396
- `文件缓存已命中,缓存时间为:${lib.getFileModifyTime(filePath)} 请前往以下网址查看:[🔗${itemName}`,
397
- ],
398
- },
399
- {
400
- key: "text2",
401
- values: [
402
- `](${config.publicUrl +
403
- itemName
404
- .replace(/\//g, "-")
405
- .replace(/:/g, "-")
406
- .replace(/'/g, "-")}.jpeg)`,
407
- ],
408
- },
409
- ],
410
- },
411
- keyboard: {
412
- content: {
413
- rows: [
414
- {
415
- buttons: [
416
- {
417
- id: "1",
418
- render_data: {
419
- label: "我也要查wiki",
420
- visited_label: "我也要查wiki",
421
- },
422
- action: {
423
- type: 2,
424
- permission: {
425
- type: 2,
426
- },
427
- unsupport_tips: "兼容文本",
428
- data: "/查wiki ",
429
- enter: false,
430
- },
431
- },
432
- ],
433
- },
434
- ],
435
- },
436
- },
437
- msg_id: session.messageId,
438
- timestamp: session.timestamp,
439
- msg_seq: Math.floor(Math.random() * 500),
440
- });
441
- }
442
- }
443
- else if (Number.isNaN(awser)) {
444
- return `您输入的选项有误,已完结本轮查询。如需,如有需要,请重新发起查询.`;
445
- }
446
- }
447
- }
107
+ } else if (Number.isNaN(awser)) {
108
+ return `您输入的选项有误,已完结本轮查询。如需,如有需要,请重新发起查询.`;
109
+ }
110
+ }
111
+ async function getWiki(api) {
112
+ return await ctx.http.get(api, {
113
+ headers: {
114
+ "Content-Type": "application/json",
115
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36"
116
+ },
117
+ params: {
118
+ action: `opensearch`,
119
+ search: itemName,
120
+ limit: 3,
121
+ redirects: "return",
122
+ format: "json"
448
123
  }
449
- });
124
+ }).then(async (res2) => {
125
+ logger.info(res2);
126
+ return [res2[1], res2[3]];
127
+ }).catch((err) => {
128
+ logger.error(err);
129
+ return [];
130
+ });
131
+ }
132
+ __name(getWiki, "getWiki");
133
+ async function screenShot(url) {
134
+ const page = await ctx.puppeteer.page();
135
+ await page.goto(url, {
136
+ timeout: 0
137
+ });
138
+ await (0, import_koishi.sleep)(3e3);
139
+ await page.addStyleTag({
140
+ content: "#mw-content-text{padding: 40px}"
141
+ });
142
+ const selector = await page.$("#mw-content-text");
143
+ return await selector.screenshot({
144
+ type: "jpeg",
145
+ quality: 50,
146
+ path: filePath
147
+ }).then(() => {
148
+ return true;
149
+ }).catch((err) => {
150
+ logger.error(err);
151
+ return false;
152
+ }).finally(async () => await page.close());
153
+ }
154
+ __name(screenShot, "screenShot");
155
+ });
156
+ }
157
+ __name(apply, "apply");
158
+ function checkFileExists(filePath) {
159
+ try {
160
+ import_fs.default.accessSync(filePath, import_fs.default.constants.F_OK);
161
+ return true;
162
+ } catch (err) {
163
+ return false;
164
+ }
450
165
  }
166
+ __name(checkFileExists, "checkFileExists");
167
+ // Annotate the CommonJS export names for ESM import in node:
168
+ 0 && (module.exports = {
169
+ Config,
170
+ apply,
171
+ inject,
172
+ name,
173
+ usage
174
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-oni-wiki-qq",
3
- "description": "缺氧Wiki查询。QQ群版。需要官方群机器人md模板和群机器人权限。自用",
4
- "version": "0.0.3",
3
+ "description": "缺氧wiki查询",
4
+ "version": "0.0.5",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [
@@ -15,6 +15,6 @@
15
15
  "plugin"
16
16
  ],
17
17
  "peerDependencies": {
18
- "koishi": "^4.17.2"
18
+ "koishi": "^4.17.9"
19
19
  }
20
20
  }
package/readme.md CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  [![npm](https://img.shields.io/npm/v/koishi-plugin-oni-wiki-qq?style=flat-square)](https://www.npmjs.com/package/koishi-plugin-oni-wiki-qq)
4
4
 
5
- 缺氧Wiki查询。QQ群版。需要官方群机器人md模板和群机器人权限。
5
+
package/lib/lib.d.ts DELETED
@@ -1,45 +0,0 @@
1
- import { Context } from "koishi";
2
- import { Config } from ".";
3
- /**
4
- * 检查文件是否存在
5
- * @param filePath 文件路径
6
- * @returns true:存在 false:不存在
7
- */
8
- export declare function checkFileExists(filePath: string): boolean;
9
- /**
10
- * @desc 获取文件修改时间
11
- * @param filePath 文件路径
12
- * @returns string 文件修改时间
13
- */
14
- export declare function getFileModifyTime(filePath: string): string;
15
- /**
16
- * @desc 截屏
17
- * @param url 截屏地址
18
- * @param ctx 上下文
19
- * @param config 配置
20
- * @param itemName 物品名称
21
- * @returns string
22
- */
23
- export declare function screenShot(url: string, ctx: Context, itemName: string, config: Config): Promise<boolean>;
24
- /**
25
- *
26
- * @param ms 延迟毫秒数
27
- * @returns void
28
- */
29
- export declare function delay(ms: number): Promise<unknown>;
30
- /**
31
- * @desc 从fandom获取数据
32
- * @returns []
33
- */
34
- export declare function getFromFandom(url: string, ctx: Context, itemName: string): Promise<any[]>;
35
- /**
36
- * @param list 传入的列表,内部元素要求为偶数个
37
- * @returns 对象列表
38
- */
39
- export declare function createMd(list: string[]): object[];
40
- /**
41
- * @param btn_list 按钮数组 [['第一行按钮','第一行按钮DATA'],['第二行按钮','第二行按钮DATA']]
42
- * @returns 按钮列表rows
43
- * @description 创建多行按钮
44
- */
45
- export declare function createBtn(input: string[][]): object[];
package/lib/lib.js DELETED
@@ -1,175 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkFileExists = checkFileExists;
7
- exports.getFileModifyTime = getFileModifyTime;
8
- exports.screenShot = screenShot;
9
- exports.delay = delay;
10
- exports.getFromFandom = getFromFandom;
11
- exports.createMd = createMd;
12
- exports.createBtn = createBtn;
13
- const fs_1 = __importDefault(require("fs"));
14
- /**
15
- * 检查文件是否存在
16
- * @param filePath 文件路径
17
- * @returns true:存在 false:不存在
18
- */
19
- function checkFileExists(filePath) {
20
- try {
21
- fs_1.default.accessSync(filePath, fs_1.default.constants.F_OK);
22
- return true;
23
- }
24
- catch (err) {
25
- return false;
26
- }
27
- }
28
- /**
29
- * @desc 获取文件修改时间
30
- * @param filePath 文件路径
31
- * @returns string 文件修改时间
32
- */
33
- function getFileModifyTime(filePath) {
34
- const stats = fs_1.default.statSync(filePath);
35
- const fileModifiedTime = stats.mtime.getTime();
36
- return new Date(fileModifiedTime).toLocaleDateString("zh-CN", {
37
- year: "numeric",
38
- month: "long",
39
- day: "numeric",
40
- hour: "numeric",
41
- minute: "numeric",
42
- second: "numeric",
43
- });
44
- }
45
- /**
46
- * @desc 截屏
47
- * @param url 截屏地址
48
- * @param ctx 上下文
49
- * @param config 配置
50
- * @param itemName 物品名称
51
- * @returns string
52
- */
53
- async function screenShot(url, ctx, itemName, config) {
54
- if (!url) {
55
- return false;
56
- }
57
- else {
58
- const page = await ctx.puppeteer.page();
59
- await page.goto(url, {
60
- timeout: 0,
61
- });
62
- await delay(5000);
63
- await page.addStyleTag({
64
- // 添加详情页边框
65
- content: "#mw-content-text{padding: 40px}",
66
- });
67
- await delay(3000);
68
- const selector = await page.$("#mw-content-text");
69
- await delay(2000);
70
- return await selector
71
- .screenshot({
72
- type: "jpeg",
73
- quality: 80,
74
- path: `${config.imgPath}${itemName
75
- .replace(/\//g, "-")
76
- .replace(/:/g, "-")
77
- .replace(/'/g, "-")}.jpeg`,
78
- })
79
- .then(async () => {
80
- // console.info(`截图成功...`);
81
- return true;
82
- })
83
- .catch((err) => {
84
- console.error(err);
85
- return false;
86
- })
87
- .finally(async () => {
88
- await page.close();
89
- });
90
- }
91
- }
92
- /**
93
- *
94
- * @param ms 延迟毫秒数
95
- * @returns void
96
- */
97
- async function delay(ms) {
98
- return new Promise((resolve) => setTimeout(resolve, ms));
99
- }
100
- /**
101
- * @desc 从fandom获取数据
102
- * @returns []
103
- */
104
- async function getFromFandom(url, ctx, itemName) {
105
- return await ctx.http
106
- .get(url, {
107
- headers: {
108
- "Content-Type": "application/json",
109
- "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36",
110
- },
111
- params: {
112
- action: `opensearch`,
113
- search: itemName,
114
- limit: 5,
115
- redirects: "return",
116
- format: "json",
117
- },
118
- })
119
- .then(async (res) => {
120
- console.log(res);
121
- return [res[1], res[3]];
122
- })
123
- .catch((err) => {
124
- console.error(err);
125
- return [];
126
- });
127
- }
128
- /**
129
- * @param list 传入的列表,内部元素要求为偶数个
130
- * @returns 对象列表
131
- */
132
- function createMd(list) {
133
- let res = [];
134
- for (let i = 0; i < list.length; i += 2) {
135
- res.push({
136
- key: list[i],
137
- values: [list[i + 1]],
138
- });
139
- }
140
- return res;
141
- }
142
- /**
143
- * @param btn_list 按钮数组 [['第一行按钮','第一行按钮DATA'],['第二行按钮','第二行按钮DATA']]
144
- * @returns 按钮列表rows
145
- * @description 创建多行按钮
146
- */
147
- function createBtn(input) {
148
- const rows = [];
149
- input.forEach((subList) => {
150
- const row = {
151
- buttons: [],
152
- };
153
- for (let i = 0; i < subList.length; i += 2) {
154
- const button = {
155
- id: i / 2 + 1,
156
- render_data: {
157
- label: subList[i],
158
- visited_label: subList[i],
159
- },
160
- action: {
161
- type: 2,
162
- permission: {
163
- type: 2,
164
- },
165
- unsupport_tips: "兼容文本",
166
- data: subList[i + 1],
167
- enter: true,
168
- },
169
- };
170
- row.buttons.push(button);
171
- }
172
- rows.push(row);
173
- });
174
- return rows;
175
- }