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 +}