Merge pull request #75 from velour/more_reactions

supplement catbase's ability to react
This commit is contained in:
Chris Sexton 2017-08-30 13:57:58 -04:00 committed by GitHub
commit 594e54a880
3 changed files with 39 additions and 2 deletions

View File

@ -92,6 +92,13 @@ type Config struct {
Emojify struct {
Chance float64
}
Reaction struct {
GeneralChance float64
HarrassChance float64
HarrassList []string
PositiveReactions []string
NegativeReactions []string
}
}
func init() {

View File

@ -74,5 +74,12 @@
},
"Emojify": {
"Chance": 0.02
},
"Reaction" : {
"GeneralChance": 0.01,
"HarrassChance": 0.05,
"HarrassList": ["msherms"],
"PositiveReactions": ["+1", "authorized", "aw_yea","joy"],
"NegativeReactions": ["bullshit","fake","tableflip","vomit"]
}
}

View File

@ -8,10 +8,12 @@ import (
"github.com/velour/catbase/bot"
"github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/config"
)
type ReactionPlugin struct {
Bot bot.Bot
Config *config.Config
}
func New(bot bot.Bot) *ReactionPlugin {
@ -19,13 +21,34 @@ func New(bot bot.Bot) *ReactionPlugin {
return &ReactionPlugin{
Bot: bot,
Config: bot.Config(),
}
}
func (p *ReactionPlugin) Message(message msg.Message) bool {
if rand.Intn(100) == 0 {
p.Bot.React(message.Channel, "+1", message)
outOf := int(1. / p.Config.Reaction.GeneralChance)
for _, reaction := range p.Config.Reaction.PositiveReactions {
if rand.Intn(outOf) == 0 {
p.Bot.React(message.Channel, reaction, message)
return false
}
}
for _, nick := range p.Config.Reaction.HarrassList {
if message.User.Name == nick {
outOf = int(1. / p.Config.Reaction.HarrassChance)
break
}
}
for _, reaction := range p.Config.Reaction.NegativeReactions {
if rand.Intn(outOf) == 0 {
p.Bot.React(message.Channel, reaction, message)
return false
}
}
return false
}