From f004cecf3a0a0d208aeb4f7b3d98bd29ff81f7a0 Mon Sep 17 00:00:00 2001 From: cws Date: Tue, 25 Jul 2017 14:44:36 -0400 Subject: [PATCH] emojify: configurize the chance --- config/config.go | 3 +++ example_config.json | 3 +++ plugins/emojifyme/emojifyme.go | 2 +- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 063be8f..cbe2e09 100644 --- a/config/config.go +++ b/config/config.go @@ -89,6 +89,9 @@ type Config struct { DBPath string Sightings []string } + Emojify struct { + Chance float64 + } } func init() { diff --git a/example_config.json b/example_config.json index 777a2bc..6cba1c9 100644 --- a/example_config.json +++ b/example_config.json @@ -71,5 +71,8 @@ "Stats": { "DBPath": "stats.db", "Sightings": ["user"] + }, + "Emojify": { + "Chance": 0.02 } } diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index 2d02f75..91c9730 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -67,7 +67,7 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { } } - if rand.Intn(10) == 0 { + if rand.Float64() <= p.Bot.Config().Emojify.Chance { tokens := strings.Fields(strings.ToLower(message.Body)) sendMessage := false for i, token := range tokens {