From 83289d65f0394c7f8f8c34b2709dab1de31e984b Mon Sep 17 00:00:00 2001 From: Steve McCoy Date: Mon, 27 Nov 2017 22:07:59 -0500 Subject: [PATCH 1/3] Don't count "a" and "it" toward the emojification score Fixes #95. --- plugins/emojifyme/emojifyme.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index e8a6119..e71aede 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -71,19 +71,25 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { tokens := strings.Fields(strings.ToLower(message.Body)) for i, token := range tokens { if _, ok := p.Emoji[token]; ok { - emojied++ + if token != "a" && token != "it" { + emojied++ + } tokens[i] = ":" + token + ":" } else if strings.HasSuffix(token, "s") { //Check to see if we can strip the trailing "es" off and get an emoji temp := strings.TrimSuffix(token, "s") if _, ok := p.Emoji[temp]; ok { - emojied++ + if token != "a" && token != "it" { + emojied++ + } tokens[i] = ":" + temp + ":s" } else if strings.HasSuffix(token, "es") { //Check to see if we can strip the trailing "es" off and get an emoji temp := strings.TrimSuffix(token, "es") if _, ok := p.Emoji[temp]; ok { - emojied++ + if token != "a" && token != "it" { + emojied++ + } tokens[i] = ":" + temp + ":es" } } From 85b649bc98ebac7be503318f6c1bd009dff793cb Mon Sep 17 00:00:00 2001 From: Steve McCoy Date: Mon, 27 Nov 2017 22:09:55 -0500 Subject: [PATCH 2/3] =?UTF-8?q?Oh,=20and=20handle=20the=20plurals=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/emojifyme/emojifyme.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index e71aede..8898b54 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -79,7 +79,7 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { //Check to see if we can strip the trailing "es" off and get an emoji temp := strings.TrimSuffix(token, "s") if _, ok := p.Emoji[temp]; ok { - if token != "a" && token != "it" { + if temp != "a" && temp != "it" { emojied++ } tokens[i] = ":" + temp + ":s" @@ -87,7 +87,7 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { //Check to see if we can strip the trailing "es" off and get an emoji temp := strings.TrimSuffix(token, "es") if _, ok := p.Emoji[temp]; ok { - if token != "a" && token != "it" { + if temp != "a" && temp != "it" { emojied++ } tokens[i] = ":" + temp + ":es" From 5794c73efdcb27132b4d858b8c516cebfe3a1cc7 Mon Sep 17 00:00:00 2001 From: Steve McCoy Date: Sun, 3 Dec 2017 13:04:55 -0500 Subject: [PATCH 3/3] =?UTF-8?q?Change=20to=20use=20the=20lua=20config?= =?UTF-8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/config.go | 1 + example_config.lua | 6 +++++- plugins/emojifyme/emojifyme.go | 16 +++++++++++++--- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/config/config.go b/config/config.go index d00cb5c..0d345c7 100644 --- a/config/config.go +++ b/config/config.go @@ -91,6 +91,7 @@ type Config struct { } Emojify struct { Chance float64 + Scoreless []string } Reaction struct { GeneralChance float64 diff --git a/example_config.lua b/example_config.lua index 58e3d74..fce3646 100644 --- a/example_config.lua +++ b/example_config.lua @@ -29,7 +29,11 @@ config = { YourChance = 0.4 }, Emojify = { - Chance = 0.02 + Chance = 0.02, + Scoreless = { + "a", + "it" + } }, DB = { File = "catbase.db", diff --git a/plugins/emojifyme/emojifyme.go b/plugins/emojifyme/emojifyme.go index 8898b54..4c1383d 100644 --- a/plugins/emojifyme/emojifyme.go +++ b/plugins/emojifyme/emojifyme.go @@ -67,11 +67,12 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { } } + inertTokens := p.Bot.Config().Emojify.Scoreless emojied := 0.0 tokens := strings.Fields(strings.ToLower(message.Body)) for i, token := range tokens { if _, ok := p.Emoji[token]; ok { - if token != "a" && token != "it" { + if !stringsContain(inertTokens, token) { emojied++ } tokens[i] = ":" + token + ":" @@ -79,7 +80,7 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { //Check to see if we can strip the trailing "es" off and get an emoji temp := strings.TrimSuffix(token, "s") if _, ok := p.Emoji[temp]; ok { - if temp != "a" && temp != "it" { + if !stringsContain(inertTokens, temp) { emojied++ } tokens[i] = ":" + temp + ":s" @@ -87,7 +88,7 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool { //Check to see if we can strip the trailing "es" off and get an emoji temp := strings.TrimSuffix(token, "es") if _, ok := p.Emoji[temp]; ok { - if temp != "a" && temp != "it" { + if !stringsContain(inertTokens, temp) { emojied++ } tokens[i] = ":" + temp + ":es" @@ -120,3 +121,12 @@ func (p *EmojifyMePlugin) RegisterWeb() *string { } func (p *EmojifyMePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false } + +func stringsContain(haystack []string, needle string) bool { + for _, s := range haystack { + if s == needle { + return true + } + } + return false +}