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.
This commit is contained in:
svohr 2017-07-31 11:16:59 -07:00
parent dcd38a55ff
commit 8119df6dea
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))
sendMessage := false
for i, token := range tokens {
if _, ok := p.Emoji[token]; ok {
sendMessage = true
emojied++
tokens[i] = ":" + token + ":"
}
}
if sendMessage {
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
}