koishi-plugin-crom-querier-modified 2.0.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/graphql/index.d.ts +5 -0
- package/lib/index.d.ts +22 -0
- package/lib/index.js +389 -0
- package/lib/lib.d.ts +6 -0
- package/lib/types.d.ts +59 -0
- package/package.json +28 -0
- package/readme.md +5 -0
package/lib/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Context, Schema } from "koishi";
|
|
2
|
+
declare module "koishi" {
|
|
3
|
+
interface Tables {
|
|
4
|
+
cromQuerier: CromQuerierTable;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
interface CromQuerierTable {
|
|
8
|
+
id?: number;
|
|
9
|
+
platform: string;
|
|
10
|
+
channelId: string;
|
|
11
|
+
defaultBranch: string;
|
|
12
|
+
}
|
|
13
|
+
export declare const name: string;
|
|
14
|
+
export declare const inject: string[];
|
|
15
|
+
export interface Config {
|
|
16
|
+
bannedUsers: string[];
|
|
17
|
+
bannedTitles: string[];
|
|
18
|
+
bannedTags: string[];
|
|
19
|
+
}
|
|
20
|
+
export declare const Config: Schema<Config>;
|
|
21
|
+
export declare function apply(ctx: Context, config: Config): void;
|
|
22
|
+
export {};
|
package/lib/index.js
ADDED
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name2 in all)
|
|
8
|
+
__defProp(target, name2, { get: all[name2], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.tsx
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
Config: () => Config,
|
|
24
|
+
apply: () => apply,
|
|
25
|
+
inject: () => inject,
|
|
26
|
+
name: () => name
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(src_exports);
|
|
29
|
+
var import_koishi = require("koishi");
|
|
30
|
+
|
|
31
|
+
// src/graphql/index.ts
|
|
32
|
+
var gql = /* @__PURE__ */ __name((query, ...substitutions) => String.raw(query, ...substitutions), "gql");
|
|
33
|
+
var queries = {
|
|
34
|
+
titleQuery: gql`
|
|
35
|
+
query titleQuery($anyBaseUrl: [String], $query: String) {
|
|
36
|
+
articles(wiki: $anyBaseUrl, titleKeyword: $query, page: 1, pageSize: 10) {
|
|
37
|
+
nodes {
|
|
38
|
+
title
|
|
39
|
+
url
|
|
40
|
+
author
|
|
41
|
+
rating
|
|
42
|
+
}
|
|
43
|
+
pageInfo {
|
|
44
|
+
total
|
|
45
|
+
page
|
|
46
|
+
pageSize
|
|
47
|
+
hasNextPage
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
`,
|
|
52
|
+
userQuery: gql`
|
|
53
|
+
query userQuery($query: String!, $baseUrl: String!) {
|
|
54
|
+
authorWikiRank(
|
|
55
|
+
wiki: $baseUrl
|
|
56
|
+
name: $query
|
|
57
|
+
by: RATING
|
|
58
|
+
) {
|
|
59
|
+
rank
|
|
60
|
+
name
|
|
61
|
+
value
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
`,
|
|
65
|
+
userRankQuery: gql`
|
|
66
|
+
query userRankQuery($baseUrl: String) {
|
|
67
|
+
authorRanking(wiki: $baseUrl, by: RATING) {
|
|
68
|
+
rank
|
|
69
|
+
name
|
|
70
|
+
value
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
`
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
// src/lib.ts
|
|
77
|
+
var apiList = [
|
|
78
|
+
"https://wikit.unitreaty.org/apiv1/graphql"
|
|
79
|
+
];
|
|
80
|
+
var branchInfo = {
|
|
81
|
+
// br
|
|
82
|
+
"cn": { url: "http://backrooms-wiki-cn.wikidot.com" },
|
|
83
|
+
"en": { url: "http://backrooms-wiki.wikidot.com" },
|
|
84
|
+
"es": { url: "http://es-backrooms-wiki.wikidot.com" },
|
|
85
|
+
"fr": { url: "http://fr-backrooms-wiki.wikidot.com" },
|
|
86
|
+
"id": { url: "http://id-backrooms-wiki.wikidot.com" },
|
|
87
|
+
"jp": { url: "http://japan-backrooms-wiki.wikidot.com" },
|
|
88
|
+
"pl": { url: "http://pl-backrooms-wiki.wikidot.com" },
|
|
89
|
+
"ptbr": { url: "http://pt-br-backrooms-wiki.wikidot.com" },
|
|
90
|
+
"ru": { url: "http://ru-backrooms-wiki.wikidot.com" },
|
|
91
|
+
"vn": { url: "http://backrooms-vn.wikidot.com" },
|
|
92
|
+
"it": { url: "http://it-backrooms-wiki.wikidot.com" },
|
|
93
|
+
"de": { url: "http://de-backrooms-wiki.wikidot.com" },
|
|
94
|
+
// scp
|
|
95
|
+
"scp-cn": { url: "http://scp-wiki-cn.wikidot.com" },
|
|
96
|
+
"scp-cs": { url: "http://scp-cs.wikidot.com" },
|
|
97
|
+
"scp-de": { url: "http://scp-wiki-de.wikidot.com" },
|
|
98
|
+
"scp-en": { url: "http://scp-wiki.wikidot.com" },
|
|
99
|
+
"scp-es": { url: "http://lafundacionscp.wikidot.com" },
|
|
100
|
+
"scp-fr": { url: "http://fondationscp.wikidot.com" },
|
|
101
|
+
"scp-int": { url: "http://scp-int.wikidot.com" },
|
|
102
|
+
"scp-it": { url: "http://fondazionescp.wikidot.com" },
|
|
103
|
+
"scp-jp": { url: "http://scp-jp.wikidot.com" },
|
|
104
|
+
"scp-ko": { url: "http://scpko.wikidot.com" },
|
|
105
|
+
"scp-pl": { url: "http://scp-pl.wikidot.com" },
|
|
106
|
+
"scp-ptbr": { url: "http://scp-pt-br.wikidot.com" },
|
|
107
|
+
"scp-ru": { url: "http://scp-ru.wikidot.com" },
|
|
108
|
+
"scp-th": { url: "http://scp-th.wikidot.com" },
|
|
109
|
+
"scp-uk": { url: "http://scp-ukrainian.wikidot.com" },
|
|
110
|
+
"scp-vn": { url: "http://scp-vn.wikidot.com" },
|
|
111
|
+
"scp-el": { url: "http://scp-el.wikidot.com" },
|
|
112
|
+
"scp-id": { url: "http://scp-id.wikidot.com" },
|
|
113
|
+
// others
|
|
114
|
+
"na": { url: "http://nationarea.wikidot.com" },
|
|
115
|
+
"ci-cn": { url: "http://ci-cn-wiki.wikidot.com" },
|
|
116
|
+
// wl
|
|
117
|
+
"wl-en": { url: "http://wanderers-library.wikidot.com" },
|
|
118
|
+
"wl-pl": { url: "http://wanderers-library-pl.wikidot.com" },
|
|
119
|
+
"wl-jp": { url: "http://wanderers-library-jp.wikidot.com" },
|
|
120
|
+
"wl-cs": { url: "http://wanderers-library-cs.wikidot.com" },
|
|
121
|
+
"wl-ko": { url: "http://wanderers-library-ko.wikidot.com" },
|
|
122
|
+
"wl-vn": { url: "http://wanderers-library-vn.wikidot.com" }
|
|
123
|
+
};
|
|
124
|
+
async function cromApiRequest(titleQuery, baseUrl, endpointIndex = 0, queryString) {
|
|
125
|
+
if (endpointIndex >= apiList.length) {
|
|
126
|
+
throw new Error("所有API端点均已尝试但均失败");
|
|
127
|
+
}
|
|
128
|
+
try {
|
|
129
|
+
const response = await fetch(apiList[endpointIndex], {
|
|
130
|
+
method: "POST",
|
|
131
|
+
headers: { "Content-Type": "application/json" },
|
|
132
|
+
body: JSON.stringify({
|
|
133
|
+
query: queryString,
|
|
134
|
+
variables: {
|
|
135
|
+
query: titleQuery,
|
|
136
|
+
anyBaseUrl: baseUrl !== "" ? baseUrl : null,
|
|
137
|
+
baseUrl,
|
|
138
|
+
rank: parseInt(titleQuery.replace(/#([0-9]{1,15})/, "$1")) || 0
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
});
|
|
142
|
+
if (!response.ok) {
|
|
143
|
+
throw new Error(`请求失败,状态码: ${response.status}`);
|
|
144
|
+
}
|
|
145
|
+
const { data, errors } = await response.json();
|
|
146
|
+
if (errors && errors.length > 0) {
|
|
147
|
+
return await cromApiRequest(titleQuery, baseUrl, endpointIndex + 1, queryString);
|
|
148
|
+
}
|
|
149
|
+
return data;
|
|
150
|
+
} catch (error) {
|
|
151
|
+
if (endpointIndex < apiList.length - 1) {
|
|
152
|
+
return await cromApiRequest(titleQuery, baseUrl, endpointIndex + 1, queryString);
|
|
153
|
+
}
|
|
154
|
+
throw error;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
__name(cromApiRequest, "cromApiRequest");
|
|
158
|
+
|
|
159
|
+
// src/index.tsx
|
|
160
|
+
var import_jsx_runtime = require("@satorijs/element/jsx-runtime");
|
|
161
|
+
var name = "crom-querier";
|
|
162
|
+
var inject = ["database"];
|
|
163
|
+
var Config = import_koishi.Schema.object({
|
|
164
|
+
bannedUsers: import_koishi.Schema.array(import_koishi.Schema.string()).description("禁止查询的用户列表"),
|
|
165
|
+
bannedTitles: import_koishi.Schema.array(import_koishi.Schema.string()).description("禁止查询的文章列表"),
|
|
166
|
+
bannedTags: import_koishi.Schema.array(import_koishi.Schema.string()).description("禁止查询的标签列表")
|
|
167
|
+
}).description("禁止查询配置");
|
|
168
|
+
function apply(ctx, config) {
|
|
169
|
+
ctx.model.extend("cromQuerier", {
|
|
170
|
+
id: "unsigned",
|
|
171
|
+
platform: "string(64)",
|
|
172
|
+
channelId: "string(64)",
|
|
173
|
+
defaultBranch: "string(64)"
|
|
174
|
+
});
|
|
175
|
+
const normalizeUrl = /* @__PURE__ */ __name((url) => url.replace(/^https?:\/\/backrooms-wiki-cn.wikidot.com/, "https://brcn.backroomswiki.cn").replace(/^https?:\/\/scp-wiki-cn.wikidot.com/, "https://scpcn.backroomswiki.cn").replace(/^https?:\/\/([a-z]+-wiki-cn|nationarea)/, "https://$1"), "normalizeUrl");
|
|
176
|
+
const getBranchUrl = /* @__PURE__ */ __name(async (branch, lastStr, { platform, channel: { id: channelId } }) => {
|
|
177
|
+
const branchUrls = await ctx.database.get("cromQuerier", { platform, channelId });
|
|
178
|
+
if (Object.keys(branchInfo).includes(lastStr)) {
|
|
179
|
+
return branchInfo[lastStr].url;
|
|
180
|
+
} else if (branch && Object.keys(branchInfo).includes(branch)) {
|
|
181
|
+
return branchInfo[branch].url;
|
|
182
|
+
} else if (branchUrls.length > 0) {
|
|
183
|
+
return branchInfo[branchUrls[0].defaultBranch].url;
|
|
184
|
+
} else {
|
|
185
|
+
return branchInfo.cn.url;
|
|
186
|
+
}
|
|
187
|
+
}, "getBranchUrl");
|
|
188
|
+
ctx.command("default-branch <分部名称:string>", "设置默认分部。").alias("默认分部").alias("默认").alias("db").action(async (argv, branch) => {
|
|
189
|
+
const platform = argv.session.event.platform;
|
|
190
|
+
const channelId = argv.session.event.channel.id;
|
|
191
|
+
if (!branch || !Object.keys(branchInfo).includes(branch) || branch === "all") {
|
|
192
|
+
return "分部名称不正确。";
|
|
193
|
+
}
|
|
194
|
+
ctx.database.upsert("cromQuerier", [{ channelId, platform, defaultBranch: branch }], ["platform", "channelId"]);
|
|
195
|
+
return `已将本群默认查询分部设置为: ${branch}`;
|
|
196
|
+
});
|
|
197
|
+
ctx.command("author <作者:string> [分部名称:string]", "查询作者信息。\n默认搜索后室中文站。").alias("作者").alias("作").alias("au").action(async (argv, author, branch) => {
|
|
198
|
+
const branchUrl = await getBranchUrl(branch, argv.args.at(-1), argv.session.event);
|
|
199
|
+
const isRankQuery = /^#[0-9]{1,15}$/.test(author);
|
|
200
|
+
const queryString = isRankQuery ? queries.userRankQuery : queries.userQuery;
|
|
201
|
+
const authorName = branch && !Object.keys(branchInfo).includes(branch) || !author ? Object.keys(branchInfo).includes(argv.args.at(-1)) ? argv.args.slice(0, -1).join(" ") : argv.args.join(" ") : author;
|
|
202
|
+
const authorpageOutput = /* @__PURE__ */ __name((author2, authorInfos, branch2) => {
|
|
203
|
+
if (!authorInfos || authorInfos.length === 0) {
|
|
204
|
+
return "";
|
|
205
|
+
}
|
|
206
|
+
const filteredInfos = authorInfos.filter(
|
|
207
|
+
(info) => info.authorPage.translationOf == null && !info.authorPage.url.includes("old:") && !info.authorPage.url.includes("deleted:")
|
|
208
|
+
);
|
|
209
|
+
if (filteredInfos.length === 0) return "";
|
|
210
|
+
const matchingAuthorInfos = filteredInfos.filter(
|
|
211
|
+
(info) => info.authorPage.url.includes(author2)
|
|
212
|
+
);
|
|
213
|
+
return matchingAuthorInfos.length > 0 ? matchingAuthorInfos.find((info) => info.site === branch2)?.authorPage.url ?? matchingAuthorInfos[0]?.authorPage.url : filteredInfos.find((info) => info.site === branch2)?.authorPage.url ?? filteredInfos[0]?.authorPage.url ?? "";
|
|
214
|
+
}, "authorpageOutput");
|
|
215
|
+
const User = /* @__PURE__ */ __name(({
|
|
216
|
+
object,
|
|
217
|
+
branch: branch2,
|
|
218
|
+
isRank
|
|
219
|
+
}) => {
|
|
220
|
+
const dataArray = isRank ? object.usersByRank : object.searchUsers;
|
|
221
|
+
if (!dataArray || dataArray.length === 0) {
|
|
222
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { children: "未找到用户。" });
|
|
223
|
+
}
|
|
224
|
+
const selectedIndex = dataArray.findIndex(
|
|
225
|
+
(user2) => !config.bannedUsers.some((banned) => user2.name === banned)
|
|
226
|
+
);
|
|
227
|
+
if (selectedIndex === -1) {
|
|
228
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { children: "未找到符合条件的用户。" });
|
|
229
|
+
}
|
|
230
|
+
const user = dataArray[selectedIndex];
|
|
231
|
+
const userTotalRating = user.statistics.totalRating;
|
|
232
|
+
const userPageCount = user.statistics.pageCount;
|
|
233
|
+
const userAuthorPageUrl = normalizeUrl(authorpageOutput(user.name, user.authorInfos, branch2));
|
|
234
|
+
const averageRating = userPageCount > 0 ? (userTotalRating / userPageCount).toFixed(2) : "0.00";
|
|
235
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
236
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("quote", { id: argv.session.event.message.id }),
|
|
237
|
+
user.name,
|
|
238
|
+
" (#",
|
|
239
|
+
user.statistics.rank,
|
|
240
|
+
")",
|
|
241
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
242
|
+
"总分:",
|
|
243
|
+
userTotalRating,
|
|
244
|
+
" 总页面数:",
|
|
245
|
+
userPageCount,
|
|
246
|
+
" 平均分:",
|
|
247
|
+
averageRating,
|
|
248
|
+
userAuthorPageUrl && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
249
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
250
|
+
"作者页:",
|
|
251
|
+
userAuthorPageUrl
|
|
252
|
+
] })
|
|
253
|
+
] });
|
|
254
|
+
}, "User");
|
|
255
|
+
try {
|
|
256
|
+
const result = await cromApiRequest(authorName, branchUrl, 0, queryString);
|
|
257
|
+
const response = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(User, { object: result, branch: branchUrl, isRank: isRankQuery });
|
|
258
|
+
const sentMessages = await argv.session.send(response);
|
|
259
|
+
scheduleChecks(0, argv.session, sentMessages[0]);
|
|
260
|
+
return;
|
|
261
|
+
} catch (err) {
|
|
262
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
263
|
+
"查询失败: ",
|
|
264
|
+
err.message || "未知错误"
|
|
265
|
+
] });
|
|
266
|
+
}
|
|
267
|
+
});
|
|
268
|
+
ctx.command("search <标题:string> [分部名称:string]", "查询文章信息。\n默认搜索后室中文站。").alias("搜索").alias("搜").alias("sr").action(async (argv, title, branch) => {
|
|
269
|
+
const branchUrl = await getBranchUrl(branch, argv.args.at(-1), argv.session.event);
|
|
270
|
+
const titleName = branch && !Object.keys(branchInfo).includes(branch) || !title ? Object.keys(branchInfo).includes(argv.args.at(-1)) ? argv.args.slice(0, -1).join(" ") : argv.args.join(" ") : title;
|
|
271
|
+
const Author = /* @__PURE__ */ __name(({ article, isTranslation }) => {
|
|
272
|
+
const prefix = isTranslation ? "译者:" : "作者:";
|
|
273
|
+
if (!article.attributions) return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
274
|
+
prefix,
|
|
275
|
+
" 未知"
|
|
276
|
+
] });
|
|
277
|
+
const authors = article.attributions.map((attr) => attr.user.name).join("、");
|
|
278
|
+
if (!isTranslation) {
|
|
279
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
280
|
+
prefix,
|
|
281
|
+
authors
|
|
282
|
+
] });
|
|
283
|
+
}
|
|
284
|
+
if (!article.translationOf || !article.translationOf.attributions) {
|
|
285
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
286
|
+
prefix,
|
|
287
|
+
authors,
|
|
288
|
+
" 作者:未知"
|
|
289
|
+
] });
|
|
290
|
+
}
|
|
291
|
+
const originalAuthors = article.translationOf.attributions.map((attr) => attr.user.name).join("、");
|
|
292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
293
|
+
prefix,
|
|
294
|
+
authors,
|
|
295
|
+
" 作者:",
|
|
296
|
+
originalAuthors
|
|
297
|
+
] });
|
|
298
|
+
}, "Author");
|
|
299
|
+
const TitleProceed = /* @__PURE__ */ __name(({ titleData }) => {
|
|
300
|
+
if (!titleData.searchPages || titleData.searchPages.length === 0) {
|
|
301
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { children: "未找到文章。" });
|
|
302
|
+
}
|
|
303
|
+
const selectedIndex = titleData.searchPages.findIndex((article2) => {
|
|
304
|
+
const isBannedTitle = config.bannedTitles.includes(article2.wikidotInfo.title);
|
|
305
|
+
const isBannedUser = config.bannedUsers.some(
|
|
306
|
+
(user) => article2.attributions.some((attr) => attr.user.name === user)
|
|
307
|
+
);
|
|
308
|
+
const isBannedTag = config.bannedTags.some(
|
|
309
|
+
(tag) => article2.wikidotInfo.tags.includes(tag)
|
|
310
|
+
);
|
|
311
|
+
return !(isBannedTitle || isBannedUser || isBannedTag);
|
|
312
|
+
});
|
|
313
|
+
if (selectedIndex === -1) {
|
|
314
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("template", { children: "未找到符合条件的文章。" });
|
|
315
|
+
}
|
|
316
|
+
const article = titleData.searchPages[selectedIndex];
|
|
317
|
+
const { rating, voteCount } = article.wikidotInfo;
|
|
318
|
+
const positiveVotes = Math.round((voteCount + rating) / 2);
|
|
319
|
+
const negativeVotes = Math.round((voteCount - rating) / 2);
|
|
320
|
+
const alternateTitle = article.alternateTitles && article.alternateTitles.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
321
|
+
" - ",
|
|
322
|
+
article.alternateTitles[selectedIndex].title
|
|
323
|
+
] }) : null;
|
|
324
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
325
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("quote", { id: argv.session.event.message.id }),
|
|
326
|
+
article.wikidotInfo.title,
|
|
327
|
+
alternateTitle,
|
|
328
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
329
|
+
"评分:",
|
|
330
|
+
rating,
|
|
331
|
+
" (+",
|
|
332
|
+
positiveVotes,
|
|
333
|
+
", -",
|
|
334
|
+
negativeVotes,
|
|
335
|
+
")",
|
|
336
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
337
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Author, { article, isTranslation: Boolean(article.translationOf) }),
|
|
338
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("br", {}),
|
|
339
|
+
normalizeUrl(article.url)
|
|
340
|
+
] });
|
|
341
|
+
}, "TitleProceed");
|
|
342
|
+
try {
|
|
343
|
+
const result = await cromApiRequest(titleName, branchUrl, 0, queries.titleQuery);
|
|
344
|
+
const response = /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TitleProceed, { titleData: result });
|
|
345
|
+
const sentMessages = await argv.session.send(response);
|
|
346
|
+
scheduleChecks(0, argv.session, sentMessages[0]);
|
|
347
|
+
return;
|
|
348
|
+
} catch (err) {
|
|
349
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("template", { children: [
|
|
350
|
+
"查询失败:",
|
|
351
|
+
err.message || "未知错误"
|
|
352
|
+
] });
|
|
353
|
+
}
|
|
354
|
+
});
|
|
355
|
+
const checkTimes = [1e4, 3e4, 6e4, 9e4, 11e3, 12e3];
|
|
356
|
+
const checkAndDelete = /* @__PURE__ */ __name(async (session, sentMessage) => {
|
|
357
|
+
try {
|
|
358
|
+
const message = await session.onebot.getMsg(session.messageId);
|
|
359
|
+
if (message?.raw_message === "") {
|
|
360
|
+
await session.onebot.deleteMsg(sentMessage);
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
return false;
|
|
364
|
+
} catch (error) {
|
|
365
|
+
ctx.logger("crom-querier").warn("检测或撤回消息失败:", error);
|
|
366
|
+
return false;
|
|
367
|
+
}
|
|
368
|
+
}, "checkAndDelete");
|
|
369
|
+
const scheduleChecks = /* @__PURE__ */ __name((index, session, sentMessage) => {
|
|
370
|
+
if (index >= checkTimes.length) return;
|
|
371
|
+
ctx.setTimeout(
|
|
372
|
+
async () => {
|
|
373
|
+
const deleted = await checkAndDelete(session, sentMessage);
|
|
374
|
+
if (!deleted) {
|
|
375
|
+
scheduleChecks(index + 1, session, sentMessage);
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
index === 0 ? checkTimes[0] : checkTimes[index] - checkTimes[index - 1]
|
|
379
|
+
);
|
|
380
|
+
}, "scheduleChecks");
|
|
381
|
+
}
|
|
382
|
+
__name(apply, "apply");
|
|
383
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
384
|
+
0 && (module.exports = {
|
|
385
|
+
Config,
|
|
386
|
+
apply,
|
|
387
|
+
inject,
|
|
388
|
+
name
|
|
389
|
+
});
|
package/lib/lib.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TitleQuery, UserQuery, UserRankQuery } from "./types";
|
|
2
|
+
export declare const branchInfo: Record<string, {
|
|
3
|
+
url: string;
|
|
4
|
+
}>;
|
|
5
|
+
export declare function cromApiRequest(titleQuery: string, baseUrl: string, endpointIndex: number, queryString: string): Promise<TitleQuery & UserQuery & UserRankQuery>;
|
|
6
|
+
export declare function getBranchUrl(branch: string): string;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface UserWikidotInfo {
|
|
2
|
+
displayName: string;
|
|
3
|
+
wikidotId: number;
|
|
4
|
+
unixName: string;
|
|
5
|
+
}
|
|
6
|
+
export interface AuthorInfo {
|
|
7
|
+
site: string;
|
|
8
|
+
authorPage: {
|
|
9
|
+
translationOf: {
|
|
10
|
+
url: string;
|
|
11
|
+
} | null;
|
|
12
|
+
url: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export interface Statistics {
|
|
16
|
+
rank: number;
|
|
17
|
+
totalRating: number;
|
|
18
|
+
pageCount: number;
|
|
19
|
+
}
|
|
20
|
+
export interface User {
|
|
21
|
+
name: string;
|
|
22
|
+
wikidotInfo: UserWikidotInfo;
|
|
23
|
+
authorInfos: AuthorInfo[];
|
|
24
|
+
statistics: Statistics;
|
|
25
|
+
}
|
|
26
|
+
export interface UserQuery {
|
|
27
|
+
searchUsers: User[];
|
|
28
|
+
}
|
|
29
|
+
export interface UserRankQuery {
|
|
30
|
+
usersByRank: User[];
|
|
31
|
+
}
|
|
32
|
+
export interface Attribution {
|
|
33
|
+
user: {
|
|
34
|
+
name: string;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
interface TitleWikidotInfo {
|
|
38
|
+
title: string;
|
|
39
|
+
rating: number;
|
|
40
|
+
voteCount: number;
|
|
41
|
+
createdAt: Date;
|
|
42
|
+
tags: string[];
|
|
43
|
+
}
|
|
44
|
+
export interface Title {
|
|
45
|
+
url: string;
|
|
46
|
+
wikidotInfo: TitleWikidotInfo;
|
|
47
|
+
alternateTitles: {
|
|
48
|
+
title: string;
|
|
49
|
+
}[];
|
|
50
|
+
translationOf: {
|
|
51
|
+
url: string;
|
|
52
|
+
attributions: Attribution[];
|
|
53
|
+
} | null;
|
|
54
|
+
attributions: Attribution[];
|
|
55
|
+
}
|
|
56
|
+
export interface TitleQuery {
|
|
57
|
+
searchPages: Title[];
|
|
58
|
+
}
|
|
59
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "koishi-plugin-crom-querier-modified",
|
|
3
|
+
"description": "向crom查询并返回文本的插件,自用",
|
|
4
|
+
"version": "2.0.0",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"typings": "lib/index.d.ts",
|
|
7
|
+
"files": [
|
|
8
|
+
"lib",
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"license": "MIT",
|
|
12
|
+
"homepage": "https://github.com/WindyPear-Team/koishi-plugin-crom-querier-modified",
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/WindyPeat-Team/koishi-plugin-crom-querier-modified.git"
|
|
16
|
+
},
|
|
17
|
+
"keywords": [
|
|
18
|
+
"chatbot",
|
|
19
|
+
"koishi",
|
|
20
|
+
"plugin"
|
|
21
|
+
],
|
|
22
|
+
"peerDependencies": {
|
|
23
|
+
"koishi": "^4.18.7"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@satorijs/element": "^3.1.8"
|
|
27
|
+
}
|
|
28
|
+
}
|