diff --git a/api-system/internal/cron/cron.go b/api-system/internal/cron/cron.go index 2f1713c..8585ce3 100644 --- a/api-system/internal/cron/cron.go +++ b/api-system/internal/cron/cron.go @@ -25,13 +25,19 @@ func addJob(c *cron.Cron) { if _, err := c.AddFunc("@daily", RefreshUserTodayCount); err != nil { logging.L().Fatal("add cron job RefreshUserTodayCount failed", logging.Error(err)) } - if _, err := c.AddFunc("@every 2m", CheckWTNewsUpdate); err != nil { + if _, err := c.AddFunc("@every 2m", func() { + CheckWTNewsUpdate("en") + CheckWTNewsUpdate("zh") + }); err != nil { logging.L().Fatal("add cron job CheckWTNewsUpdate failed", logging.Error(err)) } logging.L().Info("all cron job add success") } func CheckRoomLiving() { + if service.IsStopAllResponse() { + return + } qcs, err := service.GetEnableCheckBiliRoomGroupConfig(true) if err != nil { logging.L().Warn("get group config checkbilibiliroom failed", logging.Error(err)) @@ -73,12 +79,15 @@ func RefreshUserTodayCount() { } } -func CheckWTNewsUpdate() { - if err := crawler.GetFirstPageNewsFromWTOfficial(func(news []table.GameNew) { +func CheckWTNewsUpdate(region string) { + if err := crawler.GetFirstPageNewsFromWTOfficial(region, func(news []table.GameNew) { for _, item := range news { found := service.MustFindGameNewByLink(item.Link) if found == nil { service.MustSaveGameNew(&item) + if service.IsStopAllResponse() { + return + } // 向配置了的群发送消息 qcs, err := service.GetEnableCheckWTNew(true) if err != nil { diff --git a/api-system/internal/data/display/display.go b/api-system/internal/data/display/display.go index ff96cf3..429ebf9 100644 --- a/api-system/internal/data/display/display.go +++ b/api-system/internal/data/display/display.go @@ -3,7 +3,7 @@ package display import ( "bytes" "github.com/axiangcoding/antonstar-bot/pkg/logging" - "html/template" + "text/template" ) func parseTemplate(templateStr string, u any) string { diff --git a/api-system/pkg/crawler/crawler.go b/api-system/pkg/crawler/crawler.go index 3b495eb..4ad92e0 100644 --- a/api-system/pkg/crawler/crawler.go +++ b/api-system/pkg/crawler/crawler.go @@ -92,8 +92,8 @@ func GetProfileFromThunderskill(nick string, callback func(status int, skill *Th return nil } -func GetFirstPageNewsFromWTOfficial(callback func(news []table.GameNew)) error { - baseUrl := "https://warthunder.com/zh/news/" +func GetFirstPageNewsFromWTOfficial(region string, callback func(news []table.GameNew)) error { + baseUrl := fmt.Sprintf("https://warthunder.com/%s/news/", region) c := colly.NewCollector( colly.AllowedDomains("warthunder.com"), colly.MaxDepth(1), diff --git a/api-system/pkg/crawler/crawler_test.go b/api-system/pkg/crawler/crawler_test.go index 87ffbd0..f8edf96 100644 --- a/api-system/pkg/crawler/crawler_test.go +++ b/api-system/pkg/crawler/crawler_test.go @@ -33,7 +33,7 @@ func TestGetProfileFromThunderskill(t *testing.T) { } func TestGetFirstPageNewsFromWTOfficial(t *testing.T) { - if err := GetFirstPageNewsFromWTOfficial(func(news []table2.GameNew) { + if err := GetFirstPageNewsFromWTOfficial("en", func(news []table2.GameNew) { fmt.Println(len(news)) for _, i := range news { fmt.Println(i)