koishi-plugin-sy-bot 0.1.0 → 0.1.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.
@@ -1,5 +1,6 @@
1
- export declare function cronTask({ ctx, bot, config }: {
1
+ export declare function cronTask({ ctx, config, logger, platform }: {
2
2
  ctx: any;
3
- bot: any;
4
3
  config: any;
4
+ logger: any;
5
+ platform: any;
5
6
  }): Promise<void>;
package/lib/index.d.ts CHANGED
@@ -8,7 +8,7 @@ export interface Config {
8
8
  api: string;
9
9
  model: string;
10
10
  prompt: string;
11
- guild: number;
11
+ guild: string;
12
12
  user: string;
13
13
  dailyShares: Array<object>;
14
14
  tasks: Task[];
package/lib/index.js CHANGED
@@ -632,7 +632,8 @@ async function everyDayShare(obj) {
632
632
  }
633
633
  __name(everyDayShare, "everyDayShare");
634
634
  function registerCronShare(obj) {
635
- const { ctx, bot, config, time, beforeTip, user_query, system_prompt } = obj;
635
+ const { ctx, config, platform, time, beforeTip, user_query, system_prompt } = obj;
636
+ const bot = ctx.bots.filter((bot2) => bot2.platform == platform)[0];
636
637
  ctx.cron(time, async () => {
637
638
  const logger = ctx.logger;
638
639
  beforeTip && await bot.sendMessage(config.guild, beforeTip);
@@ -658,9 +659,9 @@ function registerCronShare(obj) {
658
659
  __name(registerCronShare, "registerCronShare");
659
660
 
660
661
  // src/function/cronTask.tsx
661
- async function cronTask({ ctx, bot, config }) {
662
- const logger = ctx.logger;
662
+ async function cronTask({ ctx, config, logger, platform }) {
663
663
  for (const task of config.tasks) {
664
+ const bot = ctx.bots.filter((bot2) => bot2.platform == platform)[0];
664
665
  const {
665
666
  startTime,
666
667
  endTime,
@@ -670,15 +671,29 @@ async function cronTask({ ctx, bot, config }) {
670
671
  unlockName,
671
672
  ifMute
672
673
  } = task;
674
+ logger.info(`cron 定时任务加载中:
675
+ `, startTime + `
676
+ `, endTime);
673
677
  ctx.cron(startTime, async () => {
674
- await bot.sendMessage(config.guild.toString(), beforeTip);
675
- await bot.muteChannel(config.guild.toString(), ifMute);
676
- await bot.internal.setGroupName(config.guild, lockName);
678
+ try {
679
+ logger.info(`执行 cron 任务:`, task);
680
+ await bot.sendMessage(config.guild, beforeTip);
681
+ logger.info(`是否禁言:${ifMute} 类型: ${typeof ifMute}`);
682
+ await bot.internal.setGroupWholeMute(Number(config.guild), ifMute);
683
+ await bot.internal.setGroupName(Number(config.guild), lockName);
684
+ } catch (error) {
685
+ logger.error(`Cron 结束任务执行失败: ${error.message}`);
686
+ }
677
687
  });
678
688
  ctx.cron(endTime, async () => {
679
- await bot.sendMessage(config.guild.toString(), afterTip);
680
- await bot.muteChannel(config.guild.toString(), false);
681
- await bot.internal.setGroupName(config.guild, unlockName);
689
+ try {
690
+ logger.info(`执行 cron 任务:`, task);
691
+ await bot.sendMessage(config.guild, afterTip);
692
+ await bot.internal.setGroupWholeMute(Number(config.guild), false);
693
+ await bot.internal.setGroupName(Number(config.guild), unlockName);
694
+ } catch (error) {
695
+ logger.error(`Cron 结束任务执行失败: ${error.message}`);
696
+ }
682
697
  });
683
698
  }
684
699
  }
@@ -700,14 +715,12 @@ var Config = import_koishi3.Schema.object({
700
715
  afterTip: import_koishi3.Schema.string().description("解放公告").role("textarea"),
701
716
  lockName: import_koishi3.Schema.string().description("开始群名"),
702
717
  unlockName: import_koishi3.Schema.string().description("解放群名"),
703
- ifMute: import_koishi3.Schema.boolean().description("禁言")
718
+ ifMute: import_koishi3.Schema.boolean().default(false).description("禁言")
704
719
  })
705
720
  ).description("定时禁言任务列表"),
706
721
  model: import_koishi3.Schema.string().required().description("模型名称(必填)"),
707
722
  prompt: import_koishi3.Schema.string().description("预设系统提示词(可以留空)"),
708
- guild: import_koishi3.Schema.number().required().description(
709
- "在目标群聊启用,留空表示广播所有群聊(填入QQ群号)"
710
- ),
723
+ guild: import_koishi3.Schema.string().required().description("在目标群聊启用,留空表示广播所有群聊(填入QQ群号)"),
711
724
  user: import_koishi3.Schema.string().required().description("在目标用户启用(填入管理员QQ号)"),
712
725
  dailyShares: import_koishi3.Schema.array(
713
726
  import_koishi3.Schema.object({
@@ -720,18 +733,23 @@ var Config = import_koishi3.Schema.object({
720
733
  });
721
734
  function apply(ctx, config) {
722
735
  const platform = `milky`;
723
- const bot = ctx.bots.filter((bot2) => bot2.platform == platform)[0];
736
+ const logger = ctx.logger;
724
737
  ctx.on("ready", () => {
725
- ctx.bots.forEach((bot2) => {
726
- ctx.logger.info("milky_bot:", bot2.platform);
727
- ctx.logger.info("milky_bot:", bot2.selfId);
728
- ctx.logger.info("milky_bot 加载成功!");
729
- });
738
+ const bots = ctx.bots.filter((b) => b.platform === platform);
739
+ if (bots.length === 0) {
740
+ logger.warn(
741
+ `未找到平台为 ${platform} 的机器人,请检查配置或登录状态。`
742
+ );
743
+ } else {
744
+ bots.forEach((bot) => {
745
+ logger.info(`Bot loaded: ${bot.platform} - ${bot.selfId}`);
746
+ });
747
+ }
730
748
  });
731
749
  registerCommand(ctx, config);
732
750
  registerTables(ctx);
733
- cronTask({ ctx, bot, config });
734
- everyDayShare({ ctx, bot, config });
751
+ cronTask({ ctx, config, logger, platform });
752
+ everyDayShare({ ctx, config });
735
753
  }
736
754
  __name(apply, "apply");
737
755
  // Annotate the CommonJS export names for ESM import in node:
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "koishi-plugin-sy-bot",
3
3
  "description": "考研群答疑Bot,接入Gemini。",
4
- "version": "0.1.0",
4
+ "version": "0.1.2",
5
5
  "main": "lib/index.js",
6
6
  "typings": "lib/index.d.ts",
7
7
  "files": [