2017-11-16 22:05:22 +00:00
|
|
|
package tell
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
|
|
|
"github.com/velour/catbase/bot"
|
|
|
|
"github.com/velour/catbase/bot/msg"
|
|
|
|
)
|
|
|
|
|
|
|
|
type delayedMsg string
|
|
|
|
|
|
|
|
type TellPlugin struct {
|
|
|
|
b bot.Bot
|
|
|
|
users map[string][]string
|
|
|
|
}
|
|
|
|
|
|
|
|
func New(b bot.Bot) *TellPlugin {
|
2019-02-05 19:41:38 +00:00
|
|
|
tp := &TellPlugin{b, make(map[string][]string)}
|
|
|
|
b.Register(tp, bot.Message, tp.message)
|
|
|
|
return tp
|
2017-11-16 22:05:22 +00:00
|
|
|
}
|
|
|
|
|
2019-02-05 19:41:38 +00:00
|
|
|
func (t *TellPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
|
2017-11-17 13:39:35 +00:00
|
|
|
if strings.HasPrefix(strings.ToLower(message.Body), "tell") {
|
2017-11-16 22:05:22 +00:00
|
|
|
parts := strings.Split(message.Body, " ")
|
2017-11-17 13:39:35 +00:00
|
|
|
target := strings.ToLower(parts[1])
|
2017-11-16 22:05:22 +00:00
|
|
|
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)
|
2019-02-05 15:54:13 +00:00
|
|
|
t.b.Send(bot.Message, message.Channel, fmt.Sprintf("Okay. I'll tell %s.", target))
|
2017-11-16 22:05:22 +00:00
|
|
|
return true
|
|
|
|
}
|
2017-11-17 13:39:35 +00:00
|
|
|
uname := strings.ToLower(message.User.Name)
|
|
|
|
if msg, ok := t.users[uname]; ok && len(msg) > 0 {
|
2017-11-16 22:05:22 +00:00
|
|
|
for _, m := range msg {
|
2019-02-05 15:54:13 +00:00
|
|
|
t.b.Send(bot.Message, message.Channel, string(m))
|
2017-11-16 22:05:22 +00:00
|
|
|
}
|
2017-11-17 13:39:35 +00:00
|
|
|
t.users[uname] = []string{}
|
2017-11-16 22:05:22 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2019-02-05 19:41:38 +00:00
|
|
|
func (t *TellPlugin) RegisterWeb() *string { return nil }
|