From 7b7c0dc5bba2f05884fa60f5bdb1161e0cd61ecd Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 30 Aug 2016 15:40:55 -0400 Subject: [PATCH] Add a ducking filter --- config/config.go | 7 ++++--- example_config.json | 1 + plugins/your/your.go | 10 ++++++++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 5809471..719a423 100644 --- a/config/config.go +++ b/config/config.go @@ -37,9 +37,9 @@ type Config struct { Freq int Channels []string } - Twitch struct { - Freq int - Users map[string][]string //channel -> usernames + Twitch struct { + Freq int + Users map[string][]string //channel -> usernames } EnforceNicks bool WelcomeMsgs []string @@ -56,6 +56,7 @@ type Config struct { Your struct { YourChance float64 FuckingChance float64 + DuckingChance float64 MaxLength int } LeftPad struct { diff --git a/example_config.json b/example_config.json index 3540c3f..0942470 100644 --- a/example_config.json +++ b/example_config.json @@ -47,6 +47,7 @@ "Your": { "YourChance": 0.4, "FuckingChance": 0.15, + "DuckingChance": 0.5, "MaxLength": 140 }, "LeftPad": { diff --git a/plugins/your/your.go b/plugins/your/your.go index ed2df52..7342f7d 100644 --- a/plugins/your/your.go +++ b/plugins/your/your.go @@ -44,6 +44,16 @@ func (p *YourPlugin) Message(message msg.Message) bool { return true } } + if strings.Contains(message.Body, "ducking") || strings.Contains(message.Body, "fucking") { // let's not mess with case + log.Println("Found a fucking|ducking") + if rand.Float64() < config.DuckingChance { + log.Println("Replacing a ducking") + r := strings.NewReplacer("fucking", "ducking", "ducking", "fucking") + msg := r.Replace(message.Body) + p.bot.SendMessage(message.Channel, msg) + return true + } + } if strings.Contains(lower, "your") || strings.Contains(lower, "you're") { if rand.Float64() < config.YourChance { r := strings.NewReplacer("Your", "You're", "your", "you're", "You're",