koishi-plugin-sy-bot 0.1.1 → 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.
- package/lib/function/cronTask.d.ts +3 -2
- package/lib/index.d.ts +1 -1
- package/lib/index.js +39 -21
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
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,
|
|
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,
|
|
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
|
-
|
|
675
|
-
|
|
676
|
-
|
|
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
|
-
|
|
680
|
-
|
|
681
|
-
|
|
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.
|
|
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
|
|
736
|
+
const logger = ctx.logger;
|
|
724
737
|
ctx.on("ready", () => {
|
|
725
|
-
ctx.bots.
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
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,
|
|
734
|
-
everyDayShare({ ctx,
|
|
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:
|