emojify: handle plurals again

This commit is contained in:
Chris Sexton 2019-01-21 18:05:35 -05:00
parent 36320df725
commit 4d188bdf20
1 changed files with 12 additions and 4 deletions

View File

@ -70,13 +70,21 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool {
msg := strings.Replace(strings.ToLower(message.Body), "_", " ", -1)
for k, v := range p.Emoji {
k = strings.Replace(k, "_", " ", -1)
if strings.Contains(msg, " "+k+" ") || strings.HasPrefix(msg, k) || strings.HasSuffix(msg, k) {
candidates := []string{
k + "es",
k + "s",
}
for _, c := range candidates {
if strings.Contains(msg, " "+c+" ") ||
strings.HasPrefix(msg, c) ||
strings.HasSuffix(msg, c) {
emojys = append(emojys, v)
if !stringsContain(inertTokens, k) || len(k) <= 2 {
emojied++
}
}
}
}
if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance")*emojied {
for _, e := range emojys {