go-wxhelper/tasks/news/news.go

37 lines
789 B
Go
Raw Permalink Normal View History

2024-05-15 11:15:15 +08:00
package news
import (
"fmt"
"go-wechat/service"
"go-wechat/utils"
"log"
"strings"
"time"
)
// DailyNews
// @description: 每日新闻
func DailyNews() {
groups, err := service.GetAllEnableNews()
if err != nil {
log.Printf("获取启用了聊天排行榜的群组失败, 错误信息: %v", err)
return
}
news := utils.NewsUtil().MorningPost()
if len(news) == 0 {
log.Println("每日早报获取失败")
return
}
2024-07-05 09:06:38 +08:00
newsStr := fmt.Sprintf("#每日早报\n\n又是新的一天了让我们康康一觉醒来世界又发生了哪些变化~\n\n%s", strings.Join(news, "\n \n"))
2024-05-15 11:15:15 +08:00
// 循环发送新闻
for _, group := range groups {
// 发送消息
utils.SendMessage(group.Wxid, "", newsStr, 0)
// 休眠一秒,防止频繁发送
time.Sleep(time.Second)
}
}