mirror of https://github.com/velour/catbase.git
Merge pull request #72 from velour/weighted-emojify
emojifyme Chance weighted on number of emoji
This commit is contained in:
commit
414f7c4bb6
|
@ -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 {
|
emojied++
|
||||||
sendMessage = true
|
tokens[i] = ":" + token + ":"
|
||||||
tokens[i] = ":" + token + ":"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if sendMessage {
|
|
||||||
modified := strings.Join(tokens, " ")
|
|
||||||
p.Bot.SendMessage(message.Channel, modified)
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue