koishi-plugin-oni-wiki-qq 0.0.7 → 0.0.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 +1 -1
- package/lib/index.js +31 -10
- package/package.json +2 -2
package/lib/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
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.7 \u5BF9\u7F51\u5740\u8FDB\u884C\u7F16\u7801\u4EE5\u786E\u4FDD\u4E0D\u4F1A\u51FA\u73B0\u5947\u5947\u602A\u602A\u7684\u95EE\u9898\n - 0.0.6 \u7A7A\u7F51\u5740\u9519\u8BEF\u5904\u7406\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";
|
|
4
|
+
export declare const usage = "\n - 0.0.9 \u5C1D\u8BD5\u79FB\u9664\u5BFC\u822A\u6846,\u66F4\u65B0koishi\u4F9D\u8D56\n - 0.0.8 \u5BF9\u9009\u62E9\u7684\u5176\u4ED6\u9879\u8FDB\u884C\u5F31\u667A\u4E00\u6837\u7684\u5904\u7406,\u514D\u5F97 errlog \u90FD\u5FEB 13M \u4E86\n - 0.0.7 \u5BF9\u7F51\u5740\u8FDB\u884C\u7F16\u7801\u4EE5\u786E\u4FDD\u4E0D\u4F1A\u51FA\u73B0\u5947\u5947\u602A\u602A\u7684\u95EE\u9898\n - 0.0.6 \u7A7A\u7F51\u5740\u9519\u8BEF\u5904\u7406\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
6
|
api: string;
|
|
7
7
|
imgPath: string;
|
package/lib/index.js
CHANGED
|
@@ -43,6 +43,8 @@ var import_node_os = __toESM(require("node:os"));
|
|
|
43
43
|
var name = "oni-wiki-qq";
|
|
44
44
|
var inject = ["puppeteer"];
|
|
45
45
|
var usage = `
|
|
46
|
+
- 0.0.9 尝试移除导航框,更新koishi依赖
|
|
47
|
+
- 0.0.8 对选择的其他项进行弱智一样的处理,免得 errlog 都快 13M 了
|
|
46
48
|
- 0.0.7 对网址进行编码以确保不会出现奇奇怪怪的问题
|
|
47
49
|
- 0.0.6 空网址错误处理
|
|
48
50
|
- 0.0.5 太久没写忘记build了...
|
|
@@ -59,7 +61,6 @@ var Config = import_koishi.Schema.object({
|
|
|
59
61
|
function apply(ctx, config) {
|
|
60
62
|
const logger = ctx.logger;
|
|
61
63
|
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority: 2 }).action(async ({ session, options }, itemName = "电解器") => {
|
|
62
|
-
logger.info(session.guildId);
|
|
63
64
|
const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
64
65
|
const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
65
66
|
if (options.delete) {
|
|
@@ -75,7 +76,7 @@ function apply(ctx, config) {
|
|
|
75
76
|
return (0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` });
|
|
76
77
|
}
|
|
77
78
|
session.send(`您查询的「${itemName}」进行中,请稍等...`);
|
|
78
|
-
await (0, import_koishi.sleep)(
|
|
79
|
+
await (0, import_koishi.sleep)(500);
|
|
79
80
|
const res = await getWiki(config.api);
|
|
80
81
|
if (res.length == 0) {
|
|
81
82
|
return `在Wiki里没找到或API查询超时或....`;
|
|
@@ -101,14 +102,29 @@ function apply(ctx, config) {
|
|
|
101
102
|
const awlist = [1, 2, 3];
|
|
102
103
|
const awser = +(await session.prompt(50 * 1e3))?.replace(/\s+/g, "")?.slice(-1) || NaN;
|
|
103
104
|
if (awlist.includes(awser)) {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
105
|
+
switch (awlist.includes(awser)) {
|
|
106
|
+
case (one == "萌新的骨头汤" && awser == 1):
|
|
107
|
+
return (0, import_koishi.h)("img", {
|
|
108
|
+
src: `${encodeURI(config.urlPath + one)}.jpeg`
|
|
109
|
+
});
|
|
110
|
+
case (two == "" && awser == 2):
|
|
111
|
+
return (0, import_koishi.h)("img", {
|
|
112
|
+
src: `${encodeURI(config.urlPath + two)}.jpeg`
|
|
113
|
+
});
|
|
114
|
+
case (three == "" && awser == 3):
|
|
115
|
+
return (0, import_koishi.h)("img", {
|
|
116
|
+
src: `${encodeURI(config.urlPath + three)}.jpeg`
|
|
117
|
+
});
|
|
118
|
+
default:
|
|
119
|
+
let res2 = await screenShot(itemUrl[awser - 1]);
|
|
120
|
+
if (res2) {
|
|
121
|
+
return (0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` });
|
|
122
|
+
} else {
|
|
123
|
+
return `截图发生错误.请稍后重试..`;
|
|
124
|
+
}
|
|
109
125
|
}
|
|
110
126
|
} else if (Number.isNaN(awser)) {
|
|
111
|
-
return
|
|
127
|
+
return `您输入的选项有误,已完结本轮查询,如有需要,请重新发起查询.`;
|
|
112
128
|
}
|
|
113
129
|
}
|
|
114
130
|
async function getWiki(api) {
|
|
@@ -138,10 +154,15 @@ function apply(ctx, config) {
|
|
|
138
154
|
await page.goto(url, {
|
|
139
155
|
timeout: 0
|
|
140
156
|
});
|
|
141
|
-
await (0, import_koishi.sleep)(
|
|
157
|
+
await (0, import_koishi.sleep)(2e3);
|
|
142
158
|
await page.addStyleTag({
|
|
143
159
|
content: "#mw-content-text{padding: 40px}"
|
|
144
160
|
});
|
|
161
|
+
try {
|
|
162
|
+
await page.$eval(".pi-navbox", (el) => el.remove());
|
|
163
|
+
} catch (error) {
|
|
164
|
+
logger.error(error);
|
|
165
|
+
}
|
|
145
166
|
const selector = await page.$("#mw-content-text");
|
|
146
167
|
return await selector.screenshot({
|
|
147
168
|
type: "jpeg",
|
|
@@ -149,7 +170,7 @@ function apply(ctx, config) {
|
|
|
149
170
|
path: filePath
|
|
150
171
|
}).then(() => {
|
|
151
172
|
return true;
|
|
152
|
-
}).catch((err) => {
|
|
173
|
+
}).catch(async (err) => {
|
|
153
174
|
logger.error(err);
|
|
154
175
|
return false;
|
|
155
176
|
}).finally(async () => await page.close());
|
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.0.
|
|
4
|
+
"version": "0.0.9",
|
|
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.
|
|
18
|
+
"koishi": "^4.17.10"
|
|
19
19
|
}
|
|
20
20
|
}
|