Fixes #1: Make quotes multiline

This commit is contained in:
Chris Sexton 2013-08-31 23:05:00 -04:00
parent 74a5647d2d
commit 54899c74ca
1 changed files with 64 additions and 52 deletions

View File

@ -55,8 +55,14 @@ func (p *RememberPlugin) Message(message bot.Message) bool {
// we have a remember! // we have a remember!
// look through the logs and find parts[1] as a user, if not, // look through the logs and find parts[1] as a user, if not,
// fuck this hoser // fuck this hoser
nick := parts[1] snips := strings.Split(strings.Join(parts[1:], " "), "$and")
snip := strings.Join(parts[2:], " ") var msgs []string
var trigger string
for _, snip := range snips {
snipParts := strings.Split(snip, " ")
nick := snipParts[0]
snip := strings.Join(snipParts[1:], " ")
for i := len(p.Log[message.Channel]) - 1; i >= 0; i-- { for i := len(p.Log[message.Channel]) - 1; i >= 0; i-- {
entry := p.Log[message.Channel][i] entry := p.Log[message.Channel][i]
@ -66,18 +72,24 @@ func (p *RememberPlugin) Message(message bot.Message) bool {
strings.ToLower(entry.Body), strings.ToLower(entry.Body),
strings.ToLower(snip), strings.ToLower(snip),
) { ) {
// insert new remember entry
var msg string
// check if it's an action // check if it's an action
if entry.Action { if entry.Action {
msg = fmt.Sprintf("*%s* %s", entry.User.Name, entry.Body) msgs = append(msgs, fmt.Sprintf("*%s* %s", entry.User.Name, entry.Body))
} else { } else {
msg = fmt.Sprintf("<%s> %s", entry.User.Name, entry.Body) msgs = append(msgs, fmt.Sprintf("<%s> %s", entry.User.Name, entry.Body))
} }
trigger := fmt.Sprintf("%s quotes", entry.User.Name) if trigger == "" {
trigger = fmt.Sprintf("%s quotes", entry.User.Name)
}
}
}
}
if len(msgs) == len(snips) {
msg := strings.Join(msgs, "$and")
var funcres bson.M var funcres bson.M
err := p.Bot.Db.Run( err := p.Bot.Db.Run(
bson.M{"eval": "return counter(\"factoid\");"}, bson.M{"eval": "return counter(\"factoid\");"},
@ -112,7 +124,7 @@ func (p *RememberPlugin) Message(message bot.Message) bool {
p.Log[message.Channel] = append(p.Log[message.Channel], message) p.Log[message.Channel] = append(p.Log[message.Channel], message)
return true return true
} }
}
p.Bot.SendMessage(message.Channel, "Sorry, I don't know that phrase.") p.Bot.SendMessage(message.Channel, "Sorry, I don't know that phrase.")
p.Log[message.Channel] = append(p.Log[message.Channel], message) p.Log[message.Channel] = append(p.Log[message.Channel], message)
return true return true