From 980359b4e13e1ebde1e457c46c4d63356fb6352d Mon Sep 17 00:00:00 2001 From: skkiesel Date: Wed, 30 Aug 2017 13:41:58 -0400 Subject: [PATCH] supplement catbase's ability to react --- config/config.go | 7 +++++++ example_config.json | 7 +++++++ plugins/reaction/reaction.go | 27 +++++++++++++++++++++++++-- 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index cbe2e09..053371a 100644 --- a/config/config.go +++ b/config/config.go @@ -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() { diff --git a/example_config.json b/example_config.json index 6cba1c9..66f53d3 100644 --- a/example_config.json +++ b/example_config.json @@ -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"] } } diff --git a/plugins/reaction/reaction.go b/plugins/reaction/reaction.go index dc75b96..5352537 100644 --- a/plugins/reaction/reaction.go +++ b/plugins/reaction/reaction.go @@ -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 }