mirror of
https://github.com/FloatTech/ZeroBot-Plugin.git
synced 2026-01-18 06:10:31 +00:00
feat(aichat): agent reduce log evs (#1260)
This commit is contained in:
parent
d14e1be92b
commit
b432731c9b
4
go.mod
4
go.mod
@ -12,7 +12,7 @@ require (
|
|||||||
github.com/FloatTech/sqlite v1.7.2
|
github.com/FloatTech/sqlite v1.7.2
|
||||||
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d
|
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d
|
||||||
github.com/FloatTech/zbpctrl v1.7.1
|
github.com/FloatTech/zbpctrl v1.7.1
|
||||||
github.com/FloatTech/zbputils v1.7.2-0.20260108160028-ff0902a05ebd
|
github.com/FloatTech/zbputils v1.7.2-0.20260109060005-2922571e6c7e
|
||||||
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
|
github.com/RomiChan/syncx v0.0.0-20240418144900-b7402ffdebc7
|
||||||
github.com/RomiChan/websocket v1.4.3-0.20251002072000-d3eb41798438
|
github.com/RomiChan/websocket v1.4.3-0.20251002072000-d3eb41798438
|
||||||
github.com/Tnze/go-mc v1.20.2
|
github.com/Tnze/go-mc v1.20.2
|
||||||
@ -27,7 +27,6 @@ require (
|
|||||||
github.com/fumiama/go-onebot-agent v0.0.0-20260106161505-f7d25272034c
|
github.com/fumiama/go-onebot-agent v0.0.0-20260106161505-f7d25272034c
|
||||||
github.com/fumiama/go-registry v0.2.7
|
github.com/fumiama/go-registry v0.2.7
|
||||||
github.com/fumiama/gotracemoe v0.0.3
|
github.com/fumiama/gotracemoe v0.0.3
|
||||||
github.com/fumiama/imgsz v0.0.4
|
|
||||||
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
|
github.com/fumiama/jieba v0.0.0-20221203025406-36c17a10b565
|
||||||
github.com/fumiama/slowdo v0.0.0-20241001074058-27c4fe5259a4
|
github.com/fumiama/slowdo v0.0.0-20241001074058-27c4fe5259a4
|
||||||
github.com/fumiama/terasu v1.0.2
|
github.com/fumiama/terasu v1.0.2
|
||||||
@ -66,6 +65,7 @@ require (
|
|||||||
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
|
github.com/ericpauley/go-quantize v0.0.0-20200331213906-ae555eb2afa4 // indirect
|
||||||
github.com/fumiama/go-simple-protobuf v0.2.0 // indirect
|
github.com/fumiama/go-simple-protobuf v0.2.0 // indirect
|
||||||
github.com/fumiama/gofastTEA v0.1.3 // indirect
|
github.com/fumiama/gofastTEA v0.1.3 // indirect
|
||||||
|
github.com/fumiama/imgsz v0.0.4 // indirect
|
||||||
github.com/fumiama/orbyte v0.0.0-20251002065953-3bb358367eb5 // indirect
|
github.com/fumiama/orbyte v0.0.0-20251002065953-3bb358367eb5 // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.12 // indirect
|
||||||
github.com/go-ole/go-ole v1.2.6 // indirect
|
github.com/go-ole/go-ole v1.2.6 // indirect
|
||||||
|
|||||||
4
go.sum
4
go.sum
@ -16,8 +16,8 @@ github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d h1:mUQ/c3wXKsUGa4Sg9
|
|||||||
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
github.com/FloatTech/ttl v0.0.0-20250224045156-012b1463287d/go.mod h1:fHZFWGquNXuHttu9dUYoKuNbm3dzLETnIOnm1muSfDs=
|
||||||
github.com/FloatTech/zbpctrl v1.7.1 h1:0yPEmCForhyMbnhTckmjDUFFDZgQp1RjO2bVF4ZVqOs=
|
github.com/FloatTech/zbpctrl v1.7.1 h1:0yPEmCForhyMbnhTckmjDUFFDZgQp1RjO2bVF4ZVqOs=
|
||||||
github.com/FloatTech/zbpctrl v1.7.1/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE=
|
github.com/FloatTech/zbpctrl v1.7.1/go.mod h1:xmM4dSwHA02Gei3ogCRiG+RTrw/7Z69PfrN5NYf8BPE=
|
||||||
github.com/FloatTech/zbputils v1.7.2-0.20260108160028-ff0902a05ebd h1:6wjYpYyG294ja2dFnDbnbDlQdz8azGAxQibeOJNpORc=
|
github.com/FloatTech/zbputils v1.7.2-0.20260109060005-2922571e6c7e h1:nyoWiWc3kWtbQWgx5BAgOGCNAACC6H5wm+7rhEupj98=
|
||||||
github.com/FloatTech/zbputils v1.7.2-0.20260108160028-ff0902a05ebd/go.mod h1:yLJvsQJssgQIB4+/uVRNseN4sgFqyfGQLcrKUuXL454=
|
github.com/FloatTech/zbputils v1.7.2-0.20260109060005-2922571e6c7e/go.mod h1:yLJvsQJssgQIB4+/uVRNseN4sgFqyfGQLcrKUuXL454=
|
||||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||||
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
|
||||||
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
github.com/PuerkitoBio/goquery v1.8.0/go.mod h1:ypIiRMtY7COPGk+I/YbZLbxsxn9g5ejnI2HSMtkjZvI=
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
package aichat
|
package aichat
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -123,6 +124,7 @@ func init() {
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
hasresp = true
|
hasresp = true
|
||||||
|
ctx.State[zero.StateKeyPrefixKeep+"_chat_ag_triggered__"] = struct{}{}
|
||||||
for _, req := range reqs {
|
for _, req := range reqs {
|
||||||
if req.Action == goba.SVM { // is a fake action
|
if req.Action == goba.SVM { // is a fake action
|
||||||
if hassavemem {
|
if hassavemem {
|
||||||
@ -141,7 +143,17 @@ func init() {
|
|||||||
}
|
}
|
||||||
ispuremsg = true
|
ispuremsg = true
|
||||||
}
|
}
|
||||||
_ = ctx.CallAction(req.Action, req.Params)
|
logrus.Debugln("[chat] agent triggered", gid, "add requ:", &req)
|
||||||
|
ag.AddRequest(gid, &req)
|
||||||
|
rsp := ctx.CallAction(req.Action, req.Params)
|
||||||
|
logrus.Debugln("[chat] agent triggered", gid, "add resp:", &rsp)
|
||||||
|
ag.AddResponse(gid, &goba.APIResponse{
|
||||||
|
Status: rsp.Status,
|
||||||
|
Data: json.RawMessage(rsp.Data.Raw),
|
||||||
|
Message: rsp.Message,
|
||||||
|
Wording: rsp.Wording,
|
||||||
|
RetCode: rsp.RetCode,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if hasresp {
|
if hasresp {
|
||||||
@ -177,7 +189,7 @@ func init() {
|
|||||||
if t == "" {
|
if t == "" {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
logrus.Infoln("[aichat] 回复内容:", t)
|
logrus.Debugln("[aichat] 回复内容:", t)
|
||||||
recCfg := airecord.GetConfig()
|
recCfg := airecord.GetConfig()
|
||||||
record := ""
|
record := ""
|
||||||
if !fastfailnorecord && !stor.NoRecord() {
|
if !fastfailnorecord && !stor.NoRecord() {
|
||||||
|
|||||||
@ -3,7 +3,6 @@ package crypter
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/FloatTech/AnimeAPI/airecord"
|
"github.com/FloatTech/AnimeAPI/airecord"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
zero "github.com/wdvxdr1123/ZeroBot"
|
zero "github.com/wdvxdr1123/ZeroBot"
|
||||||
"github.com/wdvxdr1123/ZeroBot/message"
|
"github.com/wdvxdr1123/ZeroBot/message"
|
||||||
)
|
)
|
||||||
@ -12,7 +11,6 @@ import (
|
|||||||
func houEncryptHandler(ctx *zero.Ctx) {
|
func houEncryptHandler(ctx *zero.Ctx) {
|
||||||
text := ctx.State["regex_matched"].([]string)[1]
|
text := ctx.State["regex_matched"].([]string)[1]
|
||||||
result := encodeHou(text)
|
result := encodeHou(text)
|
||||||
logrus.Infoln("[crypter] 回复内容:", result)
|
|
||||||
recCfg := airecord.GetConfig()
|
recCfg := airecord.GetConfig()
|
||||||
record := ctx.GetAIRecord(recCfg.ModelID, recCfg.Customgid, result)
|
record := ctx.GetAIRecord(recCfg.ModelID, recCfg.Customgid, result)
|
||||||
if record != "" {
|
if record != "" {
|
||||||
|
|||||||
@ -36,7 +36,7 @@ var (
|
|||||||
lotsList = func() map[string]info {
|
lotsList = func() map[string]info {
|
||||||
lotsList, err := getList()
|
lotsList, err := getList()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Infoln("[drawlots]加载失败:", err)
|
logrus.Infoln("[drawlots]加载失败:", err, "(如果从未使用过该插件, 这是正常现象)")
|
||||||
} else {
|
} else {
|
||||||
logrus.Infoln("[drawlots]加载", len(lotsList), "个抽签")
|
logrus.Infoln("[drawlots]加载", len(lotsList), "个抽签")
|
||||||
}
|
}
|
||||||
|
|||||||
@ -11,8 +11,6 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
|
|
||||||
"github.com/FloatTech/floatbox/file"
|
"github.com/FloatTech/floatbox/file"
|
||||||
"github.com/FloatTech/zbputils/ctxext"
|
"github.com/FloatTech/zbputils/ctxext"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
@ -30,7 +28,7 @@ func init() {
|
|||||||
var err1 error
|
var err1 error
|
||||||
t2s, err1 = gocc.New("t2s")
|
t2s, err1 = gocc.New("t2s")
|
||||||
if err1 != nil {
|
if err1 != nil {
|
||||||
log.Infof("[guessmusic]:%s", err1)
|
panic(err1)
|
||||||
}
|
}
|
||||||
|
|
||||||
engine.OnRegex(`^(个人|团队)猜歌(-(.*))?$`, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByGroup).
|
engine.OnRegex(`^(个人|团队)猜歌(-(.*))?$`, zero.OnlyGroup).SetBlock(true).Limit(ctxext.LimitByGroup).
|
||||||
|
|||||||
@ -3,8 +3,9 @@ package minecraftobserver
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/jinzhu/gorm"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/jinzhu/gorm"
|
||||||
)
|
)
|
||||||
|
|
||||||
func cleanTestData(t *testing.T) {
|
func cleanTestData(t *testing.T) {
|
||||||
|
|||||||
@ -28,7 +28,7 @@ func (repo *RssDomain) syncRss(ctx context.Context) (updated map[int64]*RssClien
|
|||||||
feed, err = repo.rssHubClient.FetchFeed(channel.RssHubFeedPath)
|
feed, err = repo.rssHubClient.FetchFeed(channel.RssHubFeedPath)
|
||||||
// 如果获取失败,则跳过
|
// 如果获取失败,则跳过
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] fetch path(%+v) error: %v", channel.RssHubFeedPath, err)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] fetch path(%+v) error: %v", channel.RssHubFeedPath, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
rv := convertFeedToRssView(0, channel.RssHubFeedPath, feed)
|
rv := convertFeedToRssView(0, channel.RssHubFeedPath, feed)
|
||||||
@ -42,27 +42,27 @@ func (repo *RssDomain) syncRss(ctx context.Context) (updated map[int64]*RssClien
|
|||||||
var needUpdate bool
|
var needUpdate bool
|
||||||
needUpdate, err = repo.checkSourceNeedUpdate(ctx, cv.Source)
|
needUpdate, err = repo.checkSourceNeedUpdate(ctx, cv.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] checkSourceNeedUpdate error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] checkSourceNeedUpdate error: %v", err)
|
||||||
err = nil
|
err = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
// 保存
|
// 保存
|
||||||
logrus.WithContext(ctx).Infof("[rsshub syncRss] cv %+v, need update(real): %v", cv.Source, needUpdate)
|
logrus.WithContext(ctx).Debugf("[rsshub syncRss] cv %+v, need update(real): %v", cv.Source, needUpdate)
|
||||||
// 如果需要更新,更新channel 和 content
|
// 如果需要更新,更新channel 和 content
|
||||||
if needUpdate {
|
if needUpdate {
|
||||||
err = repo.storage.UpsertSource(ctx, cv.Source)
|
err = repo.storage.UpsertSource(ctx, cv.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] upsert source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] upsert source error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var updateChannelView = &RssClientView{Source: cv.Source, Contents: []*RssContent{}}
|
var updateChannelView = &RssClientView{Source: cv.Source, Contents: []*RssContent{}}
|
||||||
err = repo.processContentsUpdate(ctx, cv, updateChannelView)
|
err = repo.processContentsUpdate(ctx, cv, updateChannelView)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] processContentsUpdate error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] processContentsUpdate error: %v", err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if len(updateChannelView.Contents) == 0 {
|
if len(updateChannelView.Contents) == 0 {
|
||||||
logrus.WithContext(ctx).Infof("[rsshub syncRss] cv %s, no new content", cv.Source.RssHubFeedPath)
|
logrus.WithContext(ctx).Debugf("[rsshub syncRss] cv %s, no new content", cv.Source.RssHubFeedPath)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
updateChannelView.Sort()
|
updateChannelView.Sort()
|
||||||
@ -80,7 +80,7 @@ func (repo *RssDomain) checkSourceNeedUpdate(ctx context.Context, source *RssSou
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
if sourceInDB == nil {
|
if sourceInDB == nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] source not found: %v", source.RssHubFeedPath)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] source not found: %v", source.RssHubFeedPath)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
source.ID = sourceInDB.ID
|
source.ID = sourceInDB.ID
|
||||||
@ -102,13 +102,13 @@ func (repo *RssDomain) processContentsUpdate(ctx context.Context, cv *RssClientV
|
|||||||
var existed bool
|
var existed bool
|
||||||
existed, err = repo.processContentItemUpdate(ctx, content)
|
existed, err = repo.processContentItemUpdate(ctx, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] upsert content error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] upsert content error: %v", err)
|
||||||
err = nil
|
err = nil
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !existed {
|
if !existed {
|
||||||
updateChannelView.Contents = append(updateChannelView.Contents, content)
|
updateChannelView.Contents = append(updateChannelView.Contents, content)
|
||||||
logrus.WithContext(ctx).Infof("[rsshub syncRss] cv %s, add new content: %v", cv.Source.RssHubFeedPath, content.Title)
|
logrus.WithContext(ctx).Debugf("[rsshub syncRss] cv %s, add new content: %v", cv.Source.RssHubFeedPath, content.Title)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
@ -127,7 +127,7 @@ func (repo *RssDomain) processContentItemUpdate(ctx context.Context, content *Rs
|
|||||||
// 保存
|
// 保存
|
||||||
err = repo.storage.UpsertContent(ctx, content)
|
err = repo.storage.UpsertContent(ctx, content)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub syncRss] upsert content error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub syncRss] upsert content error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
@ -36,11 +36,11 @@ func (c *RssHubClient) FetchFeed(path string) (feed *gofeed.Feed, err error) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("[rsshub FetchFeed] fetch feed error: %v", err)
|
logrus.Warnf("[rsshub FetchFeed] fetch feed error: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if len(data) == 0 {
|
if len(data) == 0 {
|
||||||
logrus.Errorf("[rsshub FetchFeed] fetch feed error: data is empty")
|
logrus.Warnf("[rsshub FetchFeed] fetch feed error: data is empty")
|
||||||
return nil, errors.New("feed data is empty")
|
return nil, errors.New("feed data is empty")
|
||||||
}
|
}
|
||||||
feed, err = gofeed.NewParser().Parse(bytes.NewBuffer(data))
|
feed, err = gofeed.NewParser().Parse(bytes.NewBuffer(data))
|
||||||
|
|||||||
@ -33,7 +33,7 @@ func newRssDomain(dbPath string) (*RssDomain, error) {
|
|||||||
}
|
}
|
||||||
orm, err := gorm.Open("sqlite3", dbPath)
|
orm, err := gorm.Open("sqlite3", dbPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("[rsshub NewRssDomain] open db error: %v", err)
|
logrus.Warnf("[rsshub NewRssDomain] open db error: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
repo := &RssDomain{
|
repo := &RssDomain{
|
||||||
@ -42,7 +42,7 @@ func newRssDomain(dbPath string) (*RssDomain, error) {
|
|||||||
}
|
}
|
||||||
err = repo.storage.initDB()
|
err = repo.storage.initDB()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("[rsshub NewRssDomain] open db error: %v", err)
|
logrus.Warnf("[rsshub NewRssDomain] open db error: %v", err)
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return repo, nil
|
return repo, nil
|
||||||
@ -54,15 +54,15 @@ func (repo *RssDomain) Subscribe(ctx context.Context, gid int64, feedPath string
|
|||||||
// 验证
|
// 验证
|
||||||
feed, err := repo.rssHubClient.FetchFeed(feedPath)
|
feed, err := repo.rssHubClient.FetchFeed(feedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] add source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] add source error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Subscribe] try get source success: %v", len(feed.Title))
|
logrus.WithContext(ctx).Debugf("[rsshub Subscribe] try get source success: %v", len(feed.Title))
|
||||||
// 新建source结构体
|
// 新建source结构体
|
||||||
rv = convertFeedToRssView(0, feedPath, feed)
|
rv = convertFeedToRssView(0, feedPath, feed)
|
||||||
feedChannel, err := repo.storage.GetSourceByRssHubFeedLink(ctx, feedPath)
|
feedChannel, err := repo.storage.GetSourceByRssHubFeedLink(ctx, feedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] query source by feedPath error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] query source by feedPath error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 如果已经存在
|
// 如果已经存在
|
||||||
@ -76,30 +76,30 @@ func (repo *RssDomain) Subscribe(ctx context.Context, gid int64, feedPath string
|
|||||||
// 保存
|
// 保存
|
||||||
err = repo.storage.UpsertSource(ctx, rv.Source)
|
err = repo.storage.UpsertSource(ctx, rv.Source)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] save source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] save source error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Infof("[rsshub Subscribe] save/update source success %v", rv.Source.ID)
|
logrus.Debugf("[rsshub Subscribe] save/update source success %v", rv.Source.ID)
|
||||||
// 添加群号到订阅
|
// 添加群号到订阅
|
||||||
subscribe, err := repo.storage.GetSubscribeByID(ctx, gid, rv.Source.ID)
|
subscribe, err := repo.storage.GetSubscribeByID(ctx, gid, rv.Source.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] query subscribe error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] query subscribe error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Subscribe] query subscribe success: %v", subscribe)
|
logrus.WithContext(ctx).Debugf("[rsshub Subscribe] query subscribe success: %v", subscribe)
|
||||||
// 如果已经存在,直接返回
|
// 如果已经存在,直接返回
|
||||||
if subscribe != nil {
|
if subscribe != nil {
|
||||||
isSubExisted = true
|
isSubExisted = true
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Subscribe] subscribe existed: %v", subscribe)
|
logrus.WithContext(ctx).Debugf("[rsshub Subscribe] subscribe existed: %v", subscribe)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 如果不存在,保存
|
// 如果不存在,保存
|
||||||
err = repo.storage.CreateSubscribe(ctx, gid, rv.Source.ID)
|
err = repo.storage.CreateSubscribe(ctx, gid, rv.Source.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] save subscribe error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] save subscribe error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Subscribe] success: %v", len(rv.Contents))
|
logrus.WithContext(ctx).Debugf("[rsshub Subscribe] success: %v", len(rv.Contents))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,31 +107,31 @@ func (repo *RssDomain) Subscribe(ctx context.Context, gid int64, feedPath string
|
|||||||
func (repo *RssDomain) Unsubscribe(ctx context.Context, gid int64, feedPath string) (err error) {
|
func (repo *RssDomain) Unsubscribe(ctx context.Context, gid int64, feedPath string) (err error) {
|
||||||
existedSubscribes, ifExisted, err := repo.storage.GetIfExistedSubscribe(ctx, gid, feedPath)
|
existedSubscribes, ifExisted, err := repo.storage.GetIfExistedSubscribe(ctx, gid, feedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] query sub by route error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] query sub by route error: %v", err)
|
||||||
return errors.New("数据库错误")
|
return errors.New("数据库错误")
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Subscribe] query source by route success: %v", existedSubscribes)
|
logrus.WithContext(ctx).Debugf("[rsshub Subscribe] query source by route success: %v", existedSubscribes)
|
||||||
// 如果不存在订阅关系,直接返回
|
// 如果不存在订阅关系,直接返回
|
||||||
if !ifExisted || existedSubscribes == nil {
|
if !ifExisted || existedSubscribes == nil {
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Subscribe] source existed: %v", ifExisted)
|
logrus.WithContext(ctx).Debugf("[rsshub Subscribe] source existed: %v", ifExisted)
|
||||||
return errors.New("频道不存在")
|
return errors.New("频道不存在")
|
||||||
}
|
}
|
||||||
err = repo.storage.DeleteSubscribe(ctx, existedSubscribes.ID)
|
err = repo.storage.DeleteSubscribe(ctx, existedSubscribes.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] delete source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] delete source error: %v", err)
|
||||||
return errors.New("删除失败")
|
return errors.New("删除失败")
|
||||||
}
|
}
|
||||||
// 查询是否还有群订阅这个频道
|
// 查询是否还有群订阅这个频道
|
||||||
subscribesNeedsToDel, err := repo.storage.GetSubscribesBySource(ctx, feedPath)
|
subscribesNeedsToDel, err := repo.storage.GetSubscribesBySource(ctx, feedPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] query source by route error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] query source by route error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 没有群订阅的时候,把频道删除
|
// 没有群订阅的时候,把频道删除
|
||||||
if len(subscribesNeedsToDel) == 0 {
|
if len(subscribesNeedsToDel) == 0 {
|
||||||
err = repo.storage.DeleteSource(ctx, existedSubscribes.RssSourceID)
|
err = repo.storage.DeleteSource(ctx, existedSubscribes.RssSourceID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Subscribe] delete source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Subscribe] delete source error: %v", err)
|
||||||
return errors.New("清除频道信息失败")
|
return errors.New("清除频道信息失败")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,11 +142,11 @@ func (repo *RssDomain) Unsubscribe(ctx context.Context, gid int64, feedPath stri
|
|||||||
func (repo *RssDomain) GetSubscribedChannelsByGroupID(ctx context.Context, gid int64) ([]*RssClientView, error) {
|
func (repo *RssDomain) GetSubscribedChannelsByGroupID(ctx context.Context, gid int64) ([]*RssClientView, error) {
|
||||||
channels, err := repo.storage.GetSubscribedChannelsByGroupID(ctx, gid)
|
channels, err := repo.storage.GetSubscribedChannelsByGroupID(ctx, gid)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub GetSubscribedChannelsByGroupID] GetSubscribedChannelsByGroupID error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub GetSubscribedChannelsByGroupID] GetSubscribedChannelsByGroupID error: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
rv := make([]*RssClientView, len(channels))
|
rv := make([]*RssClientView, len(channels))
|
||||||
logrus.WithContext(ctx).Infof("[rsshub GetSubscribedChannelsByGroupID] query subscribe success: %v", len(channels))
|
logrus.WithContext(ctx).Debugf("[rsshub GetSubscribedChannelsByGroupID] query subscribe success: %v", len(channels))
|
||||||
for i, cn := range channels {
|
for i, cn := range channels {
|
||||||
rv[i] = &RssClientView{
|
rv[i] = &RssClientView{
|
||||||
Source: cn,
|
Source: cn,
|
||||||
@ -162,13 +162,13 @@ func (repo *RssDomain) Sync(ctx context.Context) (groupView map[int64][]*RssClie
|
|||||||
// 获取所有频道
|
// 获取所有频道
|
||||||
updatedViews, err := repo.syncRss(ctx)
|
updatedViews, err := repo.syncRss(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Sync] sync rss feed error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Sync] sync rss feed error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Infof("[rsshub Sync] updated channels: %v", len(updatedViews))
|
logrus.WithContext(ctx).Debugf("[rsshub Sync] updated channels: %v", len(updatedViews))
|
||||||
subscribes, err := repo.storage.GetSubscribes(ctx)
|
subscribes, err := repo.storage.GetSubscribes(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub Sync] get subscribes error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub Sync] get subscribes error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
for _, subscribe := range subscribes {
|
for _, subscribe := range subscribes {
|
||||||
|
|||||||
@ -19,7 +19,7 @@ type repoStorage struct {
|
|||||||
func (s *repoStorage) initDB() (err error) {
|
func (s *repoStorage) initDB() (err error) {
|
||||||
err = s.orm.AutoMigrate(&RssSource{}, &RssContent{}, &RssSubscribe{}).Error
|
err = s.orm.AutoMigrate(&RssSource{}, &RssContent{}, &RssSubscribe{}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("[rsshub initDB] error: %v", err)
|
logrus.Warnf("[rsshub initDB] error: %v", err)
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -28,7 +28,7 @@ func (s *repoStorage) initDB() (err error) {
|
|||||||
|
|
||||||
// GetSubscribesBySource Impl
|
// GetSubscribesBySource Impl
|
||||||
func (s *repoStorage) GetSubscribesBySource(ctx context.Context, feedPath string) ([]*RssSubscribe, error) {
|
func (s *repoStorage) GetSubscribesBySource(ctx context.Context, feedPath string) ([]*RssSubscribe, error) {
|
||||||
logrus.WithContext(ctx).Infof("[rsshub GetSubscribesBySource] feedPath: %s", feedPath)
|
logrus.WithContext(ctx).Debugf("[rsshub GetSubscribesBySource] feedPath: %s", feedPath)
|
||||||
rs := make([]*RssSubscribe, 0)
|
rs := make([]*RssSubscribe, 0)
|
||||||
err := s.orm.Model(&RssSubscribe{}).Joins(fmt.Sprintf("%s left join %s on %s.rss_source_id=%s.id", tableNameRssSubscribe, tableNameRssSource, tableNameRssSubscribe, tableNameRssSource)).
|
err := s.orm.Model(&RssSubscribe{}).Joins(fmt.Sprintf("%s left join %s on %s.rss_source_id=%s.id", tableNameRssSubscribe, tableNameRssSource, tableNameRssSubscribe, tableNameRssSource)).
|
||||||
Where("rss_source.rss_hub_feed_path = ?", feedPath).Select("rss_subscribe.*").Find(&rs).Error
|
Where("rss_source.rss_hub_feed_path = ?", feedPath).Select("rss_subscribe.*").Find(&rs).Error
|
||||||
@ -36,7 +36,7 @@ func (s *repoStorage) GetSubscribesBySource(ctx context.Context, feedPath string
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub GetSubscribesBySource] error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub GetSubscribesBySource] error: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return rs, nil
|
return rs, nil
|
||||||
@ -56,7 +56,7 @@ func (s *repoStorage) GetIfExistedSubscribe(ctx context.Context, gid int64, feed
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, false, nil
|
return nil, false, nil
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub GetIfExistedSubscribe] error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub GetIfExistedSubscribe] error: %v", err)
|
||||||
return nil, false, err
|
return nil, false, err
|
||||||
}
|
}
|
||||||
if rs.ID == 0 {
|
if rs.ID == 0 {
|
||||||
@ -76,14 +76,14 @@ func (s *repoStorage) UpsertSource(ctx context.Context, source *RssSource) (err
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
err = s.orm.Create(source).Omit("id").Error
|
err = s.orm.Create(source).Omit("id").Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] add source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] add source error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
source.ID = querySource.ID
|
source.ID = querySource.ID
|
||||||
logrus.WithContext(ctx).Infof("[rsshub] update source: %+v", source.UpdatedParsed)
|
logrus.WithContext(ctx).Debugf("[rsshub] update source: %+v", source.UpdatedParsed)
|
||||||
err = s.orm.Model(&source).Where(&RssSource{ID: source.ID}).
|
err = s.orm.Model(&source).Where(&RssSource{ID: source.ID}).
|
||||||
Updates(&RssSource{
|
Updates(&RssSource{
|
||||||
Title: source.Title,
|
Title: source.Title,
|
||||||
@ -94,7 +94,7 @@ func (s *repoStorage) UpsertSource(ctx context.Context, source *RssSource) (err
|
|||||||
Mtime: time.Now(),
|
Mtime: time.Now(),
|
||||||
}).Error
|
}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] update source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] update source error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.Println("[rsshub] add source success: ", source.ID)
|
logrus.Println("[rsshub] add source success: ", source.ID)
|
||||||
@ -109,10 +109,10 @@ func (s *repoStorage) GetSources(ctx context.Context) (sources []RssSource, err
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, errors.New("source not found")
|
return nil, errors.New("source not found")
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] get sources error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] get sources error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Infof("[rsshub] get sources success: %d", len(sources))
|
logrus.WithContext(ctx).Debugf("[rsshub] get sources success: %d", len(sources))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ func (s *repoStorage) GetSourceByRssHubFeedLink(ctx context.Context, rssHubFeedL
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] get source error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] get source error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -134,7 +134,7 @@ func (s *repoStorage) GetSourceByRssHubFeedLink(ctx context.Context, rssHubFeedL
|
|||||||
func (s *repoStorage) DeleteSource(ctx context.Context, fID int64) (err error) {
|
func (s *repoStorage) DeleteSource(ctx context.Context, fID int64) (err error) {
|
||||||
err = s.orm.Delete(&RssSource{}, "id = ?", fID).Error
|
err = s.orm.Delete(&RssSource{}, "id = ?", fID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.DeleteSource: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.DeleteSource: %v", err)
|
||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return errors.New("source not found")
|
return errors.New("source not found")
|
||||||
}
|
}
|
||||||
@ -161,7 +161,7 @@ func (s *repoStorage) UpsertContent(ctx context.Context, content *RssContent) (e
|
|||||||
}
|
}
|
||||||
err = s.orm.Create(content).Omit("id").Error
|
err = s.orm.Create(content).Omit("id").Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.UpsertContent: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.UpsertContent: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -171,7 +171,7 @@ func (s *repoStorage) UpsertContent(ctx context.Context, content *RssContent) (e
|
|||||||
func (s *repoStorage) DeleteSourceContents(ctx context.Context, channelID int64) (rows int64, err error) {
|
func (s *repoStorage) DeleteSourceContents(ctx context.Context, channelID int64) (rows int64, err error) {
|
||||||
err = s.orm.Delete(&RssSubscribe{}).Where(&RssSubscribe{RssSourceID: channelID}).Error
|
err = s.orm.Delete(&RssSubscribe{}).Where(&RssSubscribe{RssSourceID: channelID}).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.DeleteSourceContents: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.DeleteSourceContents: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -185,7 +185,7 @@ func (s *repoStorage) IsContentHashIDExist(ctx context.Context, hashID string) (
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.IsContentHashIDExist: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.IsContentHashIDExist: %v", err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
return true, nil
|
return true, nil
|
||||||
@ -204,7 +204,7 @@ func (s *repoStorage) CreateSubscribe(ctx context.Context, gid, rssSourceID int6
|
|||||||
}
|
}
|
||||||
err = s.orm.Create(&RssSubscribe{GroupID: gid, RssSourceID: rssSourceID}).Omit("id").Error
|
err = s.orm.Create(&RssSubscribe{GroupID: gid, RssSourceID: rssSourceID}).Omit("id").Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.CreateSubscribe: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.CreateSubscribe: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -214,7 +214,7 @@ func (s *repoStorage) CreateSubscribe(ctx context.Context, gid, rssSourceID int6
|
|||||||
func (s *repoStorage) DeleteSubscribe(ctx context.Context, subscribeID int64) (err error) {
|
func (s *repoStorage) DeleteSubscribe(ctx context.Context, subscribeID int64) (err error) {
|
||||||
err = s.orm.Delete(&RssSubscribe{}, "id = ?", subscribeID).Error
|
err = s.orm.Delete(&RssSubscribe{}, "id = ?", subscribeID).Error
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.DeleteSubscribe error: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.DeleteSubscribe error: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -228,7 +228,7 @@ func (s *repoStorage) GetSubscribeByID(ctx context.Context, gid int64, subscribe
|
|||||||
if errors.Is(err, gorm.ErrRecordNotFound) {
|
if errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.GetSubscribeByID: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.GetSubscribeByID: %v", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -247,7 +247,7 @@ func (s *repoStorage) GetSubscribedChannelsByGroupID(ctx context.Context, gid in
|
|||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.GetSubscribedChannelsByGroupID: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.GetSubscribedChannelsByGroupID: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
@ -262,7 +262,7 @@ func (s *repoStorage) GetSubscribes(ctx context.Context) (res []*RssSubscribe, e
|
|||||||
err = nil
|
err = nil
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logrus.WithContext(ctx).Errorf("[rsshub] storage.GetSubscribes: %v", err)
|
logrus.WithContext(ctx).Warnf("[rsshub] storage.GetSubscribes: %v", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user