diff --git a/config/config.go b/config/config.go index 053371a..e82be8a 100644 --- a/config/config.go +++ b/config/config.go @@ -95,6 +95,7 @@ type Config struct { Reaction struct { GeneralChance float64 HarrassChance float64 + NegativeHarrassmentMultiplier int HarrassList []string PositiveReactions []string NegativeReactions []string diff --git a/example_config.json b/example_config.json index 66f53d3..ac06d16 100644 --- a/example_config.json +++ b/example_config.json @@ -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"] diff --git a/plugins/reaction/reaction.go b/plugins/reaction/reaction.go index 5352537..a52c17f 100644 --- a/plugins/reaction/reaction.go +++ b/plugins/reaction/reaction.go @@ -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