koishi-plugin-oni-wiki-qq 0.0.4 → 0.0.5
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 +11 -0
- package/lib/index.js +174 -0
- package/package.json +1 -1
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context, Schema } from "koishi";
|
|
2
|
+
export declare const name = "oni-wiki-qq";
|
|
3
|
+
export declare const inject: string[];
|
|
4
|
+
export declare const usage = "\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
|
+
export interface Config {
|
|
6
|
+
api: string;
|
|
7
|
+
imgPath: string;
|
|
8
|
+
urlPath: string;
|
|
9
|
+
}
|
|
10
|
+
export declare const Config: Schema<Config>;
|
|
11
|
+
export declare function apply(ctx: Context, config: Config): void;
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name2 in all)
|
|
10
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
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
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var src_exports = {};
|
|
32
|
+
__export(src_exports, {
|
|
33
|
+
Config: () => Config,
|
|
34
|
+
apply: () => apply,
|
|
35
|
+
inject: () => inject,
|
|
36
|
+
name: () => name,
|
|
37
|
+
usage: () => usage
|
|
38
|
+
});
|
|
39
|
+
module.exports = __toCommonJS(src_exports);
|
|
40
|
+
var import_koishi = require("koishi");
|
|
41
|
+
var import_fs = __toESM(require("fs"));
|
|
42
|
+
var import_node_os = __toESM(require("node:os"));
|
|
43
|
+
var name = "oni-wiki-qq";
|
|
44
|
+
var inject = ["puppeteer"];
|
|
45
|
+
var usage = `
|
|
46
|
+
- 0.0.5 太久没写忘记build了...
|
|
47
|
+
- 0.0.4 煞笔腾讯不给发md了艹
|
|
48
|
+
- 0.0.3 将链接改为md发送以绕过沟腾讯的链接拦截
|
|
49
|
+
- 0.0.2 基本功能完成
|
|
50
|
+
- 0.0.1 初始化,明天再慢慢写了(
|
|
51
|
+
`;
|
|
52
|
+
var Config = import_koishi.Schema.object({
|
|
53
|
+
api: import_koishi.Schema.string().default("https://oxygennotincluded.wiki.gg/zh/api.php").description("api地址"),
|
|
54
|
+
imgPath: import_koishi.Schema.string().default(import_node_os.default.homedir() + "/wikiImg/").description("图片保存路径"),
|
|
55
|
+
urlPath: import_koishi.Schema.string().description("图片公网访问路径")
|
|
56
|
+
});
|
|
57
|
+
function apply(ctx, config) {
|
|
58
|
+
const logger = ctx.logger;
|
|
59
|
+
ctx.command("t <itemName>", "查询缺氧中文wiki").alias("/查wiki").option("delete", "-d 删除本地缓存", { authority: 2 }).action(async ({ session, options }, itemName = "电解器") => {
|
|
60
|
+
logger.info(session.guildId);
|
|
61
|
+
const filePath = config.imgPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
62
|
+
const urlPath = config.urlPath + itemName.replace(/\//g, "-").replace(/:/g, "-").replace(/'/g, "-") + ".jpeg";
|
|
63
|
+
if (options.delete) {
|
|
64
|
+
if (checkFileExists(filePath)) {
|
|
65
|
+
import_fs.default.unlinkSync(filePath);
|
|
66
|
+
return `已尝试删除${itemName}的缓存...`;
|
|
67
|
+
} else {
|
|
68
|
+
return `文件不存在.请检查....`;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (checkFileExists(filePath)) {
|
|
72
|
+
return (0, import_koishi.h)("img", { src: `${urlPath}` });
|
|
73
|
+
}
|
|
74
|
+
session.send(`您查询的「${itemName}」进行中,请稍等...`);
|
|
75
|
+
await (0, import_koishi.sleep)(2e3);
|
|
76
|
+
const res = await getWiki(config.api);
|
|
77
|
+
if (res.length == 0) {
|
|
78
|
+
return `在Wiki里没找到或API查询超时或....`;
|
|
79
|
+
}
|
|
80
|
+
const title = [...res[0]];
|
|
81
|
+
let itemUrl = [...res[1]];
|
|
82
|
+
logger.info(`API返回的数据为: ${title}`);
|
|
83
|
+
if (title[0] === itemName) {
|
|
84
|
+
let res2 = await screenShot(itemUrl[0]);
|
|
85
|
+
if (res2) {
|
|
86
|
+
return (0, import_koishi.h)("img", { src: `${urlPath}` });
|
|
87
|
+
} else {
|
|
88
|
+
return `截图发生错误.请稍后重试..`;
|
|
89
|
+
}
|
|
90
|
+
} else {
|
|
91
|
+
let [one = "萌新的骨头汤", two = "托德的女装", three = "鮟鱇鱼"] = title;
|
|
92
|
+
session.send(
|
|
93
|
+
`wiki里没有找到,你可以看看底下有没有你需要的,有,回复数字序号,没有,请等待查询超时减轻服务器压力.
|
|
94
|
+
1.${one}
|
|
95
|
+
2.${two}
|
|
96
|
+
3.${three}`
|
|
97
|
+
);
|
|
98
|
+
const awlist = [1, 2, 3];
|
|
99
|
+
const awser = +(await session.prompt(50 * 1e3))?.replace(/\s+/g, "")?.slice(-1) || NaN;
|
|
100
|
+
if (awlist.includes(awser)) {
|
|
101
|
+
let res2 = await screenShot(itemUrl[awser - 1]);
|
|
102
|
+
if (res2) {
|
|
103
|
+
return (0, import_koishi.h)("img", { src: `${urlPath}` });
|
|
104
|
+
} else {
|
|
105
|
+
return `截图发生错误.请稍后重试..`;
|
|
106
|
+
}
|
|
107
|
+
} else if (Number.isNaN(awser)) {
|
|
108
|
+
return `您输入的选项有误,已完结本轮查询。如需,如有需要,请重新发起查询.`;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function getWiki(api) {
|
|
112
|
+
return await ctx.http.get(api, {
|
|
113
|
+
headers: {
|
|
114
|
+
"Content-Type": "application/json",
|
|
115
|
+
"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"
|
|
116
|
+
},
|
|
117
|
+
params: {
|
|
118
|
+
action: `opensearch`,
|
|
119
|
+
search: itemName,
|
|
120
|
+
limit: 3,
|
|
121
|
+
redirects: "return",
|
|
122
|
+
format: "json"
|
|
123
|
+
}
|
|
124
|
+
}).then(async (res2) => {
|
|
125
|
+
logger.info(res2);
|
|
126
|
+
return [res2[1], res2[3]];
|
|
127
|
+
}).catch((err) => {
|
|
128
|
+
logger.error(err);
|
|
129
|
+
return [];
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
__name(getWiki, "getWiki");
|
|
133
|
+
async function screenShot(url) {
|
|
134
|
+
const page = await ctx.puppeteer.page();
|
|
135
|
+
await page.goto(url, {
|
|
136
|
+
timeout: 0
|
|
137
|
+
});
|
|
138
|
+
await (0, import_koishi.sleep)(3e3);
|
|
139
|
+
await page.addStyleTag({
|
|
140
|
+
content: "#mw-content-text{padding: 40px}"
|
|
141
|
+
});
|
|
142
|
+
const selector = await page.$("#mw-content-text");
|
|
143
|
+
return await selector.screenshot({
|
|
144
|
+
type: "jpeg",
|
|
145
|
+
quality: 50,
|
|
146
|
+
path: filePath
|
|
147
|
+
}).then(() => {
|
|
148
|
+
return true;
|
|
149
|
+
}).catch((err) => {
|
|
150
|
+
logger.error(err);
|
|
151
|
+
return false;
|
|
152
|
+
}).finally(async () => await page.close());
|
|
153
|
+
}
|
|
154
|
+
__name(screenShot, "screenShot");
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
__name(apply, "apply");
|
|
158
|
+
function checkFileExists(filePath) {
|
|
159
|
+
try {
|
|
160
|
+
import_fs.default.accessSync(filePath, import_fs.default.constants.F_OK);
|
|
161
|
+
return true;
|
|
162
|
+
} catch (err) {
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
__name(checkFileExists, "checkFileExists");
|
|
167
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
168
|
+
0 && (module.exports = {
|
|
169
|
+
Config,
|
|
170
|
+
apply,
|
|
171
|
+
inject,
|
|
172
|
+
name,
|
|
173
|
+
usage
|
|
174
|
+
});
|