mirror of https://github.com/velour/catbase.git
Merge pull request #96 from mccoyst/emojifyme-signal-enhancement-for-eaburns-and-me
Emojifyme signal enhancement for eaburns and me
This commit is contained in:
commit
d4274b61f0
|
@ -91,6 +91,7 @@ type Config struct {
|
||||||
}
|
}
|
||||||
Emojify struct {
|
Emojify struct {
|
||||||
Chance float64
|
Chance float64
|
||||||
|
Scoreless []string
|
||||||
}
|
}
|
||||||
Reaction struct {
|
Reaction struct {
|
||||||
GeneralChance float64
|
GeneralChance float64
|
||||||
|
|
|
@ -29,7 +29,11 @@ config = {
|
||||||
YourChance = 0.4
|
YourChance = 0.4
|
||||||
},
|
},
|
||||||
Emojify = {
|
Emojify = {
|
||||||
Chance = 0.02
|
Chance = 0.02,
|
||||||
|
Scoreless = {
|
||||||
|
"a",
|
||||||
|
"it"
|
||||||
|
}
|
||||||
},
|
},
|
||||||
DB = {
|
DB = {
|
||||||
File = "catbase.db",
|
File = "catbase.db",
|
||||||
|
|
|
@ -67,23 +67,30 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inertTokens := p.Bot.Config().Emojify.Scoreless
|
||||||
emojied := 0.0
|
emojied := 0.0
|
||||||
tokens := strings.Fields(strings.ToLower(message.Body))
|
tokens := strings.Fields(strings.ToLower(message.Body))
|
||||||
for i, token := range tokens {
|
for i, token := range tokens {
|
||||||
if _, ok := p.Emoji[token]; ok {
|
if _, ok := p.Emoji[token]; ok {
|
||||||
|
if !stringsContain(inertTokens, token) {
|
||||||
emojied++
|
emojied++
|
||||||
|
}
|
||||||
tokens[i] = ":" + token + ":"
|
tokens[i] = ":" + token + ":"
|
||||||
} else if strings.HasSuffix(token, "s") {
|
} else if strings.HasSuffix(token, "s") {
|
||||||
//Check to see if we can strip the trailing "es" off and get an emoji
|
//Check to see if we can strip the trailing "es" off and get an emoji
|
||||||
temp := strings.TrimSuffix(token, "s")
|
temp := strings.TrimSuffix(token, "s")
|
||||||
if _, ok := p.Emoji[temp]; ok {
|
if _, ok := p.Emoji[temp]; ok {
|
||||||
|
if !stringsContain(inertTokens, temp) {
|
||||||
emojied++
|
emojied++
|
||||||
|
}
|
||||||
tokens[i] = ":" + temp + ":s"
|
tokens[i] = ":" + temp + ":s"
|
||||||
} else if strings.HasSuffix(token, "es") {
|
} else if strings.HasSuffix(token, "es") {
|
||||||
//Check to see if we can strip the trailing "es" off and get an emoji
|
//Check to see if we can strip the trailing "es" off and get an emoji
|
||||||
temp := strings.TrimSuffix(token, "es")
|
temp := strings.TrimSuffix(token, "es")
|
||||||
if _, ok := p.Emoji[temp]; ok {
|
if _, ok := p.Emoji[temp]; ok {
|
||||||
|
if !stringsContain(inertTokens, temp) {
|
||||||
emojied++
|
emojied++
|
||||||
|
}
|
||||||
tokens[i] = ":" + temp + ":es"
|
tokens[i] = ":" + temp + ":es"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -114,3 +121,12 @@ func (p *EmojifyMePlugin) RegisterWeb() *string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *EmojifyMePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|
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
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue