mirror of https://github.com/velour/catbase.git
Merge branch 'master' of github.com:velour/catbase
* 'master' of github.com:velour/catbase: Change to use the lua config… Oh, and handle the plurals… Don't count "a" and "it" toward the emojification score one more try grab the bot's bot id from the message response and use that to avoid self-reply loops
This commit is contained in:
commit
5e52c3bb16
|
@ -91,6 +91,7 @@ type Config struct {
|
|||
}
|
||||
Emojify struct {
|
||||
Chance float64
|
||||
Scoreless []string
|
||||
}
|
||||
Reaction struct {
|
||||
GeneralChance float64
|
||||
|
@ -109,7 +110,6 @@ type Config struct {
|
|||
MinPush int
|
||||
MaxPush int
|
||||
}
|
||||
BotList map[string]bool
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
|
|
@ -29,7 +29,11 @@ config = {
|
|||
YourChance = 0.4
|
||||
},
|
||||
Emojify = {
|
||||
Chance = 0.02
|
||||
Chance = 0.02,
|
||||
Scoreless = {
|
||||
"a",
|
||||
"it"
|
||||
}
|
||||
},
|
||||
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
|
||||
tokens := strings.Fields(strings.ToLower(message.Body))
|
||||
for i, token := range tokens {
|
||||
if _, ok := p.Emoji[token]; ok {
|
||||
if !stringsContain(inertTokens, token) {
|
||||
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 {
|
||||
if !stringsContain(inertTokens, temp) {
|
||||
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 {
|
||||
if !stringsContain(inertTokens, temp) {
|
||||
emojied++
|
||||
}
|
||||
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 stringsContain(haystack []string, needle string) bool {
|
||||
for _, s := range haystack {
|
||||
if s == needle {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
|
@ -37,6 +37,8 @@ type Slack struct {
|
|||
|
||||
users map[string]string
|
||||
|
||||
myBotID string
|
||||
|
||||
emoji map[string]string
|
||||
|
||||
eventReceived func(msg.Message)
|
||||
|
@ -228,6 +230,9 @@ func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string
|
|||
type MessageResponse struct {
|
||||
OK bool `json:"ok"`
|
||||
Timestamp string `json:"ts"`
|
||||
Message struct {
|
||||
BotID string `json:"bot_id"`
|
||||
} `json:"message"`
|
||||
}
|
||||
|
||||
var mr MessageResponse
|
||||
|
@ -240,6 +245,8 @@ func (s *Slack) SendMessageType(channel, message string, meMessage bool) (string
|
|||
return "", errors.New("failure response received")
|
||||
}
|
||||
|
||||
s.myBotID = mr.Message.BotID
|
||||
|
||||
return mr.Timestamp, err
|
||||
}
|
||||
|
||||
|
@ -392,16 +399,8 @@ func (s *Slack) Serve() error {
|
|||
}
|
||||
switch msg.Type {
|
||||
case "message":
|
||||
botOK := true
|
||||
if msg.BotID != "" {
|
||||
u, _ := s.getUser(msg.User)
|
||||
if u == "" && msg.Username != "" {
|
||||
u = msg.Username
|
||||
}
|
||||
log.Printf("User: %s, BotList: %+v", u, s.config.BotList)
|
||||
botOK = s.config.BotList[strings.Title(u)]
|
||||
}
|
||||
if botOK && !msg.Hidden && msg.ThreadTs == "" {
|
||||
isItMe := msg.BotID != "" && msg.BotID == s.myBotID
|
||||
if !isItMe && !msg.Hidden && msg.ThreadTs == "" {
|
||||
m := s.buildMessage(msg)
|
||||
if m.Time.Before(s.lastRecieved) {
|
||||
log.Printf("Ignoring message: %+v\nlastRecieved: %v msg: %v", msg.ID, s.lastRecieved, m.Time)
|
||||
|
|
Loading…
Reference in New Issue