tell: fix empty lists and user case

This commit is contained in:
Chris Sexton 2017-11-17 08:39:35 -05:00
parent 1a420c1738
commit 9f332909b5
1 changed files with 5 additions and 6 deletions

View File

@ -2,7 +2,6 @@ package tell
import (
"fmt"
"log"
"strings"
"github.com/velour/catbase/bot"
@ -21,21 +20,21 @@ func New(b bot.Bot) *TellPlugin {
}
func (t *TellPlugin) Message(message msg.Message) bool {
if strings.HasPrefix(message.Body, "tell") {
if strings.HasPrefix(strings.ToLower(message.Body), "tell") {
parts := strings.Split(message.Body, " ")
target := parts[1]
target := strings.ToLower(parts[1])
newMessage := strings.Join(parts[2:], " ")
newMessage = fmt.Sprintf("Hey, %s. %s said: %s", target, message.User.Name, newMessage)
t.users[target] = append(t.users[target], newMessage)
t.b.SendMessage(message.Channel, fmt.Sprintf("Okay. I'll tell %s.", target))
return true
}
log.Printf("current pending tells: %+v\nuser is: %s", t.users, message.User.Name)
if msg, ok := t.users[message.User.Name]; ok {
uname := strings.ToLower(message.User.Name)
if msg, ok := t.users[uname]; ok && len(msg) > 0 {
for _, m := range msg {
t.b.SendMessage(message.Channel, string(m))
}
t.users[message.User.Name] = []string{}
t.users[uname] = []string{}
return true
}
return false