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