2016-01-17 18:00:44 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
2013-12-10 23:37:07 +00:00
|
|
|
|
2016-03-24 17:32:40 +00:00
|
|
|
package talker
|
2012-08-17 22:09:29 +00:00
|
|
|
|
|
|
|
import (
|
2012-08-25 04:46:13 +00:00
|
|
|
"fmt"
|
2012-08-25 04:54:03 +00:00
|
|
|
"math/rand"
|
2012-08-25 04:49:48 +00:00
|
|
|
"strings"
|
2016-01-15 14:43:31 +00:00
|
|
|
|
2016-01-17 18:00:44 +00:00
|
|
|
"github.com/velour/catbase/bot"
|
2016-04-01 14:20:03 +00:00
|
|
|
"github.com/velour/catbase/bot/msg"
|
2012-08-17 22:09:29 +00:00
|
|
|
)
|
|
|
|
|
2013-02-05 19:52:11 +00:00
|
|
|
var goatse []string = []string{
|
2016-03-25 19:10:56 +00:00
|
|
|
"```* g o a t s e x * g o a t s e x * g o a t s e x *",
|
2013-02-05 19:52:11 +00:00
|
|
|
"g g",
|
|
|
|
"o / \\ \\ / \\ o",
|
|
|
|
"a| | \\ | | a",
|
|
|
|
"t| `. | | : t",
|
|
|
|
"s` | | \\| | s",
|
|
|
|
"e \\ | / / \\\\\\ --__ \\\\ : e",
|
|
|
|
"x \\ \\/ _--~~ ~--__| \\ | x",
|
|
|
|
"* \\ \\_-~ ~-_\\ | *",
|
|
|
|
"g \\_ \\ _.--------.______\\| | g",
|
2013-02-05 20:11:03 +00:00
|
|
|
"o \\ \\______// _ ___ _ \\_\\__> \\ | o",
|
|
|
|
"a \\ . C ___) ______ \\_\\____> | / a",
|
|
|
|
"t /\\ | C ____)/ \\ \\_____> |_/ t",
|
|
|
|
"s / /\\| C_____) | \\___> / \\ s",
|
|
|
|
"e | \\ _C_____)\\______/ // _/ / \\ e",
|
|
|
|
"x | \\ |__ \\\\_________// \\__/ | x",
|
2013-02-05 19:52:11 +00:00
|
|
|
"* | \\ \\____) `---- --' | *",
|
|
|
|
"g | \\_ ___\\ /_ _/ | g",
|
|
|
|
"o | / | | \\ | o",
|
|
|
|
"a | | / \\ \\ | a",
|
2013-02-05 20:11:03 +00:00
|
|
|
"t | / / |{nick}| \\ |t",
|
2013-02-05 19:52:11 +00:00
|
|
|
"s | / / \\__/\\___/ | |s",
|
|
|
|
"e | / | | | |e",
|
|
|
|
"x | | | | | |x",
|
2016-03-25 19:10:56 +00:00
|
|
|
"* g o a t s e x * g o a t s e x * g o a t s e x *```",
|
2013-02-05 19:52:11 +00:00
|
|
|
}
|
|
|
|
|
2012-08-17 22:09:29 +00:00
|
|
|
type TalkerPlugin struct {
|
2016-03-30 14:00:20 +00:00
|
|
|
Bot bot.Bot
|
2016-01-15 14:43:31 +00:00
|
|
|
enforceNicks bool
|
2016-03-30 23:25:02 +00:00
|
|
|
sayings []string
|
2012-08-17 22:09:29 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 14:00:20 +00:00
|
|
|
func New(bot bot.Bot) *TalkerPlugin {
|
2012-08-17 22:09:29 +00:00
|
|
|
return &TalkerPlugin{
|
2016-01-15 14:43:31 +00:00
|
|
|
Bot: bot,
|
2016-03-30 14:00:20 +00:00
|
|
|
enforceNicks: bot.Config().EnforceNicks,
|
2016-03-30 23:25:02 +00:00
|
|
|
sayings: bot.Config().WelcomeMsgs,
|
2012-08-17 22:09:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-01 14:20:03 +00:00
|
|
|
func (p *TalkerPlugin) Message(message msg.Message) bool {
|
2012-08-17 22:09:29 +00:00
|
|
|
channel := message.Channel
|
|
|
|
body := message.Body
|
2013-03-04 15:43:23 +00:00
|
|
|
lowermessage := strings.ToLower(body)
|
2012-08-17 22:09:29 +00:00
|
|
|
|
2016-01-15 14:43:31 +00:00
|
|
|
// TODO: This ought to be space split afterwards to remove any punctuation
|
2016-03-30 23:25:02 +00:00
|
|
|
if message.Command && strings.HasPrefix(lowermessage, "say") {
|
2013-03-04 15:43:23 +00:00
|
|
|
msg := strings.TrimSpace(body[3:])
|
|
|
|
p.Bot.SendMessage(channel, msg)
|
2013-03-04 15:50:39 +00:00
|
|
|
return true
|
2013-03-04 15:43:23 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 23:25:02 +00:00
|
|
|
if message.Command && strings.HasPrefix(lowermessage, "goatse") {
|
2013-02-05 20:11:03 +00:00
|
|
|
nick := message.User.Name
|
2016-05-11 16:10:15 +00:00
|
|
|
if parts := strings.Fields(message.Body); len(parts) > 1 {
|
2013-02-05 20:11:03 +00:00
|
|
|
nick = parts[1]
|
|
|
|
}
|
|
|
|
|
2016-03-25 19:10:56 +00:00
|
|
|
output := ""
|
2013-02-05 19:52:11 +00:00
|
|
|
for _, line := range goatse {
|
2013-02-05 20:11:03 +00:00
|
|
|
nick = fmt.Sprintf("%9.9s", nick)
|
|
|
|
line = strings.Replace(line, "{nick}", nick, 1)
|
2016-03-25 19:10:56 +00:00
|
|
|
output += line + "\n"
|
2013-02-05 19:52:11 +00:00
|
|
|
}
|
2016-03-25 19:10:56 +00:00
|
|
|
p.Bot.SendMessage(channel, output)
|
2013-02-05 19:52:11 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2016-01-15 14:43:31 +00:00
|
|
|
if p.enforceNicks && len(message.User.Name) != 9 {
|
2012-08-25 04:58:36 +00:00
|
|
|
msg := fmt.Sprintf("Hey %s, we really like to have 9 character nicks because we're crazy OCD and stuff.",
|
|
|
|
message.User.Name)
|
|
|
|
p.Bot.SendMessage(message.Channel, msg)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2012-08-17 22:09:29 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2012-08-17 22:56:44 +00:00
|
|
|
func (p *TalkerPlugin) Help(channel string, parts []string) {
|
|
|
|
p.Bot.SendMessage(channel, "Hi, this is talker. I like to talk about FredFelps!")
|
|
|
|
}
|
2012-08-25 04:46:13 +00:00
|
|
|
|
|
|
|
// Empty event handler because this plugin does not do anything on event recv
|
2016-04-01 14:20:03 +00:00
|
|
|
func (p *TalkerPlugin) Event(kind string, message msg.Message) bool {
|
2016-03-30 14:00:20 +00:00
|
|
|
if kind == "JOIN" && strings.ToLower(message.User.Name) != strings.ToLower(p.Bot.Config().Nick) {
|
2016-03-30 23:25:02 +00:00
|
|
|
if len(p.sayings) == 0 {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
msg := fmt.Sprintf(p.sayings[rand.Intn(len(p.sayings))], message.User.Name)
|
2012-08-25 04:46:13 +00:00
|
|
|
p.Bot.SendMessage(message.Channel, msg)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
return false
|
|
|
|
}
|
2013-05-08 00:08:18 +00:00
|
|
|
|
|
|
|
// Handler for bot's own messages
|
2016-04-01 14:20:03 +00:00
|
|
|
func (p *TalkerPlugin) BotMessage(message msg.Message) bool {
|
2013-05-08 00:08:18 +00:00
|
|
|
return false
|
|
|
|
}
|
2013-06-01 17:10:15 +00:00
|
|
|
|
|
|
|
// Register any web URLs desired
|
|
|
|
func (p *TalkerPlugin) RegisterWeb() *string {
|
|
|
|
return nil
|
|
|
|
}
|
2017-10-31 18:14:45 +00:00
|
|
|
|
|
|
|
func (p *TalkerPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
|