koishi-plugin-maple-broadcast 0.0.1 → 0.0.2
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 +0 -1
- package/lib/index.js +18 -20
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -22,12 +22,10 @@ var src_exports = {};
|
|
|
22
22
|
__export(src_exports, {
|
|
23
23
|
Config: () => Config,
|
|
24
24
|
apply: () => apply,
|
|
25
|
-
name: () => name
|
|
26
|
-
using: () => using
|
|
25
|
+
name: () => name
|
|
27
26
|
});
|
|
28
27
|
module.exports = __toCommonJS(src_exports);
|
|
29
28
|
var import_koishi = require("koishi");
|
|
30
|
-
var using = ["database"];
|
|
31
29
|
var name = "maple-broadcast";
|
|
32
30
|
var Config = import_koishi.Schema.object({
|
|
33
31
|
broadcastInterval: import_koishi.Schema.number().default(1e3).description("广播发送间隔(毫秒)").min(100).max(1e4),
|
|
@@ -50,6 +48,7 @@ async function getQQGroupName(ctx, guildId) {
|
|
|
50
48
|
}
|
|
51
49
|
__name(getQQGroupName, "getQQGroupName");
|
|
52
50
|
function apply(ctx, config) {
|
|
51
|
+
const logger = ctx.logger("maple-broadcast");
|
|
53
52
|
ctx.model.extend("broadcast_groups", {
|
|
54
53
|
id: "unsigned",
|
|
55
54
|
name: "string",
|
|
@@ -243,11 +242,11 @@ function apply(ctx, config) {
|
|
|
243
242
|
(bot, index) => `${index + 1}. [#${bot.id}] ${bot.guildName} ${bot.guildId}`
|
|
244
243
|
);
|
|
245
244
|
const 发送结果 = [`需要发送的群列表(共 ${群列表.length} 个):`, ...群信息列表];
|
|
246
|
-
await session
|
|
247
|
-
const 广播结果 = await 发送广播到群组(ctx, session, 群列表, 广播内容, config.broadcastInterval, config.broadcastTimeout);
|
|
245
|
+
await session.send(发送结果.join("\n"));
|
|
246
|
+
const 广播结果 = await 发送广播到群组(ctx, session, 群列表, 广播内容, config.broadcastInterval, config.broadcastTimeout, logger);
|
|
248
247
|
return 广播结果;
|
|
249
248
|
});
|
|
250
|
-
async function 发送广播到群组(ctx2, session, 群列表, 广播内容, 间隔,
|
|
249
|
+
async function 发送广播到群组(ctx2, session, 群列表, 广播内容, 间隔, 超时时间, logger2) {
|
|
251
250
|
const 成功列表 = [];
|
|
252
251
|
const 失败列表 = [];
|
|
253
252
|
const 超时列表 = [];
|
|
@@ -259,7 +258,7 @@ function apply(ctx, config) {
|
|
|
259
258
|
const 开始时间 = Date.now();
|
|
260
259
|
try {
|
|
261
260
|
await Promise.race([
|
|
262
|
-
发送广播任务(ctx2, 群列表, 广播内容, 间隔, 成功列表,
|
|
261
|
+
发送广播任务(ctx2, 群列表, 广播内容, 间隔, 成功列表, 失败列表, logger2),
|
|
263
262
|
超时Promise.then((isTimeout) => {
|
|
264
263
|
if (isTimeout) {
|
|
265
264
|
throw new Error(`广播发送超时(${超时时间}秒)`);
|
|
@@ -275,14 +274,14 @@ function apply(ctx, config) {
|
|
|
275
274
|
];
|
|
276
275
|
if (成功列表.length > 0) {
|
|
277
276
|
结果消息.push("");
|
|
278
|
-
结果消息.push("
|
|
277
|
+
结果消息.push("发送成功:");
|
|
279
278
|
成功列表.forEach((bot, index) => {
|
|
280
279
|
结果消息.push(`${index + 1}. [#${bot.guildId}] ${bot.guildName}`);
|
|
281
280
|
});
|
|
282
281
|
}
|
|
283
282
|
if (失败列表.length > 0) {
|
|
284
283
|
结果消息.push("");
|
|
285
|
-
结果消息.push("
|
|
284
|
+
结果消息.push("发送失败:");
|
|
286
285
|
失败列表.forEach((bot, index) => {
|
|
287
286
|
结果消息.push(`${index + 1}. [#${bot.guildId}] ${bot.guildName} - ${bot.error}`);
|
|
288
287
|
});
|
|
@@ -307,21 +306,21 @@ function apply(ctx, config) {
|
|
|
307
306
|
];
|
|
308
307
|
if (成功列表.length > 0) {
|
|
309
308
|
结果消息.push("");
|
|
310
|
-
结果消息.push("
|
|
309
|
+
结果消息.push("发送成功:");
|
|
311
310
|
成功列表.forEach((bot, index) => {
|
|
312
311
|
结果消息.push(`${index + 1}. [#${bot.guildId}] ${bot.guildName}`);
|
|
313
312
|
});
|
|
314
313
|
}
|
|
315
314
|
if (失败列表.length > 0) {
|
|
316
315
|
结果消息.push("");
|
|
317
|
-
结果消息.push("
|
|
316
|
+
结果消息.push("发送失败:");
|
|
318
317
|
失败列表.forEach((bot, index) => {
|
|
319
318
|
结果消息.push(`${index + 1}. [#${bot.guildId}] ${bot.guildName} - ${bot.error}`);
|
|
320
319
|
});
|
|
321
320
|
}
|
|
322
321
|
if (超时列表.length > 0) {
|
|
323
322
|
结果消息.push("");
|
|
324
|
-
结果消息.push("
|
|
323
|
+
结果消息.push("超时未发送:");
|
|
325
324
|
超时列表.forEach((bot, index) => {
|
|
326
325
|
结果消息.push(`${index + 1}. [#${bot.guildId}] ${bot.guildName}`);
|
|
327
326
|
});
|
|
@@ -332,7 +331,7 @@ function apply(ctx, config) {
|
|
|
332
331
|
}
|
|
333
332
|
}
|
|
334
333
|
__name(发送广播到群组, "发送广播到群组");
|
|
335
|
-
async function 发送广播任务(ctx2, 群列表, 广播内容, 间隔, 成功列表,
|
|
334
|
+
async function 发送广播任务(ctx2, 群列表, 广播内容, 间隔, 成功列表, 失败列表, logger2) {
|
|
336
335
|
for (let i = 0; i < 群列表.length; i++) {
|
|
337
336
|
const bot = 群列表[i];
|
|
338
337
|
try {
|
|
@@ -342,10 +341,10 @@ function apply(ctx, config) {
|
|
|
342
341
|
} else {
|
|
343
342
|
throw new Error("机器人实例不存在");
|
|
344
343
|
}
|
|
345
|
-
|
|
344
|
+
logger2.info(`广播发送成功 群号: ${bot.guildId}, 群名: ${bot.guildName}`);
|
|
346
345
|
成功列表.push({ guildId: bot.guildId, guildName: bot.guildName });
|
|
347
346
|
} catch (error) {
|
|
348
|
-
|
|
347
|
+
logger2.warn(`广播发送失败 群号: ${bot.guildId}, 群名: ${bot.guildName}, 错误: ${error.message}`);
|
|
349
348
|
失败列表.push({ guildId: bot.guildId, guildName: bot.guildName, error: error.message });
|
|
350
349
|
}
|
|
351
350
|
if (i < 群列表.length - 1) {
|
|
@@ -355,9 +354,9 @@ function apply(ctx, config) {
|
|
|
355
354
|
}
|
|
356
355
|
__name(发送广播任务, "发送广播任务");
|
|
357
356
|
ctx.on("ready", () => {
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
357
|
+
logger.info("广播插件已加载");
|
|
358
|
+
logger.info(`广播发送间隔:${config.broadcastInterval}ms`);
|
|
359
|
+
logger.info(`广播发送超时时间:${config.broadcastTimeout}秒`);
|
|
361
360
|
});
|
|
362
361
|
}
|
|
363
362
|
__name(apply, "apply");
|
|
@@ -365,6 +364,5 @@ __name(apply, "apply");
|
|
|
365
364
|
0 && (module.exports = {
|
|
366
365
|
Config,
|
|
367
366
|
apply,
|
|
368
|
-
name
|
|
369
|
-
using
|
|
367
|
+
name
|
|
370
368
|
});
|