Merge pull request #72 from velour/weighted-emojify

emojifyme Chance weighted on number of emoji
This commit is contained in:
Chris Sexton 2017-08-01 16:48:52 -04:00 committed by GitHub
commit 414f7c4bb6
1 changed files with 11 additions and 13 deletions

View File

@ -67,21 +67,19 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool {
} }
} }
if rand.Float64() <= p.Bot.Config().Emojify.Chance { emojied := 0.0
tokens := strings.Fields(strings.ToLower(message.Body)) tokens := strings.Fields(strings.ToLower(message.Body))
sendMessage := false
for i, token := range tokens { for i, token := range tokens {
if _, ok := p.Emoji[token]; ok { if _, ok := p.Emoji[token]; ok {
sendMessage = true emojied++
tokens[i] = ":" + token + ":" tokens[i] = ":" + token + ":"
} }
} }
if sendMessage { if emojied > 0 && rand.Float64() <= p.Bot.Config().Emojify.Chance*emojied {
modified := strings.Join(tokens, " ") modified := strings.Join(tokens, " ")
p.Bot.SendMessage(message.Channel, modified) p.Bot.SendMessage(message.Channel, modified)
return true return true
} }
}
return false return false
} }