mirror of https://github.com/velour/catbase.git
reaction: refactor
This commit is contained in:
parent
8cd79d486e
commit
c7c315ad8c
|
@ -3,6 +3,7 @@
|
||||||
package reaction
|
package reaction
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
|
@ -35,12 +36,12 @@ func New(b bot.Bot) *ReactionPlugin {
|
||||||
model: model,
|
model: model,
|
||||||
br: newBayesReactor(path),
|
br: newBayesReactor(path),
|
||||||
}
|
}
|
||||||
b.Register(rp, bot.Message, rp.message)
|
b.RegisterRegex(rp, bot.Message, regexp.MustCompile(`.*`), rp.message)
|
||||||
return rp
|
return rp
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *ReactionPlugin) message(c bot.Connector, kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
func (p *ReactionPlugin) message(r bot.Request) bool {
|
||||||
emojy, prob := p.br.React(message.Body)
|
emojy, prob := p.br.React(r.Msg.Body)
|
||||||
target := p.config.GetFloat64("reaction.confidence", 0.5)
|
target := p.config.GetFloat64("reaction.confidence", 0.5)
|
||||||
|
|
||||||
log.Debug().
|
log.Debug().
|
||||||
|
@ -51,10 +52,10 @@ func (p *ReactionPlugin) message(c bot.Connector, kind bot.Kind, message msg.Mes
|
||||||
Msgf("Reaction check")
|
Msgf("Reaction check")
|
||||||
|
|
||||||
if prob > target {
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue