koishi-plugin-oni-wiki-qq 0.1.1 → 0.2.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 +1 -1
- package/lib/index.js +73 -68
- package/lib/lib.d.ts +3 -0
- package/package.json +6 -3
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.1
|
|
4
|
+
export declare const usage = "\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 - 0.1.0 \u6DFB\u52A0\u767B\u5F55\u548C\u70B9\u51FBcookies\u6309\u94AE,\u5220\u9664\u6CA1\u6CD5\u5224\u65AD\u7B54\u6848\u7684\u4EE3\u7801\n";
|
|
5
5
|
export interface Config {
|
|
6
6
|
api: string;
|
|
7
7
|
imgPath: string;
|
package/lib/index.js
CHANGED
|
@@ -38,21 +38,57 @@ __export(src_exports, {
|
|
|
38
38
|
});
|
|
39
39
|
module.exports = __toCommonJS(src_exports);
|
|
40
40
|
var import_koishi = require("koishi");
|
|
41
|
-
var
|
|
41
|
+
var import_fs2 = __toESM(require("fs"));
|
|
42
42
|
var import_node_os = __toESM(require("node:os"));
|
|
43
|
+
|
|
44
|
+
// src/lib.ts
|
|
45
|
+
var import_fs = __toESM(require("fs"));
|
|
46
|
+
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
|
|
43
86
|
var name = "oni-wiki-qq";
|
|
44
87
|
var inject = ["puppeteer"];
|
|
45
88
|
var usage = `
|
|
89
|
+
- 0.2.1 交换图片和消息位置以使qq发送时在同一消息避免刷屏
|
|
90
|
+
- 0.2.0 尝试添加 MWN 库
|
|
46
91
|
- 0.1.0 添加登录和点击cookies按钮,删除没法判断答案的代码
|
|
47
|
-
- 0.0.9 尝试移除导航框,更新koishi依赖
|
|
48
|
-
- 0.0.8 对选择的其他项进行弱智一样的处理,免得 errlog 都快 13M 了
|
|
49
|
-
- 0.0.7 对网址进行编码以确保不会出现奇奇怪怪的问题
|
|
50
|
-
- 0.0.6 空网址错误处理
|
|
51
|
-
- 0.0.5 太久没写忘记build了...
|
|
52
|
-
- 0.0.4 煞笔腾讯不给发md了艹
|
|
53
|
-
- 0.0.3 将链接改为md发送以绕过沟腾讯的链接拦截
|
|
54
|
-
- 0.0.2 基本功能完成
|
|
55
|
-
- 0.0.1 初始化,明天再慢慢写了(
|
|
56
92
|
`;
|
|
57
93
|
var Config = import_koishi.Schema.object({
|
|
58
94
|
api: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/api.php").description("api地址"),
|
|
@@ -73,62 +109,39 @@ var Config = import_koishi.Schema.object({
|
|
|
73
109
|
});
|
|
74
110
|
function apply(ctx, config) {
|
|
75
111
|
const logger = ctx.logger;
|
|
76
|
-
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority:
|
|
112
|
+
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority: 1 }).action(async ({ session, options }, itemName = "电解器") => {
|
|
77
113
|
const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
78
114
|
const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
79
115
|
if (options.delete) {
|
|
80
116
|
if (checkFileExists(filePath)) {
|
|
81
|
-
|
|
117
|
+
import_fs2.default.unlinkSync(filePath);
|
|
82
118
|
return `已尝试删除${itemName}的缓存...`;
|
|
83
119
|
} else {
|
|
84
120
|
return `文件不存在.请检查....`;
|
|
85
121
|
}
|
|
86
122
|
}
|
|
87
123
|
if (checkFileExists(filePath)) {
|
|
88
|
-
|
|
89
|
-
|
|
124
|
+
return (0, import_koishi.h)(
|
|
125
|
+
"p",
|
|
126
|
+
(0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` }),
|
|
127
|
+
`图片已保存至:${encodeURI(urlPath)}`
|
|
128
|
+
);
|
|
90
129
|
}
|
|
91
130
|
session.send(`您查询的「${itemName}」进行中,请稍等...`);
|
|
92
|
-
await (
|
|
93
|
-
|
|
94
|
-
if (res.length == 0) {
|
|
131
|
+
const res = await getWiki(itemName, config);
|
|
132
|
+
if (!res) {
|
|
95
133
|
return `在Wiki里没找到或API查询超时,如有需要,请按照游戏内名称重新发起查询....`;
|
|
96
134
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} else {
|
|
105
|
-
return `截图发生错误.请稍后重试..`;
|
|
106
|
-
}
|
|
135
|
+
let screenShotRes = await screenShot(res);
|
|
136
|
+
if (screenShotRes) {
|
|
137
|
+
return (0, import_koishi.h)(
|
|
138
|
+
"p",
|
|
139
|
+
(0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` }),
|
|
140
|
+
`图片已保存至:${encodeURI(urlPath)}`
|
|
141
|
+
);
|
|
107
142
|
} else {
|
|
108
|
-
return
|
|
143
|
+
return `截图发生错误.请稍后重试..`;
|
|
109
144
|
}
|
|
110
|
-
async function getWiki(api) {
|
|
111
|
-
return await ctx.http.get(api, {
|
|
112
|
-
headers: {
|
|
113
|
-
"Content-Type": "application/json",
|
|
114
|
-
"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"
|
|
115
|
-
},
|
|
116
|
-
params: {
|
|
117
|
-
action: `opensearch`,
|
|
118
|
-
search: itemName,
|
|
119
|
-
limit: 3,
|
|
120
|
-
redirects: "return",
|
|
121
|
-
format: "json"
|
|
122
|
-
}
|
|
123
|
-
}).then(async (res2) => {
|
|
124
|
-
logger.info(res2);
|
|
125
|
-
return [res2[1], res2[3]];
|
|
126
|
-
}).catch((err) => {
|
|
127
|
-
logger.error(err);
|
|
128
|
-
return [];
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
__name(getWiki, "getWiki");
|
|
132
145
|
async function screenShot(url) {
|
|
133
146
|
const page = await ctx.puppeteer.page();
|
|
134
147
|
await page.goto(url, {
|
|
@@ -136,28 +149,29 @@ function apply(ctx, config) {
|
|
|
136
149
|
});
|
|
137
150
|
await (0, import_koishi.sleep)(2e3);
|
|
138
151
|
await page.addStyleTag({
|
|
139
|
-
content:
|
|
152
|
+
content: `${config.contentSelector}{padding: 40px}`
|
|
140
153
|
});
|
|
141
154
|
try {
|
|
142
155
|
await page.$eval(config.navSelector, (el) => el.remove());
|
|
143
156
|
} catch (error) {
|
|
144
|
-
logger.error(error);
|
|
145
157
|
}
|
|
146
158
|
const selector = await page.$(config.contentSelector);
|
|
147
159
|
return await selector.screenshot({
|
|
148
160
|
type: "jpeg",
|
|
149
|
-
quality:
|
|
161
|
+
quality: 60,
|
|
150
162
|
path: filePath
|
|
151
163
|
}).then(() => {
|
|
152
164
|
return true;
|
|
153
|
-
}).catch(
|
|
165
|
+
}).catch((err) => {
|
|
154
166
|
logger.error(err);
|
|
155
167
|
return false;
|
|
156
168
|
}).finally(async () => await page.close());
|
|
157
169
|
}
|
|
158
170
|
__name(screenShot, "screenShot");
|
|
159
171
|
});
|
|
160
|
-
ctx.command("loginwiki", "
|
|
172
|
+
ctx.command("loginwiki [BotuserName] <BotPassword>", "使用机器人账户登录", {
|
|
173
|
+
authority: 4
|
|
174
|
+
}).action(async ({ session }, BotuserName = "", BotPassword) => {
|
|
161
175
|
const page = await ctx.puppeteer.page();
|
|
162
176
|
logger.info(`正在前往登录页:${config.loginUrl}`);
|
|
163
177
|
await page.goto(config.loginUrl, {
|
|
@@ -165,10 +179,10 @@ function apply(ctx, config) {
|
|
|
165
179
|
});
|
|
166
180
|
await (0, import_koishi.sleep)(4e3);
|
|
167
181
|
logger.info(`输入用户名`);
|
|
168
|
-
await page.type(config.userNameSelector,
|
|
182
|
+
await page.type(config.userNameSelector, BotuserName);
|
|
169
183
|
await (0, import_koishi.sleep)(1e3);
|
|
170
184
|
logger.info(`输入密码`);
|
|
171
|
-
await page.type(config.passwordSelector,
|
|
185
|
+
await page.type(config.passwordSelector, BotPassword);
|
|
172
186
|
await (0, import_koishi.sleep)(1e3);
|
|
173
187
|
logger.info("点击保持登录复选框");
|
|
174
188
|
await page.click(config.checkBoxSelector);
|
|
@@ -180,7 +194,7 @@ function apply(ctx, config) {
|
|
|
180
194
|
await page.close().then(() => logger.info(`页面已经成功关闭`));
|
|
181
195
|
return `登录已完成.`;
|
|
182
196
|
});
|
|
183
|
-
ctx.command("clickBtn").action(async ({ session }) => {
|
|
197
|
+
ctx.command("clickBtn", { authority: 4 }).action(async ({ session }) => {
|
|
184
198
|
const page = await ctx.puppeteer.page();
|
|
185
199
|
await page.goto(config.mainPage, { timeout: 0 });
|
|
186
200
|
const selector = await page.$(config.btnSelector);
|
|
@@ -191,7 +205,7 @@ function apply(ctx, config) {
|
|
|
191
205
|
await (0, import_koishi.sleep)(5e3);
|
|
192
206
|
session.send(
|
|
193
207
|
import_koishi.h.image(
|
|
194
|
-
await page.screenshot({ type: "jpeg", quality:
|
|
208
|
+
await page.screenshot({ type: "jpeg", quality: 75 }),
|
|
195
209
|
"jpeg/image"
|
|
196
210
|
)
|
|
197
211
|
);
|
|
@@ -199,15 +213,6 @@ function apply(ctx, config) {
|
|
|
199
213
|
});
|
|
200
214
|
}
|
|
201
215
|
__name(apply, "apply");
|
|
202
|
-
function checkFileExists(filePath) {
|
|
203
|
-
try {
|
|
204
|
-
import_fs.default.accessSync(filePath, import_fs.default.constants.F_OK);
|
|
205
|
-
return true;
|
|
206
|
-
} catch (err) {
|
|
207
|
-
return false;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
__name(checkFileExists, "checkFileExists");
|
|
211
216
|
// Annotate the CommonJS export names for ESM import in node:
|
|
212
217
|
0 && (module.exports = {
|
|
213
218
|
Config,
|
package/lib/lib.d.ts
ADDED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-oni-wiki-qq",
|
|
3
|
-
"description": "缺氧wiki
|
|
4
|
-
"version": "0.
|
|
3
|
+
"description": "缺氧wiki查询,自用",
|
|
4
|
+
"version": "0.2.1",
|
|
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.
|
|
18
|
+
"koishi": "^4.17.12"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"mwn": "^2.0.3"
|
|
19
22
|
}
|
|
20
23
|
}
|