From 8119df6deae4225371cd49c26c2c9fbb52c280ec Mon Sep 17 00:00:00 2001 From: svohr Date: Mon, 31 Jul 2017 11:16:59 -0700 Subject: [PATCH] emojifyme Chance weighted on number of emojies The chance of an emojified message being sent is now proportional to the number of emojies that can be substituted in the message. --- plugins/emojifyme/emojifyme.go | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index 91c9730..a88911f 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -67,21 +67,19 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { } } - if rand.Float64() <= p.Bot.Config().Emojify.Chance { - tokens := strings.Fields(strings.ToLower(message.Body)) - sendMessage := false - for i, token := range tokens { - if _, ok := p.Emoji[token]; ok { - sendMessage = true - tokens[i] = ":" + token + ":" - } - } - if sendMessage { - modified := strings.Join(tokens, " ") - p.Bot.SendMessage(message.Channel, modified) - return true + emojied := 0.0 + tokens := strings.Fields(strings.ToLower(message.Body)) + for i, token := range tokens { + if _, ok := p.Emoji[token]; ok { + emojied++ + tokens[i] = ":" + token + ":" } } + if emojied > 0 && rand.Float64() <= p.Bot.Config().Emojify.Chance*emojied { + modified := strings.Join(tokens, " ") + p.Bot.SendMessage(message.Channel, modified) + return true + } return false }