koishi-plugin-oni-wiki-qq 0.1.0 → 0.2.0
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 +70 -81
- 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.0 \u6DFB\u52A0\u767B\u5F55\u548C\u70B9\u51FBcookies\u6309\u94AE,\u5220\u9664\u6CA1\u6CD5\u5224\u65AD\u7B54\u6848\u7684\u4EE3\u7801\n - 0.0.9 \u5C1D\u8BD5\u79FB\u9664\u5BFC\u822A\u6846,\u66F4\u65B0koishi\u4F9D\u8D56\n
|
|
4
|
+
export declare const usage = "\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 - 0.0.9 \u5C1D\u8BD5\u79FB\u9664\u5BFC\u822A\u6846,\u66F4\u65B0koishi\u4F9D\u8D56\n";
|
|
5
5
|
export interface Config {
|
|
6
6
|
api: string;
|
|
7
7
|
imgPath: string;
|
package/lib/index.js
CHANGED
|
@@ -38,21 +38,56 @@ __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
|
+
if (res[1][0] == itemName) {
|
|
76
|
+
return res[3][0];
|
|
77
|
+
} else {
|
|
78
|
+
return "";
|
|
79
|
+
}
|
|
80
|
+
}).catch(async (err) => console.log(err));
|
|
81
|
+
}
|
|
82
|
+
__name(getWiki, "getWiki");
|
|
83
|
+
|
|
84
|
+
// src/index.ts
|
|
43
85
|
var name = "oni-wiki-qq";
|
|
44
86
|
var inject = ["puppeteer"];
|
|
45
87
|
var usage = `
|
|
88
|
+
- 0.2.0 尝试添加 MWN 库
|
|
46
89
|
- 0.1.0 添加登录和点击cookies按钮,删除没法判断答案的代码
|
|
47
90
|
- 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
91
|
`;
|
|
57
92
|
var Config = import_koishi.Schema.object({
|
|
58
93
|
api: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/api.php").description("api地址"),
|
|
@@ -73,80 +108,41 @@ var Config = import_koishi.Schema.object({
|
|
|
73
108
|
});
|
|
74
109
|
function apply(ctx, config) {
|
|
75
110
|
const logger = ctx.logger;
|
|
76
|
-
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority:
|
|
111
|
+
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority: 1 }).action(async ({ session, options }, itemName = "电解器") => {
|
|
77
112
|
const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
78
113
|
const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
79
114
|
if (options.delete) {
|
|
80
115
|
if (checkFileExists(filePath)) {
|
|
81
|
-
|
|
116
|
+
import_fs2.default.unlinkSync(filePath);
|
|
82
117
|
return `已尝试删除${itemName}的缓存...`;
|
|
83
118
|
} else {
|
|
84
119
|
return `文件不存在.请检查....`;
|
|
85
120
|
}
|
|
86
121
|
}
|
|
87
122
|
if (checkFileExists(filePath)) {
|
|
88
|
-
|
|
89
|
-
|
|
123
|
+
return (0, import_koishi.h)(
|
|
124
|
+
"p",
|
|
125
|
+
`图片已保存至:${encodeURI(urlPath)}`,
|
|
126
|
+
(0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` })
|
|
127
|
+
);
|
|
90
128
|
}
|
|
91
129
|
session.send(`您查询的「${itemName}」进行中,请稍等...`);
|
|
92
130
|
await (0, import_koishi.sleep)(500);
|
|
93
|
-
const res = await getWiki(config
|
|
94
|
-
if (res
|
|
95
|
-
return `在Wiki里没找到或API
|
|
131
|
+
const res = await getWiki(itemName, config);
|
|
132
|
+
if (!res) {
|
|
133
|
+
return `在Wiki里没找到或API查询超时,如有需要,请按照游戏内名称重新发起查询....`;
|
|
96
134
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
} else {
|
|
105
|
-
return `截图发生错误.请稍后重试..`;
|
|
106
|
-
}
|
|
107
|
-
} else {
|
|
108
|
-
let [one = "萌新的骨头汤", two = "托德的女装", three = "鮟鱇鱼"] = title;
|
|
109
|
-
session.send(
|
|
110
|
-
`wiki里没有找到,你可以看看底下有没有你需要的,有,回复数字序号,没有,请等待查询超时减轻服务器压力.
|
|
111
|
-
1.${one}
|
|
112
|
-
2.${two}
|
|
113
|
-
3.${three}`
|
|
135
|
+
let screenShotRes = await screenShot(res);
|
|
136
|
+
logger.info(`API返回的数据为: ${screenShotRes}`);
|
|
137
|
+
if (screenShotRes) {
|
|
138
|
+
return (0, import_koishi.h)(
|
|
139
|
+
"p",
|
|
140
|
+
`图片已保存至:${encodeURI(urlPath)}`,
|
|
141
|
+
(0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` })
|
|
114
142
|
);
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
if (awlist.includes(awser)) {
|
|
118
|
-
let res2 = await screenShot(itemUrl[awser - 1]);
|
|
119
|
-
if (res2) {
|
|
120
|
-
return (0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` });
|
|
121
|
-
} else {
|
|
122
|
-
return `截图发生错误.请稍后重试..`;
|
|
123
|
-
}
|
|
124
|
-
} else if (Number.isNaN(awser)) {
|
|
125
|
-
return `您输入的选项有误,已完结本轮查询,如有需要,请重新发起查询.`;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
async function getWiki(api) {
|
|
129
|
-
return await ctx.http.get(api, {
|
|
130
|
-
headers: {
|
|
131
|
-
"Content-Type": "application/json",
|
|
132
|
-
"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"
|
|
133
|
-
},
|
|
134
|
-
params: {
|
|
135
|
-
action: `opensearch`,
|
|
136
|
-
search: itemName,
|
|
137
|
-
limit: 3,
|
|
138
|
-
redirects: "return",
|
|
139
|
-
format: "json"
|
|
140
|
-
}
|
|
141
|
-
}).then(async (res2) => {
|
|
142
|
-
logger.info(res2);
|
|
143
|
-
return [res2[1], res2[3]];
|
|
144
|
-
}).catch((err) => {
|
|
145
|
-
logger.error(err);
|
|
146
|
-
return [];
|
|
147
|
-
});
|
|
143
|
+
} else {
|
|
144
|
+
return `截图发生错误.请稍后重试..`;
|
|
148
145
|
}
|
|
149
|
-
__name(getWiki, "getWiki");
|
|
150
146
|
async function screenShot(url) {
|
|
151
147
|
const page = await ctx.puppeteer.page();
|
|
152
148
|
await page.goto(url, {
|
|
@@ -154,7 +150,7 @@ function apply(ctx, config) {
|
|
|
154
150
|
});
|
|
155
151
|
await (0, import_koishi.sleep)(2e3);
|
|
156
152
|
await page.addStyleTag({
|
|
157
|
-
content:
|
|
153
|
+
content: `${config.contentSelector}{padding: 40px}`
|
|
158
154
|
});
|
|
159
155
|
try {
|
|
160
156
|
await page.$eval(config.navSelector, (el) => el.remove());
|
|
@@ -175,7 +171,9 @@ function apply(ctx, config) {
|
|
|
175
171
|
}
|
|
176
172
|
__name(screenShot, "screenShot");
|
|
177
173
|
});
|
|
178
|
-
ctx.command("loginwiki", "
|
|
174
|
+
ctx.command("loginwiki [BotuserName] <BotPassword>", "使用机器人账户登录", {
|
|
175
|
+
authority: 4
|
|
176
|
+
}).action(async ({ session }, BotuserName = "", BotPassword) => {
|
|
179
177
|
const page = await ctx.puppeteer.page();
|
|
180
178
|
logger.info(`正在前往登录页:${config.loginUrl}`);
|
|
181
179
|
await page.goto(config.loginUrl, {
|
|
@@ -183,10 +181,10 @@ function apply(ctx, config) {
|
|
|
183
181
|
});
|
|
184
182
|
await (0, import_koishi.sleep)(4e3);
|
|
185
183
|
logger.info(`输入用户名`);
|
|
186
|
-
await page.type(config.userNameSelector,
|
|
184
|
+
await page.type(config.userNameSelector, BotuserName);
|
|
187
185
|
await (0, import_koishi.sleep)(1e3);
|
|
188
186
|
logger.info(`输入密码`);
|
|
189
|
-
await page.type(config.passwordSelector,
|
|
187
|
+
await page.type(config.passwordSelector, BotPassword);
|
|
190
188
|
await (0, import_koishi.sleep)(1e3);
|
|
191
189
|
logger.info("点击保持登录复选框");
|
|
192
190
|
await page.click(config.checkBoxSelector);
|
|
@@ -198,7 +196,7 @@ function apply(ctx, config) {
|
|
|
198
196
|
await page.close().then(() => logger.info(`页面已经成功关闭`));
|
|
199
197
|
return `登录已完成.`;
|
|
200
198
|
});
|
|
201
|
-
ctx.command("clickBtn").action(async ({ session }) => {
|
|
199
|
+
ctx.command("clickBtn", { authority: 4 }).action(async ({ session }) => {
|
|
202
200
|
const page = await ctx.puppeteer.page();
|
|
203
201
|
await page.goto(config.mainPage, { timeout: 0 });
|
|
204
202
|
const selector = await page.$(config.btnSelector);
|
|
@@ -217,15 +215,6 @@ function apply(ctx, config) {
|
|
|
217
215
|
});
|
|
218
216
|
}
|
|
219
217
|
__name(apply, "apply");
|
|
220
|
-
function checkFileExists(filePath) {
|
|
221
|
-
try {
|
|
222
|
-
import_fs.default.accessSync(filePath, import_fs.default.constants.F_OK);
|
|
223
|
-
return true;
|
|
224
|
-
} catch (err) {
|
|
225
|
-
return false;
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
__name(checkFileExists, "checkFileExists");
|
|
229
218
|
// Annotate the CommonJS export names for ESM import in node:
|
|
230
219
|
0 && (module.exports = {
|
|
231
220
|
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.0",
|
|
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
|
}
|