diff --git a/config/config.go b/config/config.go index 8d2f5fe..b2ce6ca 100644 --- a/config/config.go +++ b/config/config.go @@ -93,6 +93,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 657c56f..d4ad7c1 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