reaction: refactor

This commit is contained in:
Chris Sexton 2021-02-19 12:15:20 -05:00 committed by Chris Sexton
parent 8cd79d486e
commit c7c315ad8c
1 changed files with 6 additions and 5 deletions

View File

@ -3,6 +3,7 @@
package reaction
import (
"regexp"
"strings"
"github.com/rs/zerolog/log"
@ -35,12 +36,12 @@ func New(b bot.Bot) *ReactionPlugin {
model: model,
br: newBayesReactor(path),
}
b.Register(rp, bot.Message, rp.message)
b.RegisterRegex(rp, bot.Message, regexp.MustCompile(`.*`), rp.message)
return rp
}
func (p *ReactionPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
emojy, prob := p.br.React(message.Body)
func (p *ReactionPlugin) message(r bot.Request) bool {
emojy, prob := p.br.React(r.Msg.Body)
target := p.config.GetFloat64("reaction.confidence", 0.5)
log.Debug().
@ -51,10 +52,10 @@ func (p *ReactionPlugin) message(c bot.Connector, kind bot.Kind, message msg.Mes
Msgf("Reaction check")
if prob > target {
p.bot.Send(c, bot.Reaction, message.Channel, emojy, message)
p.bot.Send(r.Conn, bot.Reaction, r.Msg.Channel, emojy, r.Msg)
}
p.checkReactions(c, message)
p.checkReactions(r.Conn, r.Msg)
return false
}