koishi-plugin-bilibili-notify 3.2.4 → 3.2.5-alpha.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.
Files changed (62) hide show
  1. package/lib/biliAPI-BB6Ih4EM.mjs +659 -0
  2. package/lib/biliAPI-GF2e2-2V.js +664 -0
  3. package/lib/biliAPI.d.mts +82 -0
  4. package/lib/biliAPI.d.ts +75 -70
  5. package/lib/biliAPI.js +5 -762
  6. package/lib/biliAPI.mjs +4 -0
  7. package/lib/blive-BBVUYbxX.js +43 -0
  8. package/lib/blive-CyC_0-9A.mjs +37 -0
  9. package/lib/blive.d.mts +19 -0
  10. package/lib/blive.d.ts +15 -12
  11. package/lib/blive.js +4 -59
  12. package/lib/blive.mjs +3 -0
  13. package/lib/chunk-CrFLpmCJ.js +67 -0
  14. package/lib/chunk-DBmNgn_A.mjs +40 -0
  15. package/lib/comRegister-CcqOpkwB.mjs +1421 -0
  16. package/lib/comRegister-t7UnYFig.js +1426 -0
  17. package/lib/comRegister.d.mts +109 -0
  18. package/lib/comRegister.d.ts +103 -100
  19. package/lib/comRegister.js +6 -1896
  20. package/lib/comRegister.mjs +5 -0
  21. package/lib/database-4f9U--Ji.mjs +20 -0
  22. package/lib/database-Ct2yIdxk.js +37 -0
  23. package/lib/database-Do3O9MDA.d.mts +18 -0
  24. package/lib/database-KWDs372o.d.ts +18 -0
  25. package/lib/database.d.mts +2 -0
  26. package/lib/database.d.ts +2 -14
  27. package/lib/database.js +5 -14
  28. package/lib/database.mjs +3 -0
  29. package/lib/font/HYZhengYuan-75W.js +5 -0
  30. package/lib/font/HYZhengYuan-75W.mjs +5 -0
  31. package/lib/generateImg-E9JeFpQX.js +92628 -0
  32. package/lib/generateImg-zwzMYjw6.mjs +92623 -0
  33. package/lib/generateImg.d.mts +65 -0
  34. package/lib/generateImg.d.ts +59 -46
  35. package/lib/generateImg.js +4 -1504
  36. package/lib/generateImg.mjs +4 -0
  37. package/lib/img/arrow.js +5 -0
  38. package/lib/img/arrow.mjs +5 -0
  39. package/lib/index-DeGUe4jM.d.mts +265 -0
  40. package/lib/index-MJKYbMf7.d.ts +265 -0
  41. package/lib/index.d.mts +73 -0
  42. package/lib/index.d.ts +65 -62
  43. package/lib/index.js +296 -394
  44. package/lib/index.mjs +300 -0
  45. package/lib/page/0.mjs +0 -0
  46. package/lib/type/index.d.mts +2 -0
  47. package/lib/type/index.d.ts +2 -262
  48. package/lib/type/index.js +5 -18
  49. package/lib/type/index.mjs +3 -0
  50. package/lib/type-C5ZxPrgY.mjs +19 -0
  51. package/lib/type-WjCy4YMc.js +31 -0
  52. package/lib/utils/index.d.mts +15 -0
  53. package/lib/utils/index.d.ts +8 -6
  54. package/lib/utils/index.js +6 -102
  55. package/lib/utils/index.mjs +3 -0
  56. package/lib/utils-BoaYrSvG.js +79 -0
  57. package/lib/utils-C95cnBJG.mjs +61 -0
  58. package/package.json +16 -11
  59. package/readme.md +12 -2
  60. package/lib/img/arrow.png +0 -0
  61. /package/lib/{font/HYZhengYuan-75W.ttf → assets/HYZhengYuan-75W-CAgMN3FH.ttf} +0 -0
  62. /package/lib/page/{0.html → 0.js} +0 -0
@@ -0,0 +1,1426 @@
1
+ const require_chunk = require('./chunk-CrFLpmCJ.js');
2
+ const require_utils = require('./utils-BoaYrSvG.js');
3
+ const require_type = require('./type-WjCy4YMc.js');
4
+ const koishi = require_chunk.__toESM(require("koishi"));
5
+ const qrcode = require_chunk.__toESM(require("qrcode"));
6
+ const cron = require_chunk.__toESM(require("cron"));
7
+ const luxon = require_chunk.__toESM(require("luxon"));
8
+ const __satorijs_element_jsx_runtime = require_chunk.__toESM(require("@satorijs/element/jsx-runtime"));
9
+
10
+ //#region node_modules/@koishijs/plugin-help/lib/index.js
11
+ var require_lib = require_chunk.__commonJS({ "node_modules/@koishijs/plugin-help/lib/index.js"(exports, module) {
12
+ var __defProp = Object.defineProperty;
13
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
14
+ var __getOwnPropNames = Object.getOwnPropertyNames;
15
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
16
+ var __name = (target, value) => __defProp(target, "name", {
17
+ value,
18
+ configurable: true
19
+ });
20
+ var __export = (target, all) => {
21
+ for (var name2 in all) __defProp(target, name2, {
22
+ get: all[name2],
23
+ enumerable: true
24
+ });
25
+ };
26
+ var __copyProps = (to, from, except, desc) => {
27
+ if (from && typeof from === "object" || typeof from === "function") {
28
+ for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
29
+ get: () => from[key],
30
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
31
+ });
32
+ }
33
+ return to;
34
+ };
35
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
36
+ var src_exports = {};
37
+ __export(src_exports, {
38
+ Config: () => Config,
39
+ apply: () => apply,
40
+ name: () => name
41
+ });
42
+ module.exports = __toCommonJS(src_exports);
43
+ var import_koishi = require("koishi");
44
+ var zh_CN_default = { commands: { help: {
45
+ description: "显示帮助信息",
46
+ shortcuts: { help: "帮助" },
47
+ options: {
48
+ help: "显示此信息",
49
+ authority: "显示权限设置",
50
+ showHidden: "查看隐藏的选项和指令"
51
+ },
52
+ messages: {
53
+ "not-found": "指令未找到。",
54
+ "hint-authority": "括号内为对应的最低权限等级",
55
+ "hint-subcommand": "标有星号的表示含有子指令",
56
+ "command-title": "指令:{0}",
57
+ "command-aliases": "别名:{0}。",
58
+ "command-examples": "使用示例:",
59
+ "command-authority": "最低权限:{0} 级。",
60
+ "subcommand-prolog": "可用的子指令有{0}:",
61
+ "global-prolog": "当前可用的指令有{0}:",
62
+ "global-epilog": "输入“{0}help 指令名”查看特定指令的语法和使用示例。",
63
+ "available-options": "可用的选项有:",
64
+ "available-options-with-authority": "可用的选项有(括号内为额外要求的权限等级):"
65
+ }
66
+ } } };
67
+ var en_US_default = { commands: { help: {
68
+ description: "Show help",
69
+ shortcuts: { help: "<></>" },
70
+ options: {
71
+ help: "show this message",
72
+ authority: "show authority requirements",
73
+ showHidden: "show hidden options and commands"
74
+ },
75
+ messages: {
76
+ "not-found": "Command not found.",
77
+ "hint-authority": "this minimum authority is marked in parentheses",
78
+ "hint-subcommand": "those marked with an asterisk have subcommands",
79
+ "command-title": "Command: {0}",
80
+ "command-aliases": "Aliases: {0}.",
81
+ "command-examples": "Examples:",
82
+ "command-authority": "Minimal authority: {0}.",
83
+ "subcommand-prolog": "Available subcommands{0}:",
84
+ "global-prolog": "Available commands{0}:",
85
+ "global-epilog": "Type \"{0}help <command>\" to see syntax and examples for a specific command.",
86
+ "available-options": "Available options:",
87
+ "available-options-with-authority": "Available options (parentheses indicate additional authority requirement):"
88
+ }
89
+ } } };
90
+ var Config = import_koishi.Schema.object({
91
+ shortcut: import_koishi.Schema.boolean().default(true).description("是否启用快捷调用。"),
92
+ options: import_koishi.Schema.boolean().default(true).description("是否为每个指令添加 `-h, --help` 选项。")
93
+ });
94
+ function executeHelp(session, name2) {
95
+ if (!session.app.$commander.get("help")) return;
96
+ return session.execute({
97
+ name: "help",
98
+ args: [name2]
99
+ });
100
+ }
101
+ __name(executeHelp, "executeHelp");
102
+ var name = "help";
103
+ function apply(ctx, config) {
104
+ ctx.i18n.define("zh-CN", zh_CN_default);
105
+ ctx.i18n.define("en-US", en_US_default);
106
+ function enableHelp(command) {
107
+ command[import_koishi.Context.current] = ctx;
108
+ command.option("help", "-h", {
109
+ hidden: true,
110
+ notUsage: true,
111
+ descPath: "commands.help.options.help"
112
+ });
113
+ }
114
+ __name(enableHelp, "enableHelp");
115
+ ctx.schema.extend("command", import_koishi.Schema.object({
116
+ hideOptions: import_koishi.Schema.boolean().description("是否隐藏所有选项。").default(false).hidden(),
117
+ hidden: import_koishi.Schema.computed(import_koishi.Schema.boolean()).description("在帮助菜单中隐藏指令。").default(false),
118
+ params: import_koishi.Schema.any().description("帮助信息的本地化参数。").hidden()
119
+ }), 900);
120
+ ctx.schema.extend("command-option", import_koishi.Schema.object({
121
+ hidden: import_koishi.Schema.computed(import_koishi.Schema.boolean()).description("在帮助菜单中隐藏选项。").default(false),
122
+ params: import_koishi.Schema.any().description("帮助信息的本地化参数。").hidden()
123
+ }), 900);
124
+ if (config.options !== false) {
125
+ ctx.$commander._commandList.forEach(enableHelp);
126
+ ctx.on("command-added", enableHelp);
127
+ }
128
+ ctx.before("command/execute", (argv) => {
129
+ const { command, options, session } = argv;
130
+ if (options["help"] && command._options.help) return executeHelp(session, command.name);
131
+ if (command["_actions"].length) return;
132
+ return executeHelp(session, command.name);
133
+ });
134
+ const $ = ctx.$commander;
135
+ function findCommand(target, session) {
136
+ const command = $.resolve(target, session);
137
+ if (command?.ctx.filter(session)) return command;
138
+ const data = ctx.i18n.find("commands.(name).shortcuts.(variant)", target).map((item) => ({
139
+ ...item,
140
+ command: $.resolve(item.data.name, session)
141
+ })).filter((item) => item.command?.match(session));
142
+ const perfect = data.filter((item) => item.similarity === 1);
143
+ if (!perfect.length) return data;
144
+ return perfect[0].command;
145
+ }
146
+ __name(findCommand, "findCommand");
147
+ const createCollector = /* @__PURE__ */ __name((key) => (argv, fields) => {
148
+ const { args: [target], session } = argv;
149
+ const result = findCommand(target, session);
150
+ if (!Array.isArray(result)) {
151
+ session.collect(key, {
152
+ ...argv,
153
+ command: result,
154
+ args: [],
155
+ options: { help: true }
156
+ }, fields);
157
+ return;
158
+ }
159
+ for (const { command } of result) session.collect(key, {
160
+ ...argv,
161
+ command,
162
+ args: [],
163
+ options: { help: true }
164
+ }, fields);
165
+ }, "createCollector");
166
+ async function inferCommand(target, session) {
167
+ const result = findCommand(target, session);
168
+ if (!Array.isArray(result)) return result;
169
+ const expect = $.available(session).filter((name3) => {
170
+ return name3 && session.app.i18n.compare(name3, target);
171
+ });
172
+ for (const item of result) {
173
+ if (expect.includes(item.data.name)) continue;
174
+ expect.push(item.data.name);
175
+ }
176
+ const cache = /* @__PURE__ */ new Map();
177
+ const name2 = await session.suggest({
178
+ expect,
179
+ prefix: session.text(".not-found"),
180
+ suffix: session.text("internal.suggest-command"),
181
+ filter: /* @__PURE__ */ __name((name3) => {
182
+ const command = $.resolve(name3, session);
183
+ if (!command) return false;
184
+ return ctx.permissions.test(`command:${command.name}`, session, cache);
185
+ }, "filter")
186
+ });
187
+ return $.resolve(name2, session);
188
+ }
189
+ __name(inferCommand, "inferCommand");
190
+ const cmd = ctx.command("help [command:string]", {
191
+ authority: 0,
192
+ ...config
193
+ }).userFields(["authority"]).userFields(createCollector("user")).channelFields(createCollector("channel")).option("showHidden", "-H").action(async ({ session, options }, target) => {
194
+ if (!target) {
195
+ const prefix = session.resolve(session.app.koishi.config.prefix)[0] ?? "";
196
+ const commands = $._commandList.filter((cmd2) => cmd2.parent === null);
197
+ const output = await formatCommands(".global-prolog", session, commands, options);
198
+ const epilog = session.text(".global-epilog", [prefix]);
199
+ if (epilog) output.push(epilog);
200
+ return output.filter(Boolean).join("\n");
201
+ }
202
+ const command = await inferCommand(target, session);
203
+ if (!command) return;
204
+ if (!await ctx.permissions.test(`command:${command.name}`, session)) return session.text("internal.low-authority");
205
+ return showHelp(command, session, options);
206
+ });
207
+ if (config.shortcut !== false) cmd.shortcut("help", {
208
+ i18n: true,
209
+ fuzzy: true
210
+ });
211
+ }
212
+ __name(apply, "apply");
213
+ function* getCommands(session, commands, showHidden = false) {
214
+ for (const command of commands) {
215
+ if (!showHidden && session.resolve(command.config.hidden)) continue;
216
+ if (command.match(session) && Object.keys(command._aliases).length) yield command;
217
+ else yield* getCommands(session, command.children, showHidden);
218
+ }
219
+ }
220
+ __name(getCommands, "getCommands");
221
+ async function formatCommands(path, session, children, options) {
222
+ const cache = /* @__PURE__ */ new Map();
223
+ children = Array.from(getCommands(session, children, options.showHidden));
224
+ children = (await Promise.all(children.map(async (command) => {
225
+ return [command, await session.app.permissions.test(`command:${command.name}`, session, cache)];
226
+ }))).filter(([, result]) => result).map(([command]) => command);
227
+ children.sort((a, b) => a.displayName > b.displayName ? 1 : -1);
228
+ if (!children.length) return [];
229
+ const prefix = session.resolve(session.app.koishi.config.prefix)[0] ?? "";
230
+ const output = children.map(({ name: name2, displayName, config }) => {
231
+ let output2 = " " + prefix + displayName.replace(/\./g, " ");
232
+ output2 += " " + session.text([`commands.${name2}.description`, ""], config.params);
233
+ return output2;
234
+ });
235
+ const hints = [];
236
+ const hintText = hints.length ? session.text("general.paren", [hints.join(session.text("general.comma"))]) : "";
237
+ output.unshift(session.text(path, [hintText]));
238
+ return output;
239
+ }
240
+ __name(formatCommands, "formatCommands");
241
+ function getOptionVisibility(option, session) {
242
+ if (session.user && option.authority > session.user.authority) return false;
243
+ return !session.resolve(option.hidden);
244
+ }
245
+ __name(getOptionVisibility, "getOptionVisibility");
246
+ function getOptions(command, session, config) {
247
+ if (command.config.hideOptions && !config.showHidden) return [];
248
+ const options = config.showHidden ? Object.values(command._options) : Object.values(command._options).filter((option) => getOptionVisibility(option, session));
249
+ if (!options.length) return [];
250
+ const output = [];
251
+ Object.values(command._options).forEach((option) => {
252
+ function pushOption(option2, name2) {
253
+ if (!config.showHidden && !getOptionVisibility(option2, session)) return;
254
+ let line = `${import_koishi.h.escape(option2.syntax)}`;
255
+ const description = session.text(option2.descPath ?? [`commands.${command.name}.options.${name2}`, ""], option2.params);
256
+ if (description) line += " " + description;
257
+ line = command.ctx.chain("help/option", line, option2, command, session);
258
+ output.push(" " + line);
259
+ }
260
+ __name(pushOption, "pushOption");
261
+ if (!("value" in option)) pushOption(option, option.name);
262
+ for (const value in option.variants) pushOption(option.variants[value], `${option.name}.${value}`);
263
+ });
264
+ if (!output.length) return [];
265
+ output.unshift(session.text(".available-options"));
266
+ return output;
267
+ }
268
+ __name(getOptions, "getOptions");
269
+ async function showHelp(command, session, config) {
270
+ const output = [session.text(".command-title", [command.displayName.replace(/\./g, " ") + command.declaration])];
271
+ const description = session.text([`commands.${command.name}.description`, ""], command.config.params);
272
+ if (description) output.push(description);
273
+ if (session.app.database) {
274
+ const argv = {
275
+ command,
276
+ args: [],
277
+ options: { help: true }
278
+ };
279
+ const userFields = session.collect("user", argv);
280
+ await session.observeUser(userFields);
281
+ if (!session.isDirect) {
282
+ const channelFields = session.collect("channel", argv);
283
+ await session.observeChannel(channelFields);
284
+ }
285
+ }
286
+ if (Object.keys(command._aliases).length > 1) output.push(session.text(".command-aliases", [Array.from(Object.keys(command._aliases).slice(1)).join(",")]));
287
+ session.app.emit(session, "help/command", output, command, session);
288
+ if (command._usage) output.push(typeof command._usage === "string" ? command._usage : await command._usage(session));
289
+ else {
290
+ const text = session.text([`commands.${command.name}.usage`, ""], command.config.params);
291
+ if (text) output.push(text);
292
+ }
293
+ output.push(...getOptions(command, session, config));
294
+ if (command._examples.length) output.push(session.text(".command-examples"), ...command._examples.map((example) => " " + example));
295
+ else {
296
+ const text = session.text([`commands.${command.name}.examples`, ""], command.config.params);
297
+ if (text) output.push(...text.split("\n").map((line) => " " + line));
298
+ }
299
+ output.push(...await formatCommands(".subcommand-prolog", session, command.children, config));
300
+ return output.filter(Boolean).join("\n");
301
+ }
302
+ __name(showHelp, "showHelp");
303
+ } });
304
+
305
+ //#endregion
306
+ //#region src/comRegister.tsx
307
+ var import_lib = require_chunk.__toESM(require_lib());
308
+ var ComRegister = class {
309
+ static inject = [
310
+ "ba",
311
+ "gi",
312
+ "database",
313
+ "bl",
314
+ "sm"
315
+ ];
316
+ qqRelatedBotList = [
317
+ "qq",
318
+ "onebot",
319
+ "red",
320
+ "satori",
321
+ "chronocat"
322
+ ];
323
+ logger;
324
+ config;
325
+ loginTimer;
326
+ num = 0;
327
+ rebootCount = 0;
328
+ subNotifier;
329
+ ctx;
330
+ subManager = [];
331
+ dynamicTimelineManager = /* @__PURE__ */ new Map();
332
+ liveStatusManager = /* @__PURE__ */ new Map();
333
+ loginDBData;
334
+ privateBot;
335
+ dynamicJob;
336
+ liveJob;
337
+ constructor(ctx, config) {
338
+ this.ctx = ctx;
339
+ this.init(config);
340
+ const statusCom = ctx.command("status", "插件状态相关指令", { permissions: ["authority:5"] });
341
+ statusCom.subcommand(".dyn", "查看动态监测运行状态").usage("查看动态监测运行状态").example("status dyn").action(() => {
342
+ if (this.dynamicJob?.isActive) return "动态监测正在运行";
343
+ return "动态监测未运行";
344
+ });
345
+ statusCom.subcommand(".sm", "查看订阅管理对象").usage("查看订阅管理对象").example("status sm").action(async () => {
346
+ this.logger.info(this.subManager);
347
+ return "查看控制台";
348
+ });
349
+ statusCom.subcommand(".bot", "查询当前拥有的机器人信息", { hidden: true }).usage("查询当前拥有的机器人信息").example("status bot 查询当前拥有的机器人信息").action(() => {
350
+ this.logger.info("开始输出BOT信息");
351
+ for (const bot of ctx.bots) {
352
+ this.logger.info("--------------------------------");
353
+ this.logger.info(`平台:${bot.platform}`);
354
+ this.logger.info(`名称:${bot.user.name}`);
355
+ this.logger.info("--------------------------------");
356
+ }
357
+ });
358
+ statusCom.subcommand(".env", "查询当前环境的信息", { hidden: true }).usage("查询当前环境的信息").example("status env 查询当前环境的信息").action(async ({ session }) => {
359
+ await session.send(`Guild ID:${session.event.guild.id}`);
360
+ await session.send(`Channel ID: ${session.event.channel.id}`);
361
+ });
362
+ const biliCom = ctx.command("bili", "bili-notify插件相关指令", { permissions: ["authority:3"] });
363
+ biliCom.subcommand(".login", "登录B站之后才可以进行之后的操作").usage("使用二维码登录,登录B站之后才可以进行之后的操作").example("bili login").action(async ({ session }) => {
364
+ this.logger.info("调用bili login指令");
365
+ let content;
366
+ try {
367
+ content = await ctx.ba.getLoginQRCode();
368
+ } catch (e) {
369
+ return "bili login getLoginQRCode() 本次网络请求失败";
370
+ }
371
+ if (content.code !== 0) return await session.send("出问题咯,请联系管理员解决");
372
+ qrcode.default.toBuffer(content.data.url, {
373
+ errorCorrectionLevel: "H",
374
+ type: "png",
375
+ margin: 1,
376
+ color: {
377
+ dark: "#000000",
378
+ light: "#FFFFFF"
379
+ }
380
+ }, async (err, buffer) => {
381
+ if (err) return await session.send("二维码生成出错,请重新尝试");
382
+ await session.send(koishi.h.image(buffer, "image/jpeg"));
383
+ });
384
+ if (this.loginTimer) this.loginTimer();
385
+ let flag = true;
386
+ this.loginTimer = ctx.setInterval(async () => {
387
+ try {
388
+ if (!flag) return;
389
+ flag = false;
390
+ let loginContent;
391
+ try {
392
+ loginContent = await ctx.ba.getLoginStatus(content.data.qrcode_key);
393
+ } catch (e) {
394
+ this.logger.error(e);
395
+ return;
396
+ }
397
+ if (loginContent.code !== 0) {
398
+ this.loginTimer();
399
+ return await session.send("登录失败请重试");
400
+ }
401
+ if (loginContent.data.code === 86038) {
402
+ this.loginTimer();
403
+ return await session.send("二维码已失效,请重新登录");
404
+ }
405
+ if (loginContent.data.code === 0) {
406
+ const encryptedCookies = ctx.ba.encrypt(ctx.ba.getCookies());
407
+ const encryptedRefreshToken = ctx.ba.encrypt(loginContent.data.refresh_token);
408
+ await ctx.database.upsert("loginBili", [{
409
+ id: 1,
410
+ bili_cookies: encryptedCookies,
411
+ bili_refresh_token: encryptedRefreshToken
412
+ }]);
413
+ this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
414
+ await this.ctx.ba.loadCookiesFromDatabase();
415
+ await this.checkIfLoginInfoIsLoaded();
416
+ this.loginTimer();
417
+ const { code, msg } = await this.loadSubFromConfig(config.sub);
418
+ if (code !== 0) this.logger.error(msg);
419
+ ctx.ba.disposeNotifier();
420
+ await session.send("登录成功");
421
+ await session.execute("bili list");
422
+ ctx.ba.enableRefreshCookiesDetect();
423
+ }
424
+ } finally {
425
+ flag = true;
426
+ }
427
+ }, 1e3);
428
+ });
429
+ biliCom.subcommand(".list", "展示订阅对象").usage("展示订阅对象").example("bili list").action(() => {
430
+ const subTable = this.subShow();
431
+ return subTable;
432
+ });
433
+ biliCom.subcommand(".private", "向主人账号发送一条测试消息", { hidden: true }).usage("向主人账号发送一条测试消息").example("bili private 向主人账号发送一条测试消息").action(async ({ session }) => {
434
+ await this.sendPrivateMsg("Hello World");
435
+ await session.send("已发送消息,如未收到则说明您的机器人不支持发送私聊消息或您的信息填写有误");
436
+ });
437
+ biliCom.subcommand(".ll").usage("展示当前正在直播的订阅对象").example("bili ll").action(async () => {
438
+ const { data: { live_users } } = await ctx.ba.getTheUserWhoIsLiveStreaming();
439
+ const subLiveUsers = [];
440
+ for (const sub of this.subManager) {
441
+ let onLive = false;
442
+ if (live_users.items) {
443
+ for (const user of live_users.items) if (user.mid.toString() === sub.uid && sub.live) {
444
+ onLive = true;
445
+ break;
446
+ }
447
+ }
448
+ subLiveUsers.push({
449
+ uid: Number.parseInt(sub.uid),
450
+ uname: sub.uname,
451
+ onLive
452
+ });
453
+ }
454
+ let table = "";
455
+ for (const user of subLiveUsers) table += `[UID:${user.uid}] 「${user.uname}」 ${user.onLive ? "正在直播" : "未开播"}\n`;
456
+ return table;
457
+ });
458
+ biliCom.subcommand(".dyn <uid:string> [index:number]", "手动推送一条动态信息", { hidden: true }).usage("手动推送一条动态信息").example("bili dyn 233 1 手动推送UID为233用户空间的第一条动态信息").action(async ({ session }, uid, index) => {
459
+ const i = index && index - 1 || 0;
460
+ const content = await this.ctx.ba.getUserSpaceDynamic(uid);
461
+ const item = content.data.items[i];
462
+ const buffer = await require_utils.withRetry(async () => {
463
+ return await this.ctx.gi.generateDynamicImg(item);
464
+ }, 1).catch(async (e) => {
465
+ if (e.message === "直播开播动态,不做处理") {
466
+ await session.send("直播开播动态,不做处理");
467
+ return;
468
+ }
469
+ if (e.message === "出现关键词,屏蔽该动态") {
470
+ await session.send("已屏蔽该动态");
471
+ return;
472
+ }
473
+ if (e.message === "已屏蔽转发动态") {
474
+ await session.send("已屏蔽转发动态");
475
+ return;
476
+ }
477
+ if (e.message === "已屏蔽专栏动态") {
478
+ await session.send("已屏蔽专栏动态");
479
+ return;
480
+ }
481
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
482
+ });
483
+ buffer && await session.send(koishi.h.image(buffer, "image/jpeg"));
484
+ });
485
+ }
486
+ async init(config) {
487
+ this.logger = this.ctx.logger("cr");
488
+ this.logger.info("初始化插件中...");
489
+ this.config = config;
490
+ this.privateBot = this.ctx.bots.find((bot) => bot.platform === config.master.platform);
491
+ if (!this.privateBot) this.ctx.notifier.create({ content: "您未配置私人机器人,将无法向您推送机器人状态!" });
492
+ this.loginDBData = (await this.ctx.database.get("loginBili", 1, ["dynamic_group_id"]))[0];
493
+ await this.checkIfLoginInfoIsLoaded();
494
+ if (!await this.checkIfIsLogin()) {
495
+ this.logger.info("账号未登录,请登录");
496
+ return;
497
+ }
498
+ if (config.sub) {
499
+ const { code, msg } = await this.loadSubFromConfig(config.sub);
500
+ if (code !== 0) {
501
+ this.logger.error(msg);
502
+ this.logger.error("订阅对象加载失败,插件初始化失败!");
503
+ await this.sendPrivateMsg("订阅对象加载失败,插件初始化失败!");
504
+ return;
505
+ }
506
+ }
507
+ this.initManager();
508
+ this.checkIfDynamicDetectIsNeeded();
509
+ this.checkIfLiveDetectIsNeeded();
510
+ this.updateSubNotifier();
511
+ this.ctx.on("dispose", () => {
512
+ if (this.loginTimer) this.loginTimer();
513
+ if (this.dynamicJob) this.dynamicJob.stop();
514
+ if (this.liveJob) this.liveJob.stop();
515
+ });
516
+ this.logger.info("插件初始化完毕!");
517
+ }
518
+ initManager() {
519
+ for (const sub of this.subManager) {
520
+ if (sub.dynamic) this.dynamicTimelineManager.set(sub.uid, Math.floor(luxon.DateTime.now().toSeconds()));
521
+ if (sub.live) this.liveStatusManager.set(sub.uid, {
522
+ roomId: sub.roomId,
523
+ live: false,
524
+ liveRoomInfo: void 0,
525
+ masterInfo: void 0,
526
+ watchedNum: "0",
527
+ liveStartTime: "",
528
+ liveStartTimeInit: false,
529
+ push: 0
530
+ });
531
+ }
532
+ }
533
+ getBot(pf, selfId) {
534
+ if (!selfId || selfId === "") return this.ctx.bots.find((bot) => bot.platform === pf);
535
+ return this.ctx.bots.find((bot) => bot.platform === pf && bot.selfId === selfId);
536
+ }
537
+ async sendPrivateMsg(content) {
538
+ if (this.config.master.enable) if (this.config.master.masterAccountGuildId) await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content, this.config.master.masterAccountGuildId);
539
+ else await this.privateBot.sendPrivateMessage(this.config.master.masterAccount, content);
540
+ }
541
+ async sendPrivateMsgAndRebootService() {
542
+ if (this.rebootCount >= 3) {
543
+ this.logger.error("已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件");
544
+ await this.sendPrivateMsg("已重启插件三次,请检查机器人状态后使用指令 sys start 启动插件");
545
+ await this.ctx.sm.disposePlugin();
546
+ return;
547
+ }
548
+ this.rebootCount++;
549
+ this.logger.info("插件出现未知错误,正在重启插件");
550
+ const flag = await this.ctx.sm.restartPlugin();
551
+ if (flag) this.logger.info("重启插件成功");
552
+ else {
553
+ this.logger.error("重启插件失败,请检查机器人状态后使用指令 sys start 启动插件");
554
+ await this.sendPrivateMsg("重启插件失败,请检查机器人状态后使用指令 sys start 启动插件");
555
+ await this.ctx.sm.disposePlugin();
556
+ }
557
+ }
558
+ async sendPrivateMsgAndStopService() {
559
+ await this.sendPrivateMsg("插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件");
560
+ this.logger.error("插件发生未知错误,请检查机器人状态后使用指令 sys start 启动插件");
561
+ await this.ctx.sm.disposePlugin();
562
+ return;
563
+ }
564
+ async sendMessageWithRetry(bot, channelId, content) {
565
+ require_utils.withRetry(async () => await bot.sendMessage(channelId, content), 1).catch(async (e) => {
566
+ if (e.message === "this._request is not a function") {
567
+ this.ctx.setTimeout(async () => {
568
+ await this.sendMessageWithRetry(bot, channelId, content);
569
+ }, 2e3);
570
+ return;
571
+ }
572
+ this.logger.error(`发送群组ID:${channelId}消息失败!原因: ${e.message}`);
573
+ await this.sendPrivateMsg(`发送群组ID:${channelId}消息失败,请查看日志`);
574
+ });
575
+ }
576
+ getGroupsThatMeetCriteria(targets, type) {
577
+ const pushArr = [];
578
+ if (type === require_type.PushType.Live || type === require_type.PushType.StartBroadcasting) {
579
+ for (const target of targets) for (const channel of target.channelArr) if (channel.live) pushArr.push(`${target.platform}:${channel.channelId}`);
580
+ return pushArr;
581
+ }
582
+ if (type === require_type.PushType.Dynamic) {
583
+ for (const target of targets) for (const channel of target.channelArr) if (channel.dynamic) pushArr.push(`${target.platform}:${channel.channelId}`);
584
+ return pushArr;
585
+ }
586
+ if (type === require_type.PushType.LiveGuardBuy) {
587
+ for (const target of targets) for (const channel of target.channelArr) if (channel.liveGuardBuy) pushArr.push(`${target.platform}:${channel.channelId}`);
588
+ return pushArr;
589
+ }
590
+ }
591
+ async broadcastToTargets(targets, content, type) {
592
+ if (targets.length !== 1 || targets[0].channelArr.length !== 1) {
593
+ const pushArr = this.getGroupsThatMeetCriteria(targets, type);
594
+ this.logger.info(`推送消息到 ${pushArr.length} 个目标频道,目标频道为:${pushArr.join(", ")}`);
595
+ await require_utils.withRetry(async () => {
596
+ await this.ctx.broadcast(pushArr, content);
597
+ }, 1);
598
+ return;
599
+ }
600
+ const targetChannel = targets[0].channelArr[0];
601
+ const bot = this.getBot(targets[0].platform, targetChannel.bot);
602
+ if (!bot || !bot.isActive) {
603
+ this.sendPrivateMsg("未找到对应bot实例,本次消息推送取消!");
604
+ this.logger.warn("未找到对应bot实例,本次消息推送取消!");
605
+ return;
606
+ }
607
+ const pushTypePatternMatching = {
608
+ [require_type.PushType.Live]: async () => {
609
+ if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
610
+ },
611
+ [require_type.PushType.Dynamic]: async () => {
612
+ if (targetChannel.dynamic) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
613
+ },
614
+ [require_type.PushType.StartBroadcasting]: async () => {
615
+ if (targetChannel.live) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
616
+ if (targetChannel.atAll) await this.sendMessageWithRetry(bot, targetChannel.channelId, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("at", { type: "all" }));
617
+ },
618
+ [require_type.PushType.LiveGuardBuy]: async () => {
619
+ if (targetChannel.liveGuardBuy) await this.sendMessageWithRetry(bot, targetChannel.channelId, content);
620
+ }
621
+ };
622
+ await pushTypePatternMatching[type]();
623
+ }
624
+ dynamicDetect() {
625
+ const handler = async () => {
626
+ const currentPushDyn = {};
627
+ const content = await require_utils.withRetry(async () => {
628
+ return await this.ctx.ba.getAllDynamic();
629
+ }, 1).catch((e) => {
630
+ this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
631
+ });
632
+ if (!content) return;
633
+ if (content.code !== 0) switch (content.code) {
634
+ case -101: {
635
+ this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
636
+ await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
637
+ await this.ctx.sm.disposePlugin();
638
+ break;
639
+ }
640
+ case -352: {
641
+ this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
642
+ await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
643
+ await this.ctx.sm.disposePlugin();
644
+ break;
645
+ }
646
+ case 4101128:
647
+ case 4101129: {
648
+ this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
649
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
650
+ break;
651
+ }
652
+ default: {
653
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
654
+ break;
655
+ }
656
+ }
657
+ const items = content.data.items;
658
+ for (const item of items) {
659
+ if (!item) continue;
660
+ const postTime = item.modules.module_author.pub_ts;
661
+ const uid = item.modules.module_author.mid.toString();
662
+ const name$1 = item.modules.module_author.name;
663
+ if (this.dynamicTimelineManager.has(uid)) {
664
+ const timeline = this.dynamicTimelineManager.get(uid);
665
+ if (timeline < postTime) {
666
+ const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
667
+ const buffer = await require_utils.withRetry(async () => {
668
+ return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
669
+ }, 1).catch(async (e) => {
670
+ if (e.message === "直播开播动态,不做处理") return;
671
+ if (e.message === "出现关键词,屏蔽该动态") {
672
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$1}发布了一条含有屏蔽关键字的动态`, require_type.PushType.Dynamic);
673
+ return;
674
+ }
675
+ if (e.message === "已屏蔽转发动态") {
676
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$1}转发了一条动态,已屏蔽`, require_type.PushType.Dynamic);
677
+ return;
678
+ }
679
+ if (e.message === "已屏蔽专栏动态") {
680
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$1}投稿了一条专栏,已屏蔽`, require_type.PushType.Dynamic);
681
+ return;
682
+ }
683
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
684
+ await this.sendPrivateMsgAndStopService();
685
+ });
686
+ if (!buffer) continue;
687
+ let dUrl = "";
688
+ if (this.config.dynamicUrl) if (item.type === "DYNAMIC_TYPE_AV") if (this.config.dynamicVideoUrlToBV) {
689
+ const bv = item.modules.module_dynamic.major.archive.jump_url.match(/BV[0-9A-Za-z]+/);
690
+ dUrl = bv ? bv[0] : "";
691
+ } else dUrl = `${name$1}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
692
+ else dUrl = `${name$1}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
693
+ this.logger.info("推送动态中...");
694
+ await this.broadcastToTargets(sub.target, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), require_type.PushType.Dynamic);
695
+ if (this.config.pushImgsInDynamic) {
696
+ if (item.type === "DYNAMIC_TYPE_DRAW") {
697
+ const pics = item.modules?.module_dynamic?.major?.opus?.pics;
698
+ if (pics) {
699
+ const picsMsg = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", {
700
+ forward: true,
701
+ children: pics.map((pic) => /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("img", {
702
+ src: pic.url,
703
+ alt: "动态图片"
704
+ }, pic.url))
705
+ });
706
+ await this.broadcastToTargets(sub.target, picsMsg, require_type.PushType.Dynamic);
707
+ }
708
+ }
709
+ }
710
+ if (!currentPushDyn[uid]) currentPushDyn[uid] = item;
711
+ this.logger.info("动态推送完毕!");
712
+ }
713
+ }
714
+ }
715
+ for (const uid in currentPushDyn) {
716
+ const postTime = currentPushDyn[uid].modules.module_author.pub_ts;
717
+ this.dynamicTimelineManager.set(uid, postTime);
718
+ }
719
+ };
720
+ return require_utils.withLock(handler);
721
+ }
722
+ debug_dynamicDetect() {
723
+ const handler = async () => {
724
+ const currentPushDyn = {};
725
+ this.logger.info("开始获取动态信息...");
726
+ const content = await require_utils.withRetry(async () => {
727
+ return await this.ctx.ba.getAllDynamic();
728
+ }, 1).catch((e) => {
729
+ this.logger.error(`dynamicDetect getAllDynamic() 发生了错误,错误为:${e.message}`);
730
+ });
731
+ if (!content) return;
732
+ if (content.code !== 0) switch (content.code) {
733
+ case -101: {
734
+ this.logger.error("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
735
+ await this.sendPrivateMsg("账号未登录,插件已停止工作,请登录后,输入指令 sys start 启动插件");
736
+ await this.ctx.sm.disposePlugin();
737
+ break;
738
+ }
739
+ case -352: {
740
+ this.logger.error("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
741
+ await this.sendPrivateMsg("账号被风控,插件已停止工作,请确认风控解除后,输入指令 sys start 启动插件");
742
+ await this.ctx.sm.disposePlugin();
743
+ break;
744
+ }
745
+ case 4101128:
746
+ case 4101129: {
747
+ this.logger.error(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
748
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
749
+ break;
750
+ }
751
+ default: {
752
+ await this.sendPrivateMsg(`获取动态信息错误,错误码为:${content.code},错误为:${content.message}`);
753
+ break;
754
+ }
755
+ }
756
+ this.logger.info("获取动态信息成功!开始处理动态信息...");
757
+ const items = content.data.items;
758
+ for (const item of items) {
759
+ if (!item) continue;
760
+ const postTime = item.modules.module_author.pub_ts;
761
+ const uid = item.modules.module_author.mid.toString();
762
+ const name$1 = item.modules.module_author.name;
763
+ this.logger.info(`获取到动态信息,UP主:${name$1},UID:${uid},动态发布时间:${luxon.DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
764
+ if (this.dynamicTimelineManager.has(uid)) {
765
+ this.logger.info("订阅该UP主,判断动态时间线...");
766
+ const timeline = this.dynamicTimelineManager.get(uid);
767
+ this.logger.info(`上次推送时间线:${luxon.DateTime.fromSeconds(timeline).toFormat("yyyy-MM-dd HH:mm:ss")}`);
768
+ if (timeline < postTime) {
769
+ this.logger.info("需要推送该条动态,开始推送...");
770
+ const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
771
+ this.logger.info("开始渲染推送卡片...");
772
+ const buffer = await require_utils.withRetry(async () => {
773
+ return await this.ctx.gi.generateDynamicImg(item, sub.card.enable ? sub.card : void 0);
774
+ }, 1).catch(async (e) => {
775
+ if (e.message === "直播开播动态,不做处理") return;
776
+ if (e.message === "出现关键词,屏蔽该动态") {
777
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$1}发布了一条含有屏蔽关键字的动态`, require_type.PushType.Dynamic);
778
+ return;
779
+ }
780
+ if (e.message === "已屏蔽转发动态") {
781
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$1}转发了一条动态,已屏蔽`, require_type.PushType.Dynamic);
782
+ return;
783
+ }
784
+ if (e.message === "已屏蔽专栏动态") {
785
+ if (this.config.filter.notify) await this.broadcastToTargets(sub.target, `${name$1}投稿了一条专栏,已屏蔽`, require_type.PushType.Dynamic);
786
+ return;
787
+ }
788
+ this.logger.error(`dynamicDetect generateDynamicImg() 推送卡片发送失败,原因:${e.message}`);
789
+ await this.sendPrivateMsgAndStopService();
790
+ });
791
+ if (!buffer) continue;
792
+ this.logger.info("渲染推送卡片成功!");
793
+ let dUrl = "";
794
+ if (this.config.dynamicUrl) {
795
+ this.logger.info("需要发送动态链接,开始生成链接...");
796
+ if (item.type === "DYNAMIC_TYPE_AV") if (this.config.dynamicVideoUrlToBV) {
797
+ const bv = item.modules.module_dynamic.major.archive.jump_url.match(/BV[0-9A-Za-z]+/);
798
+ dUrl = bv ? bv[0] : "";
799
+ } else dUrl = `${name$1}发布了新视频:https:${item.modules.module_dynamic.major.archive.jump_url}`;
800
+ else dUrl = `${name$1}发布了一条动态:https://t.bilibili.com/${item.id_str}`;
801
+ this.logger.info("动态链接生成成功!");
802
+ }
803
+ this.logger.info("推送动态中...");
804
+ await this.broadcastToTargets(sub.target, /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), dUrl] }), require_type.PushType.Dynamic);
805
+ if (this.config.pushImgsInDynamic) {
806
+ this.logger.info("需要发送动态中的图片,开始发送...");
807
+ if (item.type === "DYNAMIC_TYPE_DRAW") {
808
+ const pics = item.modules?.module_dynamic?.major?.opus?.pics;
809
+ if (pics) {
810
+ const picsMsg = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("message", {
811
+ forward: true,
812
+ children: pics.map((pic) => /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("img", {
813
+ src: pic.url,
814
+ alt: "动态图片"
815
+ }, pic.url))
816
+ });
817
+ await this.broadcastToTargets(sub.target, picsMsg, require_type.PushType.Dynamic);
818
+ }
819
+ }
820
+ this.logger.info("动态中的图片发送完毕!");
821
+ }
822
+ if (!currentPushDyn[uid]) currentPushDyn[uid] = item;
823
+ this.logger.info("动态推送完毕!");
824
+ }
825
+ }
826
+ }
827
+ this.logger.info("动态信息处理完毕!");
828
+ for (const uid in currentPushDyn) {
829
+ const postTime = currentPushDyn[uid].modules.module_author.pub_ts;
830
+ this.dynamicTimelineManager.set(uid, postTime);
831
+ this.logger.info(`更新时间线成功,UP主:${uid},时间线:${luxon.DateTime.fromSeconds(postTime).toFormat("yyyy-MM-dd HH:mm:ss")}`);
832
+ }
833
+ this.logger.info(`本次推送动态数量:${Object.keys(currentPushDyn).length}`);
834
+ };
835
+ return require_utils.withLock(handler);
836
+ }
837
+ async useMasterInfo(uid, masterInfo, liveType) {
838
+ const { data } = await this.ctx.ba.getMasterInfo(uid);
839
+ let liveOpenFollowerNum;
840
+ let liveEndFollowerNum;
841
+ let liveFollowerChange;
842
+ if (liveType === require_type.LiveType.StartBroadcasting || liveType === require_type.LiveType.FirstLiveBroadcast) {
843
+ liveOpenFollowerNum = data.follower_num;
844
+ liveEndFollowerNum = data.follower_num;
845
+ liveFollowerChange = 0;
846
+ }
847
+ if (liveType === require_type.LiveType.StopBroadcast || liveType === require_type.LiveType.LiveBroadcast) {
848
+ liveOpenFollowerNum = masterInfo.liveOpenFollowerNum;
849
+ liveEndFollowerNum = data.follower_num;
850
+ liveFollowerChange = liveEndFollowerNum - masterInfo.liveOpenFollowerNum;
851
+ }
852
+ return {
853
+ username: data.info.uname,
854
+ userface: data.info.face,
855
+ roomId: data.room_id,
856
+ liveOpenFollowerNum,
857
+ liveEndFollowerNum,
858
+ liveFollowerChange
859
+ };
860
+ }
861
+ async useLiveRoomInfo(roomId) {
862
+ const data = await require_utils.withRetry(async () => await this.ctx.ba.getLiveRoomInfo(roomId)).then((content) => content.data).catch((e) => {
863
+ this.logger.error(`liveDetect getLiveRoomInfo 发生了错误,错误为:${e.message}`);
864
+ return false;
865
+ });
866
+ if (!data) return await this.sendPrivateMsgAndStopService();
867
+ return data;
868
+ }
869
+ async sendLiveNotifyCard(liveType, followerDisplay, liveInfo, target, liveNotifyMsg) {
870
+ const buffer = await require_utils.withRetry(async () => {
871
+ return await this.ctx.gi.generateLiveImg(liveInfo.liveRoomInfo, liveInfo.masterInfo.username, liveInfo.masterInfo.userface, followerDisplay, liveType, liveInfo.cardStyle.enable ? liveInfo.cardStyle : void 0);
872
+ }, 1).catch((e) => {
873
+ this.logger.error(`liveDetect generateLiveImg() 推送卡片生成失败,原因:${e.message}`);
874
+ });
875
+ if (!buffer) return await this.sendPrivateMsgAndStopService();
876
+ const msg = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [koishi.h.image(buffer, "image/jpeg"), liveNotifyMsg || ""] });
877
+ return await this.broadcastToTargets(target, msg, liveType === require_type.LiveType.StartBroadcasting ? require_type.PushType.StartBroadcasting : require_type.PushType.Live);
878
+ }
879
+ async liveDetectWithListener(roomId, target, cardStyle) {
880
+ let liveTime;
881
+ let pushAtTimeTimer;
882
+ const currentLiveDanmakuArr = [];
883
+ let liveStatus = false;
884
+ let channelArrLen = 0;
885
+ let liveRoomInfo;
886
+ let masterInfo;
887
+ let watchedNum;
888
+ const liveGuardBuyPushTargetArr = target.map((channel) => {
889
+ const liveGuardBuyArr = channel.channelArr.filter((channelId) => channelId.liveGuardBuy);
890
+ channelArrLen += liveGuardBuyArr.length;
891
+ return {
892
+ channelArr: liveGuardBuyArr,
893
+ platform: channel.platform
894
+ };
895
+ });
896
+ const pushAtTimeFunc = async () => {
897
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.LiveBroadcast)) {
898
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
899
+ return await this.sendPrivateMsgAndStopService();
900
+ }
901
+ if (liveRoomInfo.live_status === 0 || liveRoomInfo.live_status === 2) {
902
+ liveStatus = false;
903
+ pushAtTimeTimer?.();
904
+ await this.sendPrivateMsg("直播间已下播!与直播间的连接可能已断开,请使用指令 sys restart 重启插件");
905
+ return;
906
+ }
907
+ liveTime = liveRoomInfo.live_time;
908
+ const watched = watchedNum || "暂未获取到";
909
+ const liveMsg = this.config.customLive ? this.config.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-watched", watched).replace("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
910
+ await this.sendLiveNotifyCard(require_type.LiveType.LiveBroadcast, watched, {
911
+ liveRoomInfo,
912
+ masterInfo,
913
+ cardStyle
914
+ }, target, liveMsg);
915
+ };
916
+ const useMasterAndLiveRoomInfo = async (liveType) => {
917
+ let flag = true;
918
+ liveRoomInfo = await this.useLiveRoomInfo(roomId).catch(() => {
919
+ flag = false;
920
+ return null;
921
+ });
922
+ if (!flag || !liveRoomInfo || !liveRoomInfo.uid) {
923
+ flag = false;
924
+ return flag;
925
+ }
926
+ masterInfo = await this.useMasterInfo(liveRoomInfo.uid, masterInfo, liveType).catch(() => {
927
+ flag = false;
928
+ return null;
929
+ });
930
+ return flag;
931
+ };
932
+ const handler = {
933
+ onError: async () => {
934
+ liveStatus = false;
935
+ pushAtTimeTimer?.();
936
+ this.ctx.bl.closeListener(roomId);
937
+ await this.sendPrivateMsg(`[${roomId}]直播间连接发生错误!`);
938
+ this.logger.error(`[${roomId}]直播间连接发生错误!`);
939
+ },
940
+ onIncomeDanmu: ({ body }) => {
941
+ currentLiveDanmakuArr.push(body.content);
942
+ },
943
+ onIncomeSuperChat: ({ body }) => {
944
+ currentLiveDanmakuArr.push(body.content);
945
+ },
946
+ onWatchedChange: ({ body }) => {
947
+ watchedNum = body.text_small;
948
+ },
949
+ onGuardBuy: ({ body }) => {
950
+ const content = `[${masterInfo.username}的直播间]「${body.user.uname}」加入了大航海(${body.gift_name})`;
951
+ channelArrLen > 0 && this.broadcastToTargets(liveGuardBuyPushTargetArr, content, require_type.PushType.LiveGuardBuy);
952
+ },
953
+ onLiveStart: async () => {
954
+ if (liveStatus) return;
955
+ liveStatus = true;
956
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.StartBroadcasting)) {
957
+ liveStatus = false;
958
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
959
+ return await this.sendPrivateMsgAndStopService();
960
+ }
961
+ liveTime = liveRoomInfo.live_time;
962
+ const follower = masterInfo.liveOpenFollowerNum >= 1e4 ? `${(masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : masterInfo.liveOpenFollowerNum.toString();
963
+ const liveStartMsg = this.config.customLiveStart ? this.config.customLiveStart.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-follower", follower).replace("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
964
+ await this.sendLiveNotifyCard(require_type.LiveType.StartBroadcasting, follower, {
965
+ liveRoomInfo,
966
+ masterInfo,
967
+ cardStyle
968
+ }, target, liveStartMsg);
969
+ if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
970
+ },
971
+ onLiveEnd: async () => {
972
+ liveStatus = false;
973
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.StopBroadcast)) {
974
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
975
+ return await this.sendPrivateMsgAndStopService();
976
+ }
977
+ liveRoomInfo.live_time = liveTime;
978
+ const followerChange = (() => {
979
+ const liveFollowerChangeNum = masterInfo.liveFollowerChange;
980
+ if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
981
+ return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
982
+ })();
983
+ const liveEndMsg = this.config.customLiveEnd ? this.config.customLiveEnd.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-follower_change", followerChange).replace("\\n", "\n") : null;
984
+ await this.sendLiveNotifyCard(require_type.LiveType.StopBroadcast, followerChange, {
985
+ liveRoomInfo,
986
+ masterInfo,
987
+ cardStyle
988
+ }, target, liveEndMsg);
989
+ pushAtTimeTimer();
990
+ pushAtTimeTimer = null;
991
+ }
992
+ };
993
+ await this.ctx.bl.startLiveRoomListener(roomId, handler);
994
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.FirstLiveBroadcast)) return this.sendPrivateMsg("获取直播间信息失败,启动直播间弹幕检测失败!");
995
+ if (liveRoomInfo.live_status === 1) {
996
+ liveTime = liveRoomInfo.live_time;
997
+ const watched = watchedNum || "暂未获取到";
998
+ const liveMsg = this.config.customLive ? this.config.customLive.replace("-name", masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveTime)).replace("-watched", watched).replace("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveRoomInfo.short_id === 0 ? liveRoomInfo.room_id : liveRoomInfo.short_id}`) : null;
999
+ if (this.config.restartPush) await this.sendLiveNotifyCard(require_type.LiveType.LiveBroadcast, watched, {
1000
+ liveRoomInfo,
1001
+ masterInfo,
1002
+ cardStyle
1003
+ }, target, liveMsg);
1004
+ if (!pushAtTimeTimer) pushAtTimeTimer = this.ctx.setInterval(pushAtTimeFunc, this.config.pushTime * 1e3 * 60 * 60);
1005
+ liveStatus = true;
1006
+ }
1007
+ }
1008
+ async liveDetectWithAPI() {
1009
+ const useMasterAndLiveRoomInfo = async (liveType, liveStatus) => {
1010
+ let flag = true;
1011
+ liveStatus.liveRoomInfo = await this.useLiveRoomInfo(liveStatus.roomId).catch(() => {
1012
+ flag = false;
1013
+ return null;
1014
+ });
1015
+ if (!flag || !liveStatus.liveRoomInfo?.uid) {
1016
+ flag = false;
1017
+ return flag;
1018
+ }
1019
+ liveStatus.masterInfo = await this.useMasterInfo(liveStatus.liveRoomInfo.uid, liveStatus.masterInfo, liveType).catch(() => {
1020
+ flag = false;
1021
+ return null;
1022
+ });
1023
+ return flag;
1024
+ };
1025
+ const uids = [];
1026
+ for (const [uid] of this.liveStatusManager.entries()) uids.push(uid);
1027
+ const useLiveInfo = async () => {
1028
+ const { data: data$1 } = await require_utils.withRetry(async () => await this.ctx.ba.getLiveRoomInfoByUids(uids), 3).catch(async () => {
1029
+ return void 0;
1030
+ });
1031
+ if (!data$1) {
1032
+ await this.sendPrivateMsgAndStopService();
1033
+ return;
1034
+ }
1035
+ return data$1;
1036
+ };
1037
+ const data = await useLiveInfo();
1038
+ for (const item of Object.values(data)) {
1039
+ const uid = item.uid.toString();
1040
+ const liveStatus = this.liveStatusManager.get(uid);
1041
+ const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1042
+ if (item.live_status === 1) {
1043
+ liveStatus.live = true;
1044
+ await useMasterAndLiveRoomInfo(require_type.LiveType.FirstLiveBroadcast, liveStatus);
1045
+ if (!liveStatus.liveStartTimeInit) {
1046
+ liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1047
+ liveStatus.liveStartTimeInit = true;
1048
+ }
1049
+ const liveMsg = this.config.customLive ? this.config.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime)).replace("-watched", "API模式无法获取").replace("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`) : null;
1050
+ await this.sendLiveNotifyCard(require_type.LiveType.LiveBroadcast, "API", {
1051
+ liveRoomInfo: liveStatus.liveRoomInfo,
1052
+ masterInfo: liveStatus.masterInfo,
1053
+ cardStyle: sub.card
1054
+ }, sub.target, liveMsg);
1055
+ }
1056
+ }
1057
+ const handler = async () => {
1058
+ const data$1 = await useLiveInfo();
1059
+ for (const item of Object.values(data$1)) {
1060
+ const uid = item.uid.toString();
1061
+ const liveStatus = this.liveStatusManager.get(uid);
1062
+ const sub = this.subManager.find((sub$1) => sub$1.uid === uid);
1063
+ if (!sub) return;
1064
+ switch (item.live_status) {
1065
+ case 0:
1066
+ case 2: {
1067
+ if (liveStatus.live === true) {
1068
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.StopBroadcast, liveStatus)) {
1069
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播下播卡片失败!");
1070
+ return await this.sendPrivateMsgAndStopService();
1071
+ }
1072
+ if (liveStatus.liveStartTimeInit) {
1073
+ liveStatus.liveRoomInfo.live_time = liveStatus.liveStartTime;
1074
+ liveStatus.liveStartTimeInit = false;
1075
+ }
1076
+ const followerChange = (() => {
1077
+ const liveFollowerChangeNum = liveStatus.masterInfo.liveFollowerChange;
1078
+ if (liveFollowerChangeNum > 0) return liveFollowerChangeNum >= 1e4 ? `+${liveFollowerChangeNum.toFixed(1)}万` : `+${liveFollowerChangeNum}`;
1079
+ return liveFollowerChangeNum <= -1e4 ? `${liveFollowerChangeNum.toFixed(1)}万` : liveFollowerChangeNum.toString();
1080
+ })();
1081
+ const liveEndMsg = this.config.customLiveEnd ? this.config.customLiveEnd.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime)).replace("-follower_change", followerChange).replace("\\n", "\n") : null;
1082
+ await this.sendLiveNotifyCard(require_type.LiveType.StopBroadcast, followerChange, {
1083
+ liveRoomInfo: liveStatus.liveRoomInfo,
1084
+ masterInfo: liveStatus.masterInfo,
1085
+ cardStyle: sub.card
1086
+ }, sub.target, liveEndMsg);
1087
+ liveStatus.live = false;
1088
+ }
1089
+ break;
1090
+ }
1091
+ case 1: {
1092
+ if (liveStatus.live === false) {
1093
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.StopBroadcast, liveStatus)) {
1094
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播开播卡片失败!");
1095
+ return await this.sendPrivateMsgAndStopService();
1096
+ }
1097
+ liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1098
+ liveStatus.liveStartTimeInit = true;
1099
+ const follower = liveStatus.masterInfo.liveOpenFollowerNum >= 1e4 ? `${(liveStatus.masterInfo.liveOpenFollowerNum / 1e4).toFixed(1)}万` : liveStatus.masterInfo.liveOpenFollowerNum.toString();
1100
+ const liveStartMsg = this.config.customLiveStart ? this.config.customLiveStart.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime)).replace("-follower", follower).replace("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`) : null;
1101
+ await this.sendLiveNotifyCard(require_type.LiveType.StartBroadcasting, follower, {
1102
+ liveRoomInfo: liveStatus.liveRoomInfo,
1103
+ masterInfo: liveStatus.masterInfo,
1104
+ cardStyle: sub.card
1105
+ }, sub.target, liveStartMsg);
1106
+ liveStatus.live = true;
1107
+ }
1108
+ if (liveStatus.live === true) {
1109
+ if (liveStatus.push < this.config.pushTime * 60 * 60 / 30) {
1110
+ liveStatus.push++;
1111
+ break;
1112
+ }
1113
+ if (!await useMasterAndLiveRoomInfo(require_type.LiveType.LiveBroadcast, liveStatus)) {
1114
+ await this.sendPrivateMsg("获取直播间信息失败,推送直播卡片失败!");
1115
+ return await this.sendPrivateMsgAndStopService();
1116
+ }
1117
+ if (!liveStatus.liveStartTimeInit) {
1118
+ liveStatus.liveStartTime = liveStatus.liveRoomInfo.live_time;
1119
+ liveStatus.liveStartTimeInit = true;
1120
+ }
1121
+ const liveMsg = this.config.customLive ? this.config.customLive.replace("-name", liveStatus.masterInfo.username).replace("-time", await this.ctx.gi.getTimeDifference(liveStatus.liveStartTime)).replace("-watched", "API模式无法获取").replace("\\n", "\n").replace("-link", `https://live.bilibili.com/${liveStatus.liveRoomInfo.short_id === 0 ? liveStatus.liveRoomInfo.room_id : liveStatus.liveRoomInfo.short_id}`) : null;
1122
+ await this.sendLiveNotifyCard(require_type.LiveType.LiveBroadcast, "API", {
1123
+ liveRoomInfo: liveStatus.liveRoomInfo,
1124
+ masterInfo: liveStatus.masterInfo,
1125
+ cardStyle: sub.card
1126
+ }, sub.target, liveMsg);
1127
+ liveStatus.push = 0;
1128
+ }
1129
+ break;
1130
+ }
1131
+ default: break;
1132
+ }
1133
+ }
1134
+ };
1135
+ return require_utils.withLock(handler);
1136
+ }
1137
+ subShow() {
1138
+ let table = "";
1139
+ for (const sub of this.subManager) table += `UID:${sub.uid} ${sub.dynamic ? "已订阅动态" : ""} ${sub.live ? "已订阅直播" : ""}\n`;
1140
+ return table ? table : "没有订阅任何UP";
1141
+ }
1142
+ updateSubNotifier() {
1143
+ if (this.subNotifier) this.subNotifier.dispose();
1144
+ const subInfo = this.subShow();
1145
+ let table = "";
1146
+ if (subInfo === "没有订阅任何UP") table = subInfo;
1147
+ else {
1148
+ const subTableArray = subInfo.split("\n");
1149
+ subTableArray.splice(subTableArray.length - 1, 1);
1150
+ table = /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsxs)(__satorijs_element_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("p", { children: "当前订阅对象:" }), /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("ul", { children: subTableArray.map((str) => /* @__PURE__ */ (0, __satorijs_element_jsx_runtime.jsx)("li", { children: str })) })] });
1151
+ }
1152
+ this.subNotifier = this.ctx.notifier.create(table);
1153
+ }
1154
+ async checkIfLoginInfoIsLoaded() {
1155
+ return new Promise((resolve) => {
1156
+ const check = () => {
1157
+ if (!this.ctx.ba.getLoginInfoIsLoaded()) this.ctx.setTimeout(check, 500);
1158
+ else resolve("success");
1159
+ };
1160
+ check();
1161
+ });
1162
+ }
1163
+ async subUserInBili(mid) {
1164
+ const checkGroupIsReady = async () => {
1165
+ if (!this.loginDBData?.dynamic_group_id) {
1166
+ const createGroupData = await this.ctx.ba.createGroup("订阅");
1167
+ if (createGroupData.code === 22106) {
1168
+ const allGroupData = await this.ctx.ba.getAllGroup();
1169
+ for (const group of allGroupData.data) if (group.name === "订阅") {
1170
+ this.loginDBData.dynamic_group_id = group.tagid.toString();
1171
+ this.ctx.database.set("loginBili", 1, { dynamic_group_id: this.loginDBData.dynamic_group_id });
1172
+ return {
1173
+ code: 0,
1174
+ msg: "分组已存在"
1175
+ };
1176
+ }
1177
+ } else if (createGroupData.code !== 0) return {
1178
+ code: createGroupData.code,
1179
+ msg: createGroupData.message
1180
+ };
1181
+ this.ctx.database.set("loginBili", 1, { dynamic_group_id: createGroupData.data.tagid.toString() });
1182
+ return {
1183
+ code: createGroupData.code,
1184
+ msg: createGroupData.message
1185
+ };
1186
+ }
1187
+ return {
1188
+ code: 0,
1189
+ msg: "分组已存在"
1190
+ };
1191
+ };
1192
+ const resp = await checkGroupIsReady();
1193
+ if (resp.code !== 0) return resp;
1194
+ const getGroupDetailData = async () => {
1195
+ const relationGroupDetailData = await this.ctx.ba.getRelationGroupDetail(this.loginDBData.dynamic_group_id);
1196
+ if (relationGroupDetailData.code !== 0) {
1197
+ if (relationGroupDetailData.code === 22104) {
1198
+ this.loginDBData.dynamic_group_id = null;
1199
+ const resp$1 = await checkGroupIsReady();
1200
+ if (resp$1.code !== 0) return resp$1;
1201
+ return getGroupDetailData();
1202
+ }
1203
+ return {
1204
+ code: relationGroupDetailData.code,
1205
+ msg: relationGroupDetailData.message,
1206
+ data: void 0
1207
+ };
1208
+ }
1209
+ return {
1210
+ code: 0,
1211
+ msg: "获取分组明细成功",
1212
+ data: relationGroupDetailData.data
1213
+ };
1214
+ };
1215
+ const { code, msg, data } = await getGroupDetailData();
1216
+ if (code !== 0) return {
1217
+ code,
1218
+ msg
1219
+ };
1220
+ for (const user of data) if (user.mid === mid) return {
1221
+ code: 0,
1222
+ msg: "订阅对象已存在于分组中"
1223
+ };
1224
+ const subUserData = await this.ctx.ba.follow(mid);
1225
+ const subUserMatchPattern = {
1226
+ [-101]: () => {
1227
+ return {
1228
+ code: subUserData.code,
1229
+ msg: "账号未登录,请使用指令bili login登录后再进行订阅操作"
1230
+ };
1231
+ },
1232
+ [-102]: () => {
1233
+ return {
1234
+ code: subUserData.code,
1235
+ msg: "账号被封停,无法进行订阅操作"
1236
+ };
1237
+ },
1238
+ [22002]: () => {
1239
+ return {
1240
+ code: subUserData.code,
1241
+ msg: "因对方隐私设置,无法进行订阅操作"
1242
+ };
1243
+ },
1244
+ [22003]: () => {
1245
+ return {
1246
+ code: subUserData.code,
1247
+ msg: "你已将对方拉黑,无法进行订阅操作"
1248
+ };
1249
+ },
1250
+ [22013]: () => {
1251
+ return {
1252
+ code: subUserData.code,
1253
+ msg: "账号已注销,无法进行订阅操作"
1254
+ };
1255
+ },
1256
+ [40061]: () => {
1257
+ return {
1258
+ code: subUserData.code,
1259
+ msg: "账号不存在,请检查uid输入是否正确或用户是否存在"
1260
+ };
1261
+ },
1262
+ [22001]: () => {
1263
+ return {
1264
+ code: 0,
1265
+ msg: "订阅对象为自己,无需添加到分组"
1266
+ };
1267
+ },
1268
+ [22014]: async () => {
1269
+ const copyUserToGroupData = await this.ctx.ba.copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1270
+ if (copyUserToGroupData.code !== 0) return {
1271
+ code: copyUserToGroupData.code,
1272
+ msg: "添加订阅对象到分组失败,请稍后重试"
1273
+ };
1274
+ return {
1275
+ code: 0,
1276
+ msg: "订阅对象添加成功"
1277
+ };
1278
+ },
1279
+ [0]: async () => {
1280
+ const copyUserToGroupData = await this.ctx.ba.copyUserToGroup(mid, this.loginDBData.dynamic_group_id);
1281
+ if (copyUserToGroupData.code !== 0) return {
1282
+ code: copyUserToGroupData.code,
1283
+ msg: "添加订阅对象到分组失败,请稍后重试"
1284
+ };
1285
+ return {
1286
+ code: 0,
1287
+ msg: "订阅对象添加成功"
1288
+ };
1289
+ }
1290
+ };
1291
+ return await subUserMatchPattern[subUserData.code]();
1292
+ }
1293
+ async loadSubFromConfig(subs) {
1294
+ for (const sub of subs) {
1295
+ this.logger.info(`加载订阅UID:${sub.uid}中...`);
1296
+ const { code: userInfoCode, msg: userInfoMsg, data: userInfoData } = await require_utils.withRetry(async () => {
1297
+ const data = await this.ctx.ba.getUserInfo(sub.uid);
1298
+ return {
1299
+ code: 0,
1300
+ data
1301
+ };
1302
+ }).then((content) => content.data).catch((e) => {
1303
+ this.logger.error(`loadSubFromConfig() getUserInfo() 发生了错误,错误为:${e.message}`);
1304
+ return {
1305
+ code: -1,
1306
+ message: `加载订阅UID:${sub.uid}失败!`
1307
+ };
1308
+ });
1309
+ if (userInfoCode !== 0) return {
1310
+ code: userInfoCode,
1311
+ msg: userInfoMsg
1312
+ };
1313
+ if (this.config.liveDetectType === "WS" && sub.live) {
1314
+ if (!userInfoData.live_room) {
1315
+ sub.live = false;
1316
+ this.logger.warn(`UID:${sub.uid} 用户没有开通直播间,无法订阅直播!`);
1317
+ }
1318
+ if (sub.live) await this.liveDetectWithListener(userInfoData.live_room.roomid, sub.target, sub.card);
1319
+ }
1320
+ const subInfo = await this.subUserInBili(sub.uid);
1321
+ if (subInfo.code !== 0) return subInfo;
1322
+ this.subManager.push({
1323
+ id: +sub.uid,
1324
+ uid: sub.uid,
1325
+ uname: userInfoData.name,
1326
+ roomId: sub.live ? userInfoData.live_room.roomid : "",
1327
+ target: sub.target,
1328
+ platform: "",
1329
+ live: sub.live,
1330
+ dynamic: sub.dynamic,
1331
+ card: sub.card
1332
+ });
1333
+ this.logger.info(`UID:${sub.uid}订阅加载完毕!`);
1334
+ const randomDelay = Math.floor(Math.random() * 3) + 1;
1335
+ this.logger.info(`随机延迟:${randomDelay}秒`);
1336
+ await this.ctx.sleep(randomDelay * 1e3);
1337
+ }
1338
+ return {
1339
+ code: 0,
1340
+ msg: "订阅加载完毕!"
1341
+ };
1342
+ }
1343
+ checkIfDynamicDetectIsNeeded() {
1344
+ if (this.dynamicTimelineManager.size > 0) this.enableDynamicDetect();
1345
+ }
1346
+ checkIfLiveDetectIsNeeded() {
1347
+ if (this.config.liveDetectType === "API") {
1348
+ if (this.liveStatusManager.size > 0) this.enableLiveDetect();
1349
+ }
1350
+ }
1351
+ enableDynamicDetect() {
1352
+ this.dynamicJob = new cron.CronJob("*/2 * * * *", this.config.dynamicDebugMode ? this.debug_dynamicDetect() : this.dynamicDetect());
1353
+ this.logger.info("动态监测已开启");
1354
+ this.dynamicJob.start();
1355
+ }
1356
+ async enableLiveDetect() {
1357
+ this.liveJob = new cron.CronJob("*/30 * * * * *", await this.liveDetectWithAPI());
1358
+ this.logger.info("直播监测已开启");
1359
+ this.liveJob.start();
1360
+ }
1361
+ async checkIfIsLogin() {
1362
+ if ((await this.ctx.database.get("loginBili", 1)).length !== 0) {
1363
+ if (this.ctx.ba.getCookies() !== "[]") return true;
1364
+ }
1365
+ return false;
1366
+ }
1367
+ };
1368
+ (function(_ComRegister) {
1369
+ const Config$1 = _ComRegister.Config = koishi.Schema.object({
1370
+ sub: koishi.Schema.array(koishi.Schema.object({
1371
+ uid: koishi.Schema.string().description("订阅用户UID"),
1372
+ dynamic: koishi.Schema.boolean().description("是否订阅用户动态"),
1373
+ live: koishi.Schema.boolean().description("是否订阅用户直播"),
1374
+ target: koishi.Schema.array(koishi.Schema.object({
1375
+ channelArr: koishi.Schema.array(koishi.Schema.object({
1376
+ channelId: koishi.Schema.string().description("频道/群组号"),
1377
+ dynamic: koishi.Schema.boolean().description("该频道/群组是否推送动态信息"),
1378
+ live: koishi.Schema.boolean().description("该频道/群组是否推送直播通知"),
1379
+ liveGuardBuy: koishi.Schema.boolean().description("该频道/群组是否推送弹幕消息"),
1380
+ atAll: koishi.Schema.boolean().description("推送开播通知时是否艾特全体成员"),
1381
+ bot: koishi.Schema.string().description("若您有多个相同平台机器人,可在此填写当前群聊执行推送的机器人账号。不填则默认第一个")
1382
+ })).description("频道/群组信息"),
1383
+ platform: koishi.Schema.string().description("推送平台")
1384
+ })).description("订阅用户需要发送的频道/群组信息"),
1385
+ card: koishi.Schema.object({
1386
+ enable: koishi.Schema.boolean(),
1387
+ cardColorStart: koishi.Schema.string(),
1388
+ cardColorEnd: koishi.Schema.string(),
1389
+ cardBasePlateColor: koishi.Schema.string(),
1390
+ cardBasePlateBorder: koishi.Schema.string()
1391
+ }).description("自定义推送卡片颜色,默认使用插件内置的颜色,设置后会覆盖插件内置的颜色")
1392
+ })).role("table").description("手动输入订阅信息,方便自定义订阅内容,这里的订阅内容不会存入数据库。uid: 订阅用户UID,dynamic: 是否需要订阅动态,live: 是否需要订阅直播"),
1393
+ master: koishi.Schema.object({
1394
+ enable: koishi.Schema.boolean(),
1395
+ platform: koishi.Schema.string(),
1396
+ masterAccount: koishi.Schema.string(),
1397
+ masterAccountGuildId: koishi.Schema.string()
1398
+ }),
1399
+ liveDetectType: koishi.Schema.string(),
1400
+ restartPush: koishi.Schema.boolean().required(),
1401
+ pushTime: koishi.Schema.number().required(),
1402
+ pushImgsInDynamic: koishi.Schema.boolean().required(),
1403
+ liveLoopTime: koishi.Schema.number().default(10),
1404
+ customLiveStart: koishi.Schema.string().required(),
1405
+ customLive: koishi.Schema.string(),
1406
+ customLiveEnd: koishi.Schema.string().required(),
1407
+ dynamicUrl: koishi.Schema.boolean().required(),
1408
+ dynamicVideoUrlToBV: koishi.Schema.boolean().required(),
1409
+ filter: koishi.Schema.object({
1410
+ enable: koishi.Schema.boolean(),
1411
+ notify: koishi.Schema.boolean(),
1412
+ regex: koishi.Schema.string(),
1413
+ keywords: koishi.Schema.array(String)
1414
+ }),
1415
+ dynamicDebugMode: koishi.Schema.boolean().required()
1416
+ });
1417
+ })(ComRegister || (ComRegister = {}));
1418
+ var comRegister_default = ComRegister;
1419
+
1420
+ //#endregion
1421
+ Object.defineProperty(exports, 'comRegister_default', {
1422
+ enumerable: true,
1423
+ get: function () {
1424
+ return comRegister_default;
1425
+ }
1426
+ });