supplement catbase's ability to react

This commit is contained in:
skkiesel 2017-08-30 13:41:58 -04:00
parent e65afb915a
commit 980359b4e1
3 changed files with 39 additions and 2 deletions

View File

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

View File

@ -74,5 +74,12 @@
}, },
"Emojify": { "Emojify": {
"Chance": 0.02 "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"
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
"github.com/velour/catbase/config"
) )
type ReactionPlugin struct { type ReactionPlugin struct {
Bot bot.Bot Bot bot.Bot
Config *config.Config
} }
func New(bot bot.Bot) *ReactionPlugin { func New(bot bot.Bot) *ReactionPlugin {
@ -19,13 +21,34 @@ func New(bot bot.Bot) *ReactionPlugin {
return &ReactionPlugin{ return &ReactionPlugin{
Bot: bot, Bot: bot,
Config: bot.Config(),
} }
} }
func (p *ReactionPlugin) Message(message msg.Message) bool { func (p *ReactionPlugin) Message(message msg.Message) bool {
if rand.Intn(100) == 0 { outOf := int(1. / p.Config.Reaction.GeneralChance)
p.Bot.React(message.Channel, "+1", message)
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 return false
} }