From a829c943493785f0b3b8f92b9acf5c31d7fd0875 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Thu, 24 Mar 2016 13:49:44 -0400 Subject: [PATCH] Add config values for your --- config/config.go | 5 +++++ example_config.json | 5 +++++ plugins/your/your.go | 19 ++++++++++++------- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/config/config.go b/config/config.go index b1e5385..e4c68b3 100644 --- a/config/config.go +++ b/config/config.go @@ -52,6 +52,11 @@ type Config struct { Nicks []string Hosts []string } + Your struct { + YourChance float64 + FuckingChance float64 + MaxLength int + } } // Readconfig loads the config data out of a JSON file located in cfile diff --git a/example_config.json b/example_config.json index eb7c34b..a7e4a60 100644 --- a/example_config.json +++ b/example_config.json @@ -47,5 +47,10 @@ "Msgs": [], "Nicks": [], "Hosts": [] + }, + "Your": { + "YourChance": 0.4, + "FuckingChance": 0.15, + "MaxLength": 140 } } diff --git a/plugins/your/your.go b/plugins/your/your.go index 4f02b67..2976828 100644 --- a/plugins/your/your.go +++ b/plugins/your/your.go @@ -12,14 +12,14 @@ import ( ) type YourPlugin struct { - Bot *bot.Bot + bot *bot.Bot } // NewYourPlugin creates a new YourPlugin with the Plugin interface func NewYourPlugin(bot *bot.Bot) *YourPlugin { rand.Seed(time.Now().Unix()) return &YourPlugin{ - Bot: bot, + bot: bot, } } @@ -28,22 +28,27 @@ func NewYourPlugin(bot *bot.Bot) *YourPlugin { // Otherwise, the function returns false and the bot continues execution of other plugins. func (p *YourPlugin) Message(message bot.Message) bool { lower := strings.ToLower(message.Body) + config := p.bot.Config.Your + if len(message.Body) > config.MaxLength { + return false + } + if strings.Contains(message.Body, "the fucking") { // let's not mess with case log.Println("Found a fucking") - if rand.Float64() < 0.2 { + if rand.Float64() < config.FuckingChance { log.Println("Replacing a fucking") r := strings.NewReplacer("the fucking", "fucking the") msg := r.Replace(message.Body) - p.Bot.SendMessage(message.Channel, msg) + p.bot.SendMessage(message.Channel, msg) return true } } if strings.Contains(lower, "your") || strings.Contains(lower, "you're") { - if rand.Float64() < 0.15 { + if rand.Float64() < config.YourChance { r := strings.NewReplacer("Your", "You're", "your", "you're", "You're", "Your", "you're", "your", "Youre", "Your", "youre", "your") msg := r.Replace(message.Body) - p.Bot.SendMessage(message.Channel, msg) + p.bot.SendMessage(message.Channel, msg) return true } } @@ -52,7 +57,7 @@ func (p *YourPlugin) Message(message bot.Message) bool { // Help responds to help requests. Every plugin must implement a help function. func (p *YourPlugin) Help(channel string, parts []string) { - p.Bot.SendMessage(channel, "Your corrects people's grammar.") + p.bot.SendMessage(channel, "Your corrects people's grammar.") } // Empty event handler because this plugin does not do anything on event recv