koishi-plugin-oni-wiki-qq 0.2.2 → 0.3.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 +4 -12
- package/lib/index.js +45 -168
- package/package.json +1 -1
- package/lib/lib.d.ts +0 -3
package/lib/index.d.ts
CHANGED
|
@@ -1,21 +1,13 @@
|
|
|
1
1
|
import { Context, Schema } from "koishi";
|
|
2
2
|
export declare const name = "oni-wiki-qq";
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const usage = "\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 - 0.1.0 \u6DFB\u52A0\u767B\u5F55\u548C\u70B9\u51FBcookies\u6309\u94AE,\u5220\u9664\u6CA1\u6CD5\u5224\u65AD\u7B54\u6848\u7684\u4EE3\u7801\n";
|
|
3
|
+
export declare const usage = "\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.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";
|
|
5
4
|
export interface Config {
|
|
6
5
|
api: string;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
contentSelector: string;
|
|
11
|
-
loginUrl: string;
|
|
12
|
-
userNameSelector: string;
|
|
13
|
-
passwordSelector: string;
|
|
14
|
-
checkBoxSelector: string;
|
|
6
|
+
originalUrl: string;
|
|
7
|
+
mirrorUrl: string;
|
|
8
|
+
docUrl: string;
|
|
15
9
|
userName: string;
|
|
16
10
|
password: string;
|
|
17
|
-
mainPage: string;
|
|
18
|
-
btnSelector: string;
|
|
19
11
|
}
|
|
20
12
|
export declare const Config: Schema<Config>;
|
|
21
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,186 +22,74 @@ 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 = `
|
|
33
|
+
- 0.3.0 移除耗内存的截图部分,使用镜像站点网页
|
|
34
|
+
- 0.2.3 搞错了,重来
|
|
89
35
|
- 0.2.2 尝试移除顶部导航
|
|
90
36
|
- 0.2.1 交换图片和消息位置以使qq发送时在同一消息避免刷屏
|
|
91
37
|
- 0.2.0 尝试添加 MWN 库
|
|
92
|
-
- 0.1.0 添加登录和点击cookies按钮,删除没法判断答案的代码
|
|
93
38
|
`;
|
|
94
39
|
var Config = import_koishi.Schema.object({
|
|
95
40
|
api: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/api.php").description("api地址"),
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
"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"
|
|
102
|
-
),
|
|
103
|
-
userNameSelector: import_koishi.Schema.string().description("用户名输入区选择器").default("input[name='wpName']"),
|
|
104
|
-
passwordSelector: import_koishi.Schema.string().description("密码输入区选择器").default("input[name='wpPassword']"),
|
|
105
|
-
checkBoxSelector: import_koishi.Schema.string().description("总是保持登录复选框").default("inpt[name='wpRemeber']"),
|
|
106
|
-
userName: import_koishi.Schema.string().description("用户名"),
|
|
107
|
-
password: import_koishi.Schema.string().description("密码"),
|
|
108
|
-
mainPage: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/").description("主页地址"),
|
|
109
|
-
btnSelector: import_koishi.Schema.string().default(".NN0_TB_DIsNmMHgJWgT7U").description("需要点击的按钮选择器")
|
|
41
|
+
originalUrl: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/").description("原站点网址"),
|
|
42
|
+
mirrorUrl: import_koishi.Schema.string().default("https://wiki.biligame.com/oni/").description("镜像站点网址"),
|
|
43
|
+
docUrl: import_koishi.Schema.string().default("https://www.yuque.com/u25332524/ftq4u7").description("大叔的文档地址"),
|
|
44
|
+
userName: import_koishi.Schema.string().description("机器人用户名"),
|
|
45
|
+
password: import_koishi.Schema.string().description("机器人密码")
|
|
110
46
|
});
|
|
111
47
|
function apply(ctx, config) {
|
|
112
48
|
const logger = ctx.logger;
|
|
113
|
-
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").
|
|
114
|
-
const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
115
|
-
const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
116
|
-
if (options.delete) {
|
|
117
|
-
if (checkFileExists(filePath)) {
|
|
118
|
-
import_fs2.default.unlinkSync(filePath);
|
|
119
|
-
return `已尝试删除${itemName}的缓存...`;
|
|
120
|
-
} else {
|
|
121
|
-
return `文件不存在.请检查....`;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
if (checkFileExists(filePath)) {
|
|
125
|
-
return (0, import_koishi.h)(
|
|
126
|
-
"p",
|
|
127
|
-
(0, import_koishi.h)("img", { src: `${encodeURI(urlPath)}` }),
|
|
128
|
-
`图片已保存至:${encodeURI(urlPath)}`
|
|
129
|
-
);
|
|
130
|
-
}
|
|
49
|
+
ctx.command("x <itemName>", "查询缺氧中文wiki").alias("/查wiki").action(async ({ session }, itemName = "电解器") => {
|
|
131
50
|
session.send(`您查询的「${itemName}」进行中,请稍等...`);
|
|
132
|
-
const res = await getWiki(itemName
|
|
51
|
+
const res = await getWiki(itemName);
|
|
133
52
|
if (!res) {
|
|
134
53
|
return `在Wiki里没找到或API查询超时,如有需要,请按照游戏内名称重新发起查询....`;
|
|
135
54
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
} else {
|
|
144
|
-
return `截图发生错误.请稍后重试..`;
|
|
145
|
-
}
|
|
146
|
-
async function screenShot(url) {
|
|
147
|
-
const page = await ctx.puppeteer.page();
|
|
148
|
-
await page.goto(url, {
|
|
149
|
-
timeout: 0
|
|
150
|
-
});
|
|
151
|
-
await (0, import_koishi.sleep)(2e3);
|
|
152
|
-
await page.addStyleTag({
|
|
153
|
-
content: `${config.contentSelector}{padding: 40px}`
|
|
154
|
-
});
|
|
155
|
-
try {
|
|
156
|
-
await page.$eval(config.navSelector, (el) => el.remove());
|
|
157
|
-
await page.$eval("#mw-head", (el) => el.remove());
|
|
158
|
-
} catch (error) {
|
|
159
|
-
}
|
|
160
|
-
const selector = await page.$(config.contentSelector);
|
|
161
|
-
return await selector.screenshot({
|
|
162
|
-
type: "jpeg",
|
|
163
|
-
quality: 60,
|
|
164
|
-
path: filePath
|
|
165
|
-
}).then(() => {
|
|
166
|
-
return true;
|
|
167
|
-
}).catch((err) => {
|
|
168
|
-
logger.error(err);
|
|
169
|
-
return false;
|
|
170
|
-
}).finally(async () => await page.close());
|
|
171
|
-
}
|
|
172
|
-
__name(screenShot, "screenShot");
|
|
55
|
+
return `请点击连接诶前往站点查看:
|
|
56
|
+
原站点: ${encodeURI(
|
|
57
|
+
res
|
|
58
|
+
)}
|
|
59
|
+
镜像站: ${encodeURI(
|
|
60
|
+
res.replace(config.originalUrl, config.mirrorUrl)
|
|
61
|
+
)}`;
|
|
173
62
|
});
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
63
|
+
async function getWiki(itemName) {
|
|
64
|
+
const bot = await import_mwn.Mwn.init({
|
|
65
|
+
apiUrl: config.api,
|
|
66
|
+
username: config.userName,
|
|
67
|
+
password: config.password,
|
|
68
|
+
userAgent: "queryBot 0.0.3 ([[user:Charles-lf]])",
|
|
69
|
+
defaultParams: {
|
|
70
|
+
assert: "user"
|
|
71
|
+
}
|
|
181
72
|
});
|
|
182
|
-
await
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
ctx.command("
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
const selector = await page.$(config.btnSelector);
|
|
203
|
-
await (0, import_koishi.sleep)(8e3);
|
|
204
|
-
await selector.click().then(() => logger.info(`成功点击了按钮`)).catch((err) => logger.info(`出错啦,${err}`));
|
|
205
|
-
await (0, import_koishi.sleep)(8e3);
|
|
206
|
-
await page.click(`button[type="submit"]`).then(() => logger.info(`点击了按钮`)).catch((err) => logger.error(`出错了,${err}`));
|
|
207
|
-
await (0, import_koishi.sleep)(5e3);
|
|
208
|
-
session.send(
|
|
209
|
-
import_koishi.h.image(
|
|
210
|
-
await page.screenshot({ type: "jpeg", quality: 75 }),
|
|
211
|
-
"jpeg/image"
|
|
212
|
-
)
|
|
213
|
-
);
|
|
214
|
-
page.close;
|
|
73
|
+
return await bot.request({
|
|
74
|
+
action: "opensearch",
|
|
75
|
+
search: itemName,
|
|
76
|
+
namespace: "*",
|
|
77
|
+
limit: 3,
|
|
78
|
+
redirects: "return",
|
|
79
|
+
format: "json"
|
|
80
|
+
}).then(async (res) => {
|
|
81
|
+
logger.info(res);
|
|
82
|
+
if (res[1][0] == itemName) {
|
|
83
|
+
return res[3][0];
|
|
84
|
+
} else {
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
}).catch(async (err) => console.log(err));
|
|
88
|
+
}
|
|
89
|
+
__name(getWiki, "getWiki");
|
|
90
|
+
ctx.command("doc", "大叔的文档链接").alias("/大叔文档").action(async () => {
|
|
91
|
+
return `大叔的文档链接:
|
|
92
|
+
${config.docUrl}`;
|
|
215
93
|
});
|
|
216
94
|
}
|
|
217
95
|
__name(apply, "apply");
|
|
@@ -219,7 +97,6 @@ __name(apply, "apply");
|
|
|
219
97
|
0 && (module.exports = {
|
|
220
98
|
Config,
|
|
221
99
|
apply,
|
|
222
|
-
inject,
|
|
223
100
|
name,
|
|
224
101
|
usage
|
|
225
102
|
});
|
package/package.json
CHANGED
package/lib/lib.d.ts
DELETED