mirror of https://github.com/velour/catbase.git
tell: fix empty lists and user case
This commit is contained in:
parent
1a420c1738
commit
9f332909b5
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue