Skip to content

Commit

Permalink
[fix]fix cqbot send repeated
Browse files Browse the repository at this point in the history
Signed-off-by: fzxiao233 <fzxiao@outlook.com>
  • Loading branch information
AlotOfBlahaj committed Oct 9, 2020
1 parent 4d90e50 commit c7688a4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions live/plugins/cqBot.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func (cc *CQConfig) sendGroupMsg(msg *CQMsg) {
}

type PluginCQBot struct {
laseMsg string
sentMsg map[string]int
}

func CreateLiveMsg(v *interfaces.VideoInfo) string {
Expand All @@ -49,6 +49,9 @@ type CQJsonConfig struct {
}

func (p *PluginCQBot) LiveStart(process *videoworker.ProcessVideo) error {
if p.sentMsg == nil {
p.sentMsg = make(map[string]int)
}
video := process.LiveStatus.Video
config := CQJsonConfig{}
cqConfig, ok := video.UsersConfig.ExtraConfig["CQConfig"]
Expand All @@ -66,11 +69,11 @@ func (p *PluginCQBot) LiveStart(process *videoworker.ProcessVideo) error {
}

msg := CreateLiveMsg(video)
if msg == p.laseMsg {
_, ok = p.sentMsg[msg]
if ok {
log.Infof("%s|%s cancel to send msg: %s", video.Provider, video.UsersConfig.Name, msg)
return nil
}
p.laseMsg = msg
c := &CQMsg{Message: msg}
cc := &CQConfig{
CQHost: config.CQHost,
Expand All @@ -81,6 +84,7 @@ func (p *PluginCQBot) LiveStart(process *videoworker.ProcessVideo) error {
cc.sendGroupMsg(c)
log.Infof("%s|%s send notice to %d", video.Provider, video.UsersConfig.Name, GroupId)
}
p.sentMsg[msg] = 1
return nil
}

Expand Down

0 comments on commit c7688a4

Please sign in to comment.