Merge pull request #76 from velour/more_reactions

Fix Probabilities
This commit is contained in:
Chris Sexton 2017-08-31 08:53:56 -04:00 committed by GitHub
commit 885fe097c0
3 changed files with 29 additions and 14 deletions

View File

@ -93,6 +93,7 @@ type Config struct {
Reaction struct {
GeneralChance float64
HarrassChance float64
NegativeHarrassmentMultiplier int
HarrassList []string
PositiveReactions []string
NegativeReactions []string

View File

@ -78,6 +78,7 @@
"Reaction" : {
"GeneralChance": 0.01,
"HarrassChance": 0.05,
"NegativeHarrassmentMultiplier": 2,
"HarrassList": ["msherms"],
"PositiveReactions": ["+1", "authorized", "aw_yea","joy"],
"NegativeReactions": ["bullshit","fake","tableflip","vomit"]

View File

@ -26,27 +26,40 @@ func New(bot bot.Bot) *ReactionPlugin {
}
func (p *ReactionPlugin) Message(message msg.Message) bool {
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
}
}
harrass := false
for _, nick := range p.Config.Reaction.HarrassList {
if message.User.Name == nick {
outOf = int(1. / p.Config.Reaction.HarrassChance)
harrass = true
break
}
}
for _, reaction := range p.Config.Reaction.NegativeReactions {
if rand.Intn(outOf) == 0 {
p.Bot.React(message.Channel, reaction, message)
return false
chance := p.Config.Reaction.GeneralChance
negativeWeight := 1
if harrass {
chance = p.Config.Reaction.HarrassChance
negativeWeight = p.Config.Reaction.NegativeHarrassmentMultiplier
}
if rand.Float64() < chance {
numPositiveReactions := len(p.Config.Reaction.PositiveReactions)
numNegativeReactions := len(p.Config.Reaction.NegativeReactions)
maxIndex := numPositiveReactions + numNegativeReactions * negativeWeight
index := rand.Intn(maxIndex)
reaction := ""
if index < numPositiveReactions {
reaction = p.Config.Reaction.PositiveReactions[index]
} else {
index -= numPositiveReactions
index %= numNegativeReactions
reaction = p.Config.Reaction.NegativeReactions[index]
}
p.Bot.React(message.Channel, reaction, message)
}
return false