koishi-plugin-cat-raising 1.3.6 → 1.3.7

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 CHANGED
@@ -26,6 +26,12 @@ export interface Config {
26
26
  historySize: number;
27
27
  /** 用于发送B站弹幕的 access_key 列表 */
28
28
  biliAccessKeys: BiliAccessKeyConfig[];
29
+ /** 硬拒绝关键词列表 */
30
+ hardRejectionKeywords: string[];
31
+ /** 发送弹幕的延迟下限(秒) */
32
+ danmakuDelayMinSeconds?: number;
33
+ /** 发送弹幕的延迟上限(秒) */
34
+ danmakuDelayMaxSeconds?: number;
29
35
  }
30
36
  export declare const Config: Schema<Config>;
31
37
  /**
package/lib/index.js CHANGED
@@ -39,19 +39,30 @@ var import_koishi = require("koishi");
39
39
  var crypto = __toESM(require("crypto"));
40
40
  var import_url = require("url");
41
41
  var name = "cat-raising";
42
- var Config = import_koishi.Schema.object({
43
- targetQQ: import_koishi.Schema.string().description("目标QQ号或QQ群号").required(),
44
- isGroup: import_koishi.Schema.boolean().description("是否为QQ").default(false),
45
- monitorGroups: import_koishi.Schema.array(import_koishi.Schema.object({
46
- groupId: import_koishi.Schema.string().description("要监听的 QQ 群号").required(),
47
- sendHelperMessages: import_koishi.Schema.boolean().description("是否在此群内发送“看到啦”之类的辅助/警告消息").default(true)
48
- })).description("监听的群组列表及其配置").required(),
49
- historySize: import_koishi.Schema.number().description("用于防复读的历史记录大小,防止短期内对同一活动重复转发").default(30).min(5).max(100),
50
- biliAccessKeys: import_koishi.Schema.array(import_koishi.Schema.object({
51
- key: import_koishi.Schema.string().description("Bilibili access_key").required(),
52
- remark: import_koishi.Schema.string().description("对此 access_key 的备注,例如所属账号")
53
- })).description("用于发送B站弹幕的 access_key 列表。插件会为列表中的每个 key 发送弹幕。如果留空,则不执行发送弹幕功能。").default([])
54
- });
42
+ var Config = import_koishi.Schema.intersect([
43
+ import_koishi.Schema.object({
44
+ targetQQ: import_koishi.Schema.string().description("转发目标:填 QQ 或 群号").role("link").required(),
45
+ isGroup: import_koishi.Schema.boolean().description("目标类型:群聊则勾选").default(false)
46
+ }).description("基础设置"),
47
+ import_koishi.Schema.object({
48
+ monitorGroups: import_koishi.Schema.array(import_koishi.Schema.object({
49
+ groupId: import_koishi.Schema.string().description("监听群号").role("link").required(),
50
+ sendHelperMessages: import_koishi.Schema.boolean().description("在群内发送「直播间/主播/投稿数」等提示消息").default(true)
51
+ })).description("监听群组").required(),
52
+ historySize: import_koishi.Schema.number().description("防复读历史条数(避免短期重复转发)").role("slider", { min: 5, max: 100, step: 1 }).default(30)
53
+ }).description("监听设置"),
54
+ import_koishi.Schema.object({
55
+ biliAccessKeys: import_koishi.Schema.array(import_koishi.Schema.object({
56
+ key: import_koishi.Schema.string().description("Bilibili access_key").required(),
57
+ remark: import_koishi.Schema.string().description("备注(例如所属账号)")
58
+ })).description("弹幕账号配置(留空则不发弹幕)").default([]),
59
+ danmakuDelayMinSeconds: import_koishi.Schema.number().description("弹幕延迟下限(秒)").role("slider", { min: 0, max: 60, step: 1 }).default(8),
60
+ danmakuDelayMaxSeconds: import_koishi.Schema.number().description("弹幕延迟上限(秒)").role("slider", { min: 0, max: 60, step: 1 }).default(10)
61
+ }).description("弹幕设置"),
62
+ import_koishi.Schema.object({
63
+ hardRejectionKeywords: import_koishi.Schema.array(import_koishi.Schema.string()).description("命中则忽略的关键词(硬拒绝)").default(["发言榜单", "投稿数:", "预告"])
64
+ }).description("过滤规则")
65
+ ]);
55
66
  function preprocessChineseNumerals(text) {
56
67
  const numMap = { "零": 0, "一": 1, "二": 2, "两": 2, "三": 3, "四": 4, "五": 5, "六": 6, "七": 7, "八": 8, "九": 9 };
57
68
  const unitMap = {
@@ -151,7 +162,6 @@ function parseEventFromText(text) {
151
162
  return allRewards.length > 0 ? { dateTime: globalDateTime || "时间未知", rewards: allRewards } : null;
152
163
  }
153
164
  __name(parseEventFromText, "parseEventFromText");
154
- var HARD_REJECTION_KEYWORDS = ["发言榜单", "投稿数:"];
155
165
  var REJECTION_KEYWORDS = ["签到", "打卡"];
156
166
  var OVERRIDE_KEYWORDS = ["神金", "发"];
157
167
  var CHECK_IN_REJECTION_REGEX = /\b\d{2,3}\s*\+/;
@@ -310,7 +320,7 @@ function apply(ctx, config) {
310
320
  if (!groupConfig) return;
311
321
  const strippedContent = session.stripped.content;
312
322
  if (!strippedContent.trim()) return;
313
- if (HARD_REJECTION_KEYWORDS.some((keyword) => strippedContent.includes(keyword))) return;
323
+ if (config.hardRejectionKeywords.some((keyword) => strippedContent.includes(keyword))) return;
314
324
  if (CHECK_IN_REJECTION_REGEX.test(strippedContent)) {
315
325
  ctx.logger.info(`[忽略] 消息包含签到模式 (如 110+),判定为非奖励信息。内容: "${strippedContent.replace(/\n/g, " ")}"`);
316
326
  return;
@@ -366,11 +376,16 @@ function apply(ctx, config) {
366
376
  });
367
377
  if (forwardedHistory.length > config.historySize) forwardedHistory.shift();
368
378
  if (config.biliAccessKeys && config.biliAccessKeys.length > 0) {
369
- ctx.logger.info(`[弹幕] 准备为 ${config.biliAccessKeys.length} 个账号发送弹幕到直播间 ${roomId}...`);
370
- const danmakuPromises = config.biliAccessKeys.map(
371
- (keyConfig) => sendBilibiliDanmaku(ctx, keyConfig, roomId, "喵喵喵")
372
- );
373
- Promise.allSettled(danmakuPromises);
379
+ const min = Math.max(0, config.danmakuDelayMinSeconds ?? 8);
380
+ const max = Math.max(min, config.danmakuDelayMaxSeconds ?? 10);
381
+ const delayMs = (Math.floor(Math.random() * (max - min + 1)) + min) * 1e3;
382
+ ctx.logger.info(`[弹幕] ${config.biliAccessKeys.length} 个账号将于 ${Math.round(delayMs / 1e3)} 秒后发送弹幕到直播间 ${roomId}。`);
383
+ setTimeout(() => {
384
+ const danmakuPromises = config.biliAccessKeys.map(
385
+ (keyConfig) => sendBilibiliDanmaku(ctx, keyConfig, roomId, "喵喵喵")
386
+ );
387
+ Promise.allSettled(danmakuPromises);
388
+ }, delayMs);
374
389
  }
375
390
  } catch (error) {
376
391
  session.send("🐱 - 转发失败,请检查目标QQ/群号配置是否正确");
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-cat-raising",
3
3
  "description": "",
4
- "version": "1.3.6",
4
+ "version": "1.3.7",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [