2023-09-21 17:33:59 +08:00
|
|
|
package tasks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/go-co-op/gocron"
|
2023-10-11 09:21:07 +08:00
|
|
|
"go-wechat/config"
|
2024-05-15 17:19:32 +08:00
|
|
|
"go-wechat/tasks/cleargroupuser"
|
2023-11-29 10:26:02 +08:00
|
|
|
"go-wechat/tasks/friends"
|
2024-07-15 14:14:24 +08:00
|
|
|
"go-wechat/tasks/hottop"
|
2024-05-15 11:15:15 +08:00
|
|
|
"go-wechat/tasks/news"
|
2024-04-12 11:37:21 +08:00
|
|
|
"go-wechat/tasks/summary"
|
2023-11-29 10:26:02 +08:00
|
|
|
"go-wechat/tasks/watergroup"
|
2023-09-21 17:33:59 +08:00
|
|
|
"log"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// InitTasks
|
|
|
|
// @description: 初始化定时任务
|
|
|
|
func InitTasks() {
|
2023-10-11 09:21:07 +08:00
|
|
|
// 没启用直接返回
|
|
|
|
if !config.Conf.Task.Enable {
|
|
|
|
log.Println("未启用定时任务")
|
|
|
|
return
|
|
|
|
}
|
2023-09-21 17:33:59 +08:00
|
|
|
// 定时任务发送消息
|
|
|
|
s := gocron.NewScheduler(time.Local)
|
|
|
|
|
2023-10-11 09:21:07 +08:00
|
|
|
// 水群排行
|
|
|
|
if config.Conf.Task.WaterGroup.Enable {
|
2023-11-19 11:36:15 +08:00
|
|
|
log.Printf("水群排行任务已启用,执行表达式: %+v", config.Conf.Task.WaterGroup.Cron)
|
|
|
|
if config.Conf.Task.WaterGroup.Cron.Yesterday != "" {
|
2023-11-29 10:26:02 +08:00
|
|
|
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Yesterday).Do(watergroup.Yesterday)
|
2023-11-19 11:36:15 +08:00
|
|
|
}
|
|
|
|
if config.Conf.Task.WaterGroup.Cron.Week != "" {
|
2023-11-29 10:26:02 +08:00
|
|
|
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Week).Do(watergroup.Week)
|
2023-11-19 11:36:15 +08:00
|
|
|
}
|
|
|
|
if config.Conf.Task.WaterGroup.Cron.Month != "" {
|
2023-11-29 10:26:02 +08:00
|
|
|
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Month).Do(watergroup.Month)
|
2023-11-19 11:36:15 +08:00
|
|
|
}
|
2024-01-01 00:57:52 +08:00
|
|
|
if config.Conf.Task.WaterGroup.Cron.Year != "" {
|
|
|
|
_, _ = s.Cron(config.Conf.Task.WaterGroup.Cron.Year).Do(watergroup.Year)
|
|
|
|
}
|
2023-10-11 09:21:07 +08:00
|
|
|
}
|
2023-09-21 17:33:59 +08:00
|
|
|
|
2024-04-12 11:37:21 +08:00
|
|
|
// 群聊总结
|
|
|
|
if config.Conf.Task.GroupSummary.Enable {
|
|
|
|
log.Printf("群聊总结任务已启用,执行表达式: %s", config.Conf.Task.GroupSummary.Cron)
|
|
|
|
_, _ = s.Cron(config.Conf.Task.GroupSummary.Cron).Do(summary.AiSummary)
|
|
|
|
}
|
|
|
|
|
2023-10-11 09:21:07 +08:00
|
|
|
// 更新好友列表
|
|
|
|
if config.Conf.Task.SyncFriends.Enable {
|
|
|
|
log.Printf("更新好友列表任务已启用,执行表达式: %s", config.Conf.Task.SyncFriends.Cron)
|
2023-11-29 10:26:02 +08:00
|
|
|
_, _ = s.Cron(config.Conf.Task.SyncFriends.Cron).Do(friends.Sync)
|
2023-10-11 09:21:07 +08:00
|
|
|
}
|
2023-09-21 17:33:59 +08:00
|
|
|
|
2024-05-15 11:15:15 +08:00
|
|
|
// 每日早报
|
|
|
|
if config.Conf.Task.News.Enable {
|
|
|
|
_, _ = s.Cron(config.Conf.Task.News.Cron).Do(news.DailyNews)
|
|
|
|
}
|
|
|
|
|
2024-07-15 14:14:24 +08:00
|
|
|
// 热榜
|
|
|
|
if config.Conf.Task.HotTop.Enable {
|
|
|
|
_, _ = s.Cron(config.Conf.Task.HotTop.Cron).Do(hottop.HotTop)
|
|
|
|
}
|
|
|
|
|
2024-05-15 17:19:32 +08:00
|
|
|
// 每天0点检查一次处理清理群成员
|
2024-05-16 00:12:57 +08:00
|
|
|
_, _ = s.Cron("0 0 * * *").Do(cleargroupuser.ClearGroupUser)
|
2024-08-17 13:10:31 +08:00
|
|
|
// 每天0点清空AI日使用次数
|
|
|
|
_, _ = s.Cron("0 0 * * *").Do(friends.ClearAiUsedToday)
|
2024-05-15 17:19:32 +08:00
|
|
|
|
2023-09-21 17:33:59 +08:00
|
|
|
// 开启定时任务
|
|
|
|
s.StartAsync()
|
|
|
|
log.Println("定时任务初始化成功")
|
|
|
|
}
|