events: refactor

Combining all of the various send/recv functions into one
This commit is contained in:
Chris Sexton 2019-02-05 10:54:13 -05:00
parent 181f243b39
commit e7c88c0c9c
30 changed files with 271 additions and 236 deletions

View File

@ -19,7 +19,7 @@ import (
type bot struct { type bot struct {
// Each plugin must be registered in our plugins handler. To come: a map so that this // Each plugin must be registered in our plugins handler. To come: a map so that this
// will allow plugins to respond to specific kinds of events // will allow plugins to respond to specific kinds of events
plugins map[string]Handler plugins map[string]Plugin
pluginOrdering []string pluginOrdering []string
// Users holds information about all of our friends // Users holds information about all of our friends
@ -41,13 +41,16 @@ type bot struct {
// filters registered by plugins // filters registered by plugins
filters map[string]func(string) string filters map[string]func(string) string
callbacks map[string][]Callback
} }
// Variable represents a $var replacement
type Variable struct { type Variable struct {
Variable, Value string Variable, Value string
} }
// Newbot creates a bot for a given connection and set of handlers. // New creates a bot for a given connection and set of handlers.
func New(config *config.Config, connector Connector) Bot { func New(config *config.Config, connector Connector) Bot {
logIn := make(chan msg.Message) logIn := make(chan msg.Message)
logOut := make(chan msg.Messages) logOut := make(chan msg.Messages)
@ -62,7 +65,7 @@ func New(config *config.Config, connector Connector) Bot {
bot := &bot{ bot := &bot{
config: config, config: config,
plugins: make(map[string]Handler), plugins: make(map[string]Plugin),
pluginOrdering: make([]string, 0), pluginOrdering: make([]string, 0),
conn: connector, conn: connector,
users: users, users: users,
@ -71,6 +74,7 @@ func New(config *config.Config, connector Connector) Bot {
logOut: logOut, logOut: logOut,
httpEndPoints: make(map[string]string), httpEndPoints: make(map[string]string),
filters: make(map[string]func(string) string), filters: make(map[string]func(string) string),
callbacks: make(map[string][]Callback),
} }
bot.migrateDB() bot.migrateDB()
@ -109,7 +113,7 @@ func (b *bot) migrateDB() {
} }
// Adds a constructed handler to the bots handlers list // Adds a constructed handler to the bots handlers list
func (b *bot) AddHandler(name string, h Handler) { func (b *bot) AddPlugin(name string, h Plugin) {
b.plugins[name] = h b.plugins[name] = h
b.pluginOrdering = append(b.pluginOrdering, name) b.pluginOrdering = append(b.pluginOrdering, name)
if entry := h.RegisterWeb(); entry != nil { if entry := h.RegisterWeb(); entry != nil {
@ -126,7 +130,7 @@ func (b *bot) Who(channel string) []user.User {
return users return users
} }
var rootIndex string = ` var rootIndex = `
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<head> <head>
@ -166,7 +170,7 @@ func (b *bot) serveRoot(w http.ResponseWriter, r *http.Request) {
t.Execute(w, context) t.Execute(w, context)
} }
// Checks if message is a command and returns its curtailed version // IsCmd checks if message is a command and returns its curtailed version
func IsCmd(c *config.Config, message string) (bool, string) { func IsCmd(c *config.Config, message string) (bool, string) {
cmdcs := c.GetArray("CommandChar", []string{"!"}) cmdcs := c.GetArray("CommandChar", []string{"!"})
botnick := strings.ToLower(c.Get("Nick", "bot")) botnick := strings.ToLower(c.Get("Nick", "bot"))
@ -244,3 +248,9 @@ func (b *bot) checkAdmin(nick string) bool {
func (b *bot) RegisterFilter(name string, f func(string) string) { func (b *bot) RegisterFilter(name string, f func(string) string) {
b.filters[name] = f b.filters[name] = f
} }
// Send a message to the connection
func (b *bot) Send(int, ...interface{}) (error, string) { return nil, "" }
// Register a callback
func (b *bot) Register(int, Callback) {}

View File

@ -16,6 +16,10 @@ import (
"github.com/velour/catbase/bot/msg" "github.com/velour/catbase/bot/msg"
) )
func (b *bot) Receive(kind int, msg msg.Message, args ...interface{}) {
panic("I don't know what to do here yet")
}
// Handles incomming PRIVMSG requests // Handles incomming PRIVMSG requests
func (b *bot) MsgReceived(msg msg.Message) { func (b *bot) MsgReceived(msg msg.Message) {
log.Println("Received message: ", msg) log.Println("Received message: ", msg)
@ -29,9 +33,8 @@ func (b *bot) MsgReceived(msg msg.Message) {
} }
for _, name := range b.pluginOrdering { for _, name := range b.pluginOrdering {
p := b.plugins[name] if b.runCallback(name, Message, msg) {
if p.Message(msg) { goto RET
break
} }
} }
@ -45,47 +48,54 @@ func (b *bot) EventReceived(msg msg.Message) {
log.Println("Received event: ", msg) log.Println("Received event: ", msg)
//msg := b.buildMessage(conn, inMsg) //msg := b.buildMessage(conn, inMsg)
for _, name := range b.pluginOrdering { for _, name := range b.pluginOrdering {
p := b.plugins[name] if b.runCallback(name, Event, msg) {
if p.Event(msg.Body, msg) { // TODO: could get rid of msg.Body return
break
} }
} }
} }
func (b *bot) runCallback(plugin string, evt int, message msg.Message, args ...interface{}) bool {
for _, cb := range b.callbacks[plugin] {
if cb(evt, message) {
return true
}
}
return false
}
// Handle incoming replys // Handle incoming replys
func (b *bot) ReplyMsgReceived(msg msg.Message, identifier string) { func (b *bot) ReplyMsgReceived(msg msg.Message, identifier string) {
log.Println("Received message: ", msg) log.Println("Received message: ", msg)
for _, name := range b.pluginOrdering { for _, name := range b.pluginOrdering {
p := b.plugins[name] if b.runCallback(name, Reply, msg, identifier) {
if p.ReplyMessage(msg, identifier) {
break break
} }
} }
} }
func (b *bot) SendMessage(channel, message string) string { func (b *bot) SendMessage(channel, message string) (error, string) {
return b.conn.SendMessage(channel, message) return b.conn.Send(Message, channel, message)
} }
func (b *bot) SendAction(channel, message string) string { func (b *bot) SendAction(channel, message string) (error, string) {
return b.conn.SendAction(channel, message) return b.conn.Send(Action, channel, message)
} }
func (b *bot) ReplyToMessageIdentifier(channel, message, identifier string) (string, bool) { func (b *bot) ReplyToMessageIdentifier(channel, message, identifier string) (error, string) {
return b.conn.ReplyToMessageIdentifier(channel, message, identifier) return b.conn.Send(Reply, channel, message, identifier)
} }
func (b *bot) ReplyToMessage(channel, message string, replyTo msg.Message) (string, bool) { func (b *bot) ReplyToMessage(channel, message string, replyTo msg.Message) (error, string) {
return b.conn.ReplyToMessage(channel, message, replyTo) return b.conn.Send(Reply, channel, message, replyTo)
} }
func (b *bot) React(channel, reaction string, message msg.Message) bool { func (b *bot) React(channel, reaction string, message msg.Message) (error, string) {
return b.conn.React(channel, reaction, message) return b.conn.Send(Reaction, channel, reaction, message)
} }
func (b *bot) Edit(channel, newMessage, identifier string) bool { func (b *bot) Edit(channel, newMessage, identifier string) (error, string) {
return b.conn.Edit(channel, newMessage, identifier) return b.conn.Send(Edit, channel, newMessage, identifier)
} }
func (b *bot) GetEmojiList() map[string]string { func (b *bot) GetEmojiList() map[string]string {
@ -113,7 +123,8 @@ func (b *bot) checkHelp(channel string, parts []string) {
} }
plugin := b.plugins[parts[1]] plugin := b.plugins[parts[1]]
if plugin != nil { if plugin != nil {
plugin.Help(channel, parts) // TODO: Maybe broke
b.runCallback(parts[1], Help, msg.Message{Channel: channel}, channel, parts)
} else { } else {
msg := fmt.Sprintf("I'm sorry, I don't know what %s is!", parts[1]) msg := fmt.Sprintf("I'm sorry, I don't know what %s is!", parts[1])
b.SendMessage(channel, msg) b.SendMessage(channel, msg)
@ -236,9 +247,8 @@ func (b *bot) selfSaid(channel, message string, action bool) {
} }
for _, name := range b.pluginOrdering { for _, name := range b.pluginOrdering {
p := b.plugins[name] if b.runCallback(name, SelfMessage, msg) {
if p.BotMessage(msg) { return
break
} }
} }
} }

View File

@ -9,22 +9,47 @@ import (
"github.com/velour/catbase/config" "github.com/velour/catbase/config"
) )
const (
_ = iota
// Message any standard chat
Message
// Reply something containing a message reference
Reply
// Action any /me action
Action
// Reaction Icon reaction if service supports it
Reaction
// Edit message ref'd new message to replace
Edit
// Not sure what event is
Event
// Help is used when the bot help system is triggered
Help
// SelfMessage triggers when the bot is sending a message
SelfMessage
)
type kind int
type Callback func(int, msg.Message, ...interface{}) bool
type Bot interface { type Bot interface {
Config() *config.Config Config() *config.Config
DB() *sqlx.DB DB() *sqlx.DB
Who(string) []user.User Who(string) []user.User
AddHandler(string, Handler) AddPlugin(string, Plugin)
SendMessage(string, string) string
SendAction(string, string) string // First arg should be one of bot.Message/Reply/Action/etc
ReplyToMessageIdentifier(string, string, string) (string, bool) Send(int, ...interface{}) (error, string)
ReplyToMessage(string, string, msg.Message) (string, bool) // First arg should be one of bot.Message/Reply/Action/etc
React(string, string, msg.Message) bool Receive(int, msg.Message, ...interface{})
Edit(string, string, string) bool // Register a callback
MsgReceived(msg.Message) Register(int, Callback)
ReplyMsgReceived(msg.Message, string)
EventReceived(msg.Message)
Filter(msg.Message, string) string Filter(msg.Message, string) string
LastMessage(string) (msg.Message, error) LastMessage(string) (msg.Message, error)
CheckAdmin(string) bool CheckAdmin(string) bool
GetEmojiList() map[string]string GetEmojiList() map[string]string
RegisterFilter(string, func(string) string) RegisterFilter(string, func(string) string)
@ -35,12 +60,8 @@ type Connector interface {
RegisterMessageReceived(func(message msg.Message)) RegisterMessageReceived(func(message msg.Message))
RegisterReplyMessageReceived(func(msg.Message, string)) RegisterReplyMessageReceived(func(msg.Message, string))
SendMessage(channel, message string) string Send(int, ...interface{}) (error, string)
SendAction(channel, message string) string
ReplyToMessageIdentifier(string, string, string) (string, bool)
ReplyToMessage(string, string, msg.Message) (string, bool)
React(string, string, msg.Message) bool
Edit(string, string, string) bool
GetEmojiList() map[string]string GetEmojiList() map[string]string
Serve() error Serve() error
@ -48,11 +69,6 @@ type Connector interface {
} }
// Interface used for compatibility with the Plugin interface // Interface used for compatibility with the Plugin interface
type Handler interface { type Plugin interface {
Message(message msg.Message) bool
Event(kind string, message msg.Message) bool
ReplyMessage(msg.Message, string) bool
BotMessage(message msg.Message) bool
Help(channel string, parts []string)
RegisterWeb() *string RegisterWeb() *string
} }

View File

@ -26,12 +26,11 @@ type MockBot struct {
Reactions []string Reactions []string
} }
func (mb *MockBot) Config() *config.Config { return mb.Cfg } func (mb *MockBot) Config() *config.Config { return mb.Cfg }
func (mb *MockBot) DBVersion() int64 { return 1 } func (mb *MockBot) DBVersion() int64 { return 1 }
func (mb *MockBot) DB() *sqlx.DB { return mb.Cfg.DB } func (mb *MockBot) DB() *sqlx.DB { return mb.Cfg.DB }
func (mb *MockBot) Conn() Connector { return nil } func (mb *MockBot) Conn() Connector { return nil }
func (mb *MockBot) Who(string) []user.User { return []user.User{} } func (mb *MockBot) Who(string) []user.User { return []user.User{} }
func (mb *MockBot) AddHandler(name string, f Handler) {}
func (mb *MockBot) SendMessage(ch string, msg string) string { func (mb *MockBot) SendMessage(ch string, msg string) string {
mb.Messages = append(mb.Messages, msg) mb.Messages = append(mb.Messages, msg)
return fmt.Sprintf("m-%d", len(mb.Actions)-1) return fmt.Sprintf("m-%d", len(mb.Actions)-1)

50
main.go
View File

@ -78,32 +78,32 @@ func main() {
b := bot.New(c, client) b := bot.New(c, client)
b.AddHandler("admin", admin.New(b)) b.AddPlugin("admin", admin.New(b))
b.AddHandler("first", first.New(b)) b.AddPlugin("first", first.New(b))
b.AddHandler("leftpad", leftpad.New(b)) b.AddPlugin("leftpad", leftpad.New(b))
b.AddHandler("talker", talker.New(b)) b.AddPlugin("talker", talker.New(b))
b.AddHandler("dice", dice.New(b)) b.AddPlugin("dice", dice.New(b))
b.AddHandler("picker", picker.New(b)) b.AddPlugin("picker", picker.New(b))
b.AddHandler("beers", beers.New(b)) b.AddPlugin("beers", beers.New(b))
b.AddHandler("remember", fact.NewRemember(b)) b.AddPlugin("remember", fact.NewRemember(b))
b.AddHandler("your", your.New(b)) b.AddPlugin("your", your.New(b))
b.AddHandler("counter", counter.New(b)) b.AddPlugin("counter", counter.New(b))
b.AddHandler("reminder", reminder.New(b)) b.AddPlugin("reminder", reminder.New(b))
b.AddHandler("babbler", babbler.New(b)) b.AddPlugin("babbler", babbler.New(b))
b.AddHandler("zork", zork.New(b)) b.AddPlugin("zork", zork.New(b))
b.AddHandler("rss", rss.New(b)) b.AddPlugin("rss", rss.New(b))
b.AddHandler("reaction", reaction.New(b)) b.AddPlugin("reaction", reaction.New(b))
b.AddHandler("emojifyme", emojifyme.New(b)) b.AddPlugin("emojifyme", emojifyme.New(b))
b.AddHandler("twitch", twitch.New(b)) b.AddPlugin("twitch", twitch.New(b))
b.AddHandler("inventory", inventory.New(b)) b.AddPlugin("inventory", inventory.New(b))
b.AddHandler("rpgORdie", rpgORdie.New(b)) b.AddPlugin("rpgORdie", rpgORdie.New(b))
b.AddHandler("sisyphus", sisyphus.New(b)) b.AddPlugin("sisyphus", sisyphus.New(b))
b.AddHandler("tell", tell.New(b)) b.AddPlugin("tell", tell.New(b))
b.AddHandler("couldashouldawoulda", couldashouldawoulda.New(b)) b.AddPlugin("couldashouldawoulda", couldashouldawoulda.New(b))
b.AddHandler("nedepedia", nerdepedia.New(b)) b.AddPlugin("nedepedia", nerdepedia.New(b))
// catches anything left, will always return true // catches anything left, will always return true
b.AddHandler("factoid", fact.New(b)) b.AddPlugin("factoid", fact.New(b))
b.AddHandler("db", db.New(b)) b.AddPlugin("db", db.New(b))
for { for {
err := client.Serve() err := client.Serve()

View File

@ -62,7 +62,7 @@ func (p *AdminPlugin) Message(message msg.Message) bool {
if strings.ToLower(body) == "shut up" { if strings.ToLower(body) == "shut up" {
dur := time.Duration(p.cfg.GetInt("quietDuration", 5)) * time.Minute dur := time.Duration(p.cfg.GetInt("quietDuration", 5)) * time.Minute
log.Printf("Going to sleep for %v, %v", dur, time.Now().Add(dur)) log.Printf("Going to sleep for %v, %v", dur, time.Now().Add(dur))
p.Bot.SendMessage(message.Channel, "Okay. I'll be back later.") p.Bot.Send(bot.Message, message.Channel, "Okay. I'll be back later.")
p.quiet = true p.quiet = true
go func() { go func() {
select { select {
@ -76,19 +76,19 @@ func (p *AdminPlugin) Message(message msg.Message) bool {
parts := strings.Split(body, " ") parts := strings.Split(body, " ")
if parts[0] == "set" && len(parts) > 2 && forbiddenKeys[parts[1]] { if parts[0] == "set" && len(parts) > 2 && forbiddenKeys[parts[1]] {
p.Bot.SendMessage(message.Channel, "You cannot access that key") p.Bot.Send(bot.Message, message.Channel, "You cannot access that key")
return true return true
} else if parts[0] == "set" && len(parts) > 2 { } else if parts[0] == "set" && len(parts) > 2 {
p.cfg.Set(parts[1], strings.Join(parts[2:], " ")) p.cfg.Set(parts[1], strings.Join(parts[2:], " "))
p.Bot.SendMessage(message.Channel, fmt.Sprintf("Set %s", parts[1])) p.Bot.Send(bot.Message, message.Channel, fmt.Sprintf("Set %s", parts[1]))
return true return true
} }
if parts[0] == "get" && len(parts) == 2 && forbiddenKeys[parts[1]] { if parts[0] == "get" && len(parts) == 2 && forbiddenKeys[parts[1]] {
p.Bot.SendMessage(message.Channel, "You cannot access that key") p.Bot.Send(bot.Message, message.Channel, "You cannot access that key")
return true return true
} else if parts[0] == "get" && len(parts) == 2 { } else if parts[0] == "get" && len(parts) == 2 {
v := p.cfg.Get(parts[1], "<unknown>") v := p.cfg.Get(parts[1], "<unknown>")
p.Bot.SendMessage(message.Channel, fmt.Sprintf("%s: %s", parts[1], v)) p.Bot.Send(bot.Message, message.Channel, fmt.Sprintf("%s: %s", parts[1], v))
return true return true
} }
@ -102,10 +102,10 @@ func (p *AdminPlugin) handleVariables(message msg.Message) bool {
_, err := p.db.Exec(`delete from variables where name=? and value=?`, variable, value) _, err := p.db.Exec(`delete from variables where name=? and value=?`, variable, value)
if err != nil { if err != nil {
p.Bot.SendMessage(message.Channel, "I'm broke and need attention in my variable creation code.") p.Bot.Send(bot.Message, message.Channel, "I'm broke and need attention in my variable creation code.")
log.Println("[admin]: ", err) log.Println("[admin]: ", err)
} else { } else {
p.Bot.SendMessage(message.Channel, "Removed.") p.Bot.Send(bot.Message, message.Channel, "Removed.")
} }
return true return true
@ -123,28 +123,28 @@ func (p *AdminPlugin) handleVariables(message msg.Message) bool {
row := p.db.QueryRow(`select count(*) from variables where value = ?`, variable, value) row := p.db.QueryRow(`select count(*) from variables where value = ?`, variable, value)
err := row.Scan(&count) err := row.Scan(&count)
if err != nil { if err != nil {
p.Bot.SendMessage(message.Channel, "I'm broke and need attention in my variable creation code.") p.Bot.Send(bot.Message, message.Channel, "I'm broke and need attention in my variable creation code.")
log.Println("[admin]: ", err) log.Println("[admin]: ", err)
return true return true
} }
if count > 0 { if count > 0 {
p.Bot.SendMessage(message.Channel, "I've already got that one.") p.Bot.Send(bot.Message, message.Channel, "I've already got that one.")
} else { } else {
_, err := p.db.Exec(`INSERT INTO variables (name, value) VALUES (?, ?)`, variable, value) _, err := p.db.Exec(`INSERT INTO variables (name, value) VALUES (?, ?)`, variable, value)
if err != nil { if err != nil {
p.Bot.SendMessage(message.Channel, "I'm broke and need attention in my variable creation code.") p.Bot.Send(bot.Message, message.Channel, "I'm broke and need attention in my variable creation code.")
log.Println("[admin]: ", err) log.Println("[admin]: ", err)
return true return true
} }
p.Bot.SendMessage(message.Channel, "Added.") p.Bot.Send(bot.Message, message.Channel, "Added.")
} }
return true return true
} }
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *AdminPlugin) Help(channel string, parts []string) { func (p *AdminPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "This does super secret things that you're not allowed to know about.") p.Bot.Send(bot.Message, channel, "This does super secret things that you're not allowed to know about.")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -141,7 +141,7 @@ func (p *BabblerPlugin) Message(message msg.Message) bool {
} }
if saidSomething { if saidSomething {
p.Bot.SendMessage(message.Channel, saidWhat) p.Bot.Send(bot.Message, message.Channel, saidWhat)
} }
return saidSomething return saidSomething
} }
@ -155,7 +155,7 @@ func (p *BabblerPlugin) Help(channel string, parts []string) {
"seabass says-middle-out ...", "seabass says-middle-out ...",
"seabass says-bridge ... | ...", "seabass says-bridge ... | ...",
} }
p.Bot.SendMessage(channel, strings.Join(commands, "\n\n")) p.Bot.Send(bot.Message, channel, strings.Join(commands, "\n\n"))
} }
func (p *BabblerPlugin) Event(kind string, message msg.Message) bool { func (p *BabblerPlugin) Event(kind string, message msg.Message) bool {

View File

@ -81,13 +81,13 @@ func (p *BeersPlugin) Message(message msg.Message) bool {
count, err := strconv.Atoi(parts[2]) count, err := strconv.Atoi(parts[2])
if err != nil { if err != nil {
// if it's not a number, maybe it's a nick! // if it's not a number, maybe it's a nick!
p.Bot.SendMessage(channel, "Sorry, that didn't make any sense.") p.Bot.Send(bot.Message, channel, "Sorry, that didn't make any sense.")
} }
if count < 0 { if count < 0 {
// you can't be negative // you can't be negative
msg := fmt.Sprintf("Sorry %s, you can't have negative beers!", nick) msg := fmt.Sprintf("Sorry %s, you can't have negative beers!", nick)
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
return true return true
} }
if parts[1] == "+=" { if parts[1] == "+=" {
@ -101,14 +101,14 @@ func (p *BeersPlugin) Message(message msg.Message) bool {
p.randomReply(channel) p.randomReply(channel)
} }
} else { } else {
p.Bot.SendMessage(channel, "I don't know your math.") p.Bot.Send(bot.Message, channel, "I don't know your math.")
} }
} else if len(parts) == 2 { } else if len(parts) == 2 {
if p.doIKnow(parts[1]) { if p.doIKnow(parts[1]) {
p.reportCount(parts[1], channel, false) p.reportCount(parts[1], channel, false)
} else { } else {
msg := fmt.Sprintf("Sorry, I don't know %s.", parts[1]) msg := fmt.Sprintf("Sorry, I don't know %s.", parts[1])
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
} else if len(parts) == 1 { } else if len(parts) == 1 {
p.reportCount(nick, channel, true) p.reportCount(nick, channel, true)
@ -132,7 +132,7 @@ func (p *BeersPlugin) Message(message msg.Message) bool {
channel := message.Channel channel := message.Channel
if len(parts) < 2 { if len(parts) < 2 {
p.Bot.SendMessage(channel, "You must also provide a user name.") p.Bot.Send(bot.Message, channel, "You must also provide a user name.")
} else if len(parts) == 3 { } else if len(parts) == 3 {
chanNick = parts[2] chanNick = parts[2]
} else if len(parts) == 4 { } else if len(parts) == 4 {
@ -154,7 +154,7 @@ func (p *BeersPlugin) Message(message msg.Message) bool {
log.Println("Error registering untappd: ", err) log.Println("Error registering untappd: ", err)
} }
if count > 0 { if count > 0 {
p.Bot.SendMessage(channel, "I'm already watching you.") p.Bot.Send(bot.Message, channel, "I'm already watching you.")
return true return true
} }
_, err = p.db.Exec(`insert into untappd ( _, err = p.db.Exec(`insert into untappd (
@ -170,11 +170,11 @@ func (p *BeersPlugin) Message(message msg.Message) bool {
) )
if err != nil { if err != nil {
log.Println("Error registering untappd: ", err) log.Println("Error registering untappd: ", err)
p.Bot.SendMessage(channel, "I can't see.") p.Bot.Send(bot.Message, channel, "I can't see.")
return true return true
} }
p.Bot.SendMessage(channel, "I'll be watching you.") p.Bot.Send(bot.Message, channel, "I'll be watching you.")
p.checkUntappd(channel) p.checkUntappd(channel)
@ -200,7 +200,7 @@ func (p *BeersPlugin) Help(channel string, parts []string) {
msg := "Beers: imbibe by using either beers +=,=,++ or with the !imbibe/drink " + msg := "Beers: imbibe by using either beers +=,=,++ or with the !imbibe/drink " +
"commands. I'll keep a count of how many beers you've had and then if you want " + "commands. I'll keep a count of how many beers you've had and then if you want " +
"to reset, just !puke it all up!" "to reset, just !puke it all up!"
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
func getUserBeers(db *sqlx.DB, user string) counter.Item { func getUserBeers(db *sqlx.DB, user string) counter.Item {
@ -239,13 +239,13 @@ func (p *BeersPlugin) reportCount(nick, channel string, himself bool) {
msg = fmt.Sprintf("You've had %d beers so far, %s.", beers, nick) msg = fmt.Sprintf("You've had %d beers so far, %s.", beers, nick)
} }
} }
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
func (p *BeersPlugin) puke(user string, channel string) { func (p *BeersPlugin) puke(user string, channel string) {
p.setBeers(user, 0) p.setBeers(user, 0)
msg := fmt.Sprintf("Ohhhhhh, and a reversal of fortune for %s!", user) msg := fmt.Sprintf("Ohhhhhh, and a reversal of fortune for %s!", user)
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
func (p *BeersPlugin) doIKnow(nick string) bool { func (p *BeersPlugin) doIKnow(nick string) bool {
@ -260,7 +260,7 @@ func (p *BeersPlugin) doIKnow(nick string) bool {
// Sends random affirmation to the channel. This could be better (with a datastore for sayings) // Sends random affirmation to the channel. This could be better (with a datastore for sayings)
func (p *BeersPlugin) randomReply(channel string) { func (p *BeersPlugin) randomReply(channel string) {
replies := []string{"ZIGGY! ZAGGY!", "HIC!", "Stay thirsty, my friend!"} replies := []string{"ZIGGY! ZAGGY!", "HIC!", "Stay thirsty, my friend!"}
p.Bot.SendMessage(channel, replies[rand.Intn(len(replies))]) p.Bot.Send(bot.Message, channel, replies[rand.Intn(len(replies))])
} }
type checkin struct { type checkin struct {
@ -421,7 +421,7 @@ func (p *BeersPlugin) checkUntappd(channel string) {
} }
log.Println("checkin id:", checkin.Checkin_id, "Message:", msg) log.Println("checkin id:", checkin.Checkin_id, "Message:", msg)
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
} }

View File

@ -63,7 +63,7 @@ func (p *CSWPlugin) Message(message msg.Message) bool {
} }
} }
p.Bot.SendMessage(message.Channel, responses[rand.Intn(len(responses))]) p.Bot.Send(bot.Message, message.Channel, responses[rand.Intn(len(responses))])
return true return true
} }

View File

@ -211,7 +211,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
log.Println(err) log.Println(err)
return false return false
} }
p.Bot.SendMessage(channel, fmt.Sprintf("Created alias %s -> %s", p.Bot.Send(bot.Message, channel, fmt.Sprintf("Created alias %s -> %s",
parts[1], parts[2])) parts[1], parts[2]))
return true return true
} else if strings.ToLower(parts[0]) == "leaderboard" { } else if strings.ToLower(parts[0]) == "leaderboard" {
@ -241,7 +241,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
it.Item, it.Item,
) )
} }
p.Bot.SendMessage(channel, out) p.Bot.Send(bot.Message, channel, out)
return true return true
} else if match := teaMatcher.MatchString(message.Body); match { } else if match := teaMatcher.MatchString(message.Body); match {
// check for tea match TTT // check for tea match TTT
@ -250,14 +250,14 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
items, err := GetItems(p.DB, strings.ToLower(nick)) items, err := GetItems(p.DB, strings.ToLower(nick))
if err != nil { if err != nil {
log.Printf("Error getting items to reset %s: %s", nick, err) log.Printf("Error getting items to reset %s: %s", nick, err)
p.Bot.SendMessage(channel, "Something is technically wrong with your counters.") p.Bot.Send(bot.Message, channel, "Something is technically wrong with your counters.")
return true return true
} }
log.Printf("Items: %+v", items) log.Printf("Items: %+v", items)
for _, item := range items { for _, item := range items {
item.Delete() item.Delete()
} }
p.Bot.SendMessage(channel, fmt.Sprintf("%s, you are as new, my son.", nick)) p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s, you are as new, my son.", nick))
return true return true
} else if message.Command && parts[0] == "inspect" && len(parts) == 2 { } else if message.Command && parts[0] == "inspect" && len(parts) == 2 {
var subject string var subject string
@ -273,7 +273,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
items, err := GetItems(p.DB, subject) items, err := GetItems(p.DB, subject)
if err != nil { if err != nil {
log.Fatalf("Error retrieving items for %s: %s", subject, err) log.Fatalf("Error retrieving items for %s: %s", subject, err)
p.Bot.SendMessage(channel, "Something went wrong finding that counter;") p.Bot.Send(bot.Message, channel, "Something went wrong finding that counter;")
return true return true
} }
@ -293,11 +293,11 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
resp += "." resp += "."
if count == 0 { if count == 0 {
p.Bot.SendMessage(channel, fmt.Sprintf("%s has no counters.", subject)) p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has no counters.", subject))
return true return true
} }
p.Bot.SendMessage(channel, resp) p.Bot.Send(bot.Message, channel, resp)
return true return true
} else if message.Command && len(parts) == 2 && parts[0] == "clear" { } else if message.Command && len(parts) == 2 && parts[0] == "clear" {
subject := strings.ToLower(nick) subject := strings.ToLower(nick)
@ -306,17 +306,17 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
it, err := GetItem(p.DB, subject, itemName) it, err := GetItem(p.DB, subject, itemName)
if err != nil { if err != nil {
log.Printf("Error getting item to remove %s.%s: %s", subject, itemName, err) log.Printf("Error getting item to remove %s.%s: %s", subject, itemName, err)
p.Bot.SendMessage(channel, "Something went wrong removing that counter;") p.Bot.Send(bot.Message, channel, "Something went wrong removing that counter;")
return true return true
} }
err = it.Delete() err = it.Delete()
if err != nil { if err != nil {
log.Printf("Error removing item %s.%s: %s", subject, itemName, err) log.Printf("Error removing item %s.%s: %s", subject, itemName, err)
p.Bot.SendMessage(channel, "Something went wrong removing that counter;") p.Bot.Send(bot.Message, channel, "Something went wrong removing that counter;")
return true return true
} }
p.Bot.SendAction(channel, fmt.Sprintf("chops a few %s out of his brain", p.Bot.Send(bot.Action, channel, fmt.Sprintf("chops a few %s out of his brain",
itemName)) itemName))
return true return true
@ -339,7 +339,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
item, err := GetItem(p.DB, subject, itemName) item, err := GetItem(p.DB, subject, itemName)
switch { switch {
case err == sql.ErrNoRows: case err == sql.ErrNoRows:
p.Bot.SendMessage(channel, fmt.Sprintf("I don't think %s has any %s.", p.Bot.Send(bot.Message, channel, fmt.Sprintf("I don't think %s has any %s.",
subject, itemName)) subject, itemName))
return true return true
case err != nil: case err != nil:
@ -348,7 +348,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
return true return true
} }
p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, item.Count, p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has %d %s.", subject, item.Count,
itemName)) itemName))
return true return true
@ -379,7 +379,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
} }
log.Printf("About to update item: %#v", item) log.Printf("About to update item: %#v", item)
item.UpdateDelta(1) item.UpdateDelta(1)
p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has %d %s.", subject,
item.Count, item.Item)) item.Count, item.Item))
return true return true
} else if strings.HasSuffix(parts[0], "--") { } else if strings.HasSuffix(parts[0], "--") {
@ -391,7 +391,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
return false return false
} }
item.UpdateDelta(-1) item.UpdateDelta(-1)
p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has %d %s.", subject,
item.Count, item.Item)) item.Count, item.Item))
return true return true
} }
@ -420,7 +420,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
n, _ := strconv.Atoi(parts[2]) n, _ := strconv.Atoi(parts[2])
log.Printf("About to update item by %d: %#v", n, item) log.Printf("About to update item by %d: %#v", n, item)
item.UpdateDelta(n) item.UpdateDelta(n)
p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has %d %s.", subject,
item.Count, item.Item)) item.Count, item.Item))
return true return true
} else if parts[1] == "-=" { } else if parts[1] == "-=" {
@ -434,7 +434,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
n, _ := strconv.Atoi(parts[2]) n, _ := strconv.Atoi(parts[2])
log.Printf("About to update item by -%d: %#v", n, item) log.Printf("About to update item by -%d: %#v", n, item)
item.UpdateDelta(-n) item.UpdateDelta(-n)
p.Bot.SendMessage(channel, fmt.Sprintf("%s has %d %s.", subject, p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has %d %s.", subject,
item.Count, item.Item)) item.Count, item.Item))
return true return true
} }
@ -445,7 +445,7 @@ func (p *CounterPlugin) Message(message msg.Message) bool {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *CounterPlugin) Help(channel string, parts []string) { func (p *CounterPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "You can set counters incrementally by using "+ p.Bot.Send(bot.Message, channel, "You can set counters incrementally by using "+
"<noun>++ and <noun>--. You can see all of your counters using "+ "<noun>++ and <noun>--. You can see all of your counters using "+
"\"inspect\", erase them with \"clear\", and view single counters with "+ "\"inspect\", erase them with \"clear\", and view single counters with "+
"\"count\".") "\"count\".")
@ -487,7 +487,7 @@ func (p *CounterPlugin) checkMatch(message msg.Message) bool {
} }
log.Printf("About to update item: %#v", item) log.Printf("About to update item: %#v", item)
item.UpdateDelta(1) item.UpdateDelta(1)
p.Bot.SendMessage(channel, fmt.Sprintf("bleep-bloop-blop... %s has %d %s", p.Bot.Send(bot.Message, channel, fmt.Sprintf("bleep-bloop-blop... %s has %d %s",
nick, item.Count, itemName)) nick, item.Count, itemName))
return true return true
} }

View File

@ -46,7 +46,7 @@ func (p *DicePlugin) Message(message msg.Message) bool {
} }
if sides < 2 || nDice < 1 || nDice > 20 { if sides < 2 || nDice < 1 || nDice > 20 {
p.Bot.SendMessage(channel, "You're a dick.") p.Bot.Send(bot.Message, channel, "You're a dick.")
return true return true
} }
@ -61,14 +61,14 @@ func (p *DicePlugin) Message(message msg.Message) bool {
} }
} }
p.Bot.SendMessage(channel, rolls) p.Bot.Send(bot.Message, channel, rolls)
return true return true
} }
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *DicePlugin) Help(channel string, parts []string) { func (p *DicePlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Roll dice using notation XdY. Try \"3d20\".") p.Bot.Send(bot.Message, channel, "Roll dice using notation XdY. Try \"3d20\".")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -142,9 +142,9 @@ func (p *DowntimePlugin) Message(message msg.Message) bool {
} }
if !entry.id.Valid { if !entry.id.Valid {
// couldn't find em // couldn't find em
p.Bot.SendMessage(channel, fmt.Sprintf("Sorry, I don't know %s.", nick)) p.Bot.Send(bot.Message, channel, fmt.Sprintf("Sorry, I don't know %s.", nick))
} else { } else {
p.Bot.SendMessage(channel, fmt.Sprintf("%s has been idle for: %s", p.Bot.Send(bot.Message, channel, fmt.Sprintf("%s has been idle for: %s",
nick, time.Now().Sub(entry.lastSeen))) nick, time.Now().Sub(entry.lastSeen)))
} }
ret = true ret = true
@ -165,7 +165,7 @@ func (p *DowntimePlugin) Message(message msg.Message) bool {
tops = fmt.Sprintf("%s%s: %s ", tops, e.nick, time.Now().Sub(e.lastSeen)) tops = fmt.Sprintf("%s%s: %s ", tops, e.nick, time.Now().Sub(e.lastSeen))
} }
} }
p.Bot.SendMessage(channel, tops) p.Bot.Send(bot.Message, channel, tops)
ret = true ret = true
} }
@ -197,7 +197,7 @@ func (p *DowntimePlugin) remove(user string) error {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *DowntimePlugin) Help(channel string, parts []string) { func (p *DowntimePlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Ask me how long one of your friends has been idele with, \"idle <nick>\"") p.Bot.Send(bot.Message, channel, "Ask me how long one of your friends has been idele with, \"idle <nick>\"")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -90,7 +90,7 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool {
if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance", 0.02)*emojied { if emojied > 0 && rand.Float64() <= p.Bot.Config().GetFloat64("Emojify.Chance", 0.02)*emojied {
for _, e := range emojys { for _, e := range emojys {
p.Bot.React(message.Channel, e, message) p.Bot.Send(bot.Reaction, message.Channel, e, message)
} }
return true return true
} }

View File

@ -405,13 +405,13 @@ func (p *Factoid) sayFact(message msg.Message, fact factoid) {
} }
if fact.Verb == "action" { if fact.Verb == "action" {
p.Bot.SendAction(message.Channel, msg) p.Bot.Send(bot.Action, message.Channel, msg)
} else if fact.Verb == "react" { } else if fact.Verb == "react" {
p.Bot.React(message.Channel, msg, message) p.Bot.Send(bot.Reaction, message.Channel, msg, message)
} else if fact.Verb == "reply" { } else if fact.Verb == "reply" {
p.Bot.SendMessage(message.Channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
} else { } else {
p.Bot.SendMessage(message.Channel, full) p.Bot.Send(bot.Message, message.Channel, full)
} }
} }
@ -457,7 +457,7 @@ func (p *Factoid) tellThemWhatThatWas(message msg.Message) bool {
msg = fmt.Sprintf("That was (#%d) '%s <%s> %s'", msg = fmt.Sprintf("That was (#%d) '%s <%s> %s'",
fact.id.Int64, fact.Fact, fact.Verb, fact.Tidbit) fact.id.Int64, fact.Fact, fact.Verb, fact.Tidbit)
} }
p.Bot.SendMessage(message.Channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
return true return true
} }
@ -475,21 +475,21 @@ func (p *Factoid) learnAction(message msg.Message, action string) bool {
action = strings.TrimSpace(action) action = strings.TrimSpace(action)
if len(trigger) == 0 || len(fact) == 0 || len(action) == 0 { if len(trigger) == 0 || len(fact) == 0 || len(action) == 0 {
p.Bot.SendMessage(message.Channel, "I don't want to learn that.") p.Bot.Send(bot.Message, message.Channel, "I don't want to learn that.")
return true return true
} }
if len(strings.Split(fact, "$and")) > 4 { if len(strings.Split(fact, "$and")) > 4 {
p.Bot.SendMessage(message.Channel, "You can't use more than 4 $and operators.") p.Bot.Send(bot.Message, message.Channel, "You can't use more than 4 $and operators.")
return true return true
} }
strippedaction := strings.Replace(strings.Replace(action, "<", "", 1), ">", "", 1) strippedaction := strings.Replace(strings.Replace(action, "<", "", 1), ">", "", 1)
if err := p.learnFact(message, trigger, strippedaction, fact); err != nil { if err := p.learnFact(message, trigger, strippedaction, fact); err != nil {
p.Bot.SendMessage(message.Channel, err.Error()) p.Bot.Send(bot.Message, message.Channel, err.Error())
} else { } else {
p.Bot.SendMessage(message.Channel, fmt.Sprintf("Okay, %s.", message.User.Name)) p.Bot.Send(bot.Message, message.Channel, fmt.Sprintf("Okay, %s.", message.User.Name))
} }
return true return true
@ -509,7 +509,7 @@ func changeOperator(body string) string {
// an admin, it may be deleted // an admin, it may be deleted
func (p *Factoid) forgetLastFact(message msg.Message) bool { func (p *Factoid) forgetLastFact(message msg.Message) bool {
if p.LastFact == nil { if p.LastFact == nil {
p.Bot.SendMessage(message.Channel, "I refuse.") p.Bot.Send(bot.Message, message.Channel, "I refuse.")
return true return true
} }
@ -519,7 +519,7 @@ func (p *Factoid) forgetLastFact(message msg.Message) bool {
} }
fmt.Printf("Forgot #%d: %s %s %s\n", p.LastFact.id.Int64, p.LastFact.Fact, fmt.Printf("Forgot #%d: %s %s %s\n", p.LastFact.id.Int64, p.LastFact.Fact,
p.LastFact.Verb, p.LastFact.Tidbit) p.LastFact.Verb, p.LastFact.Tidbit)
p.Bot.SendAction(message.Channel, "hits himself over the head with a skillet") p.Bot.Send(bot.Action, message.Channel, "hits himself over the head with a skillet")
p.LastFact = nil p.LastFact = nil
return true return true
@ -539,7 +539,7 @@ func (p *Factoid) changeFact(message msg.Message) bool {
if len(parts) == 4 { if len(parts) == 4 {
// replacement // replacement
if parts[0] != "s" { if parts[0] != "s" {
p.Bot.SendMessage(message.Channel, "Nah.") p.Bot.Send(bot.Message, message.Channel, "Nah.")
} }
find := parts[1] find := parts[1]
replace := parts[2] replace := parts[2]
@ -554,10 +554,10 @@ func (p *Factoid) changeFact(message msg.Message) bool {
} }
// make the changes // make the changes
msg := fmt.Sprintf("Changing %d facts.", len(result)) msg := fmt.Sprintf("Changing %d facts.", len(result))
p.Bot.SendMessage(message.Channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
reg, err := regexp.Compile(find) reg, err := regexp.Compile(find)
if err != nil { if err != nil {
p.Bot.SendMessage(message.Channel, "I don't really want to.") p.Bot.Send(bot.Message, message.Channel, "I don't really want to.")
return false return false
} }
for _, fact := range result { for _, fact := range result {
@ -574,12 +574,12 @@ func (p *Factoid) changeFact(message msg.Message) bool {
result, err := getFacts(p.db, trigger, parts[1]) result, err := getFacts(p.db, trigger, parts[1])
if err != nil { if err != nil {
log.Println("Error getting facts: ", trigger, err) log.Println("Error getting facts: ", trigger, err)
p.Bot.SendMessage(message.Channel, "bzzzt") p.Bot.Send(bot.Message, message.Channel, "bzzzt")
return true return true
} }
count := len(result) count := len(result)
if count == 0 { if count == 0 {
p.Bot.SendMessage(message.Channel, "I didn't find any facts like that.") p.Bot.Send(bot.Message, message.Channel, "I didn't find any facts like that.")
return true return true
} }
if parts[2] == "g" && len(result) > 4 { if parts[2] == "g" && len(result) > 4 {
@ -599,9 +599,9 @@ func (p *Factoid) changeFact(message msg.Message) bool {
if count > 4 { if count > 4 {
msg = fmt.Sprintf("%s | ...and %d others", msg, count) msg = fmt.Sprintf("%s | ...and %d others", msg, count)
} }
p.Bot.SendMessage(message.Channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
} else { } else {
p.Bot.SendMessage(message.Channel, "I don't know what you mean.") p.Bot.Send(bot.Message, message.Channel, "I don't know what you mean.")
} }
return true return true
} }
@ -625,14 +625,14 @@ func (p *Factoid) Message(message msg.Message) bool {
m := strings.TrimPrefix(message.Body, "alias ") m := strings.TrimPrefix(message.Body, "alias ")
parts := strings.SplitN(m, "->", 2) parts := strings.SplitN(m, "->", 2)
if len(parts) != 2 { if len(parts) != 2 {
p.Bot.SendMessage(message.Channel, "If you want to alias something, use: `alias this -> that`") p.Bot.Send(bot.Message, message.Channel, "If you want to alias something, use: `alias this -> that`")
return true return true
} }
a := aliasFromStrings(strings.TrimSpace(parts[1]), strings.TrimSpace(parts[0])) a := aliasFromStrings(strings.TrimSpace(parts[1]), strings.TrimSpace(parts[0]))
if err := a.save(p.db); err != nil { if err := a.save(p.db); err != nil {
p.Bot.SendMessage(message.Channel, err.Error()) p.Bot.Send(bot.Message, message.Channel, err.Error())
} else { } else {
p.Bot.SendAction(message.Channel, "learns a new synonym") p.Bot.Send(bot.Action, message.Channel, "learns a new synonym")
} }
return true return true
} }
@ -664,14 +664,14 @@ func (p *Factoid) Message(message msg.Message) bool {
} }
// We didn't find anything, panic! // We didn't find anything, panic!
p.Bot.SendMessage(message.Channel, p.NotFound[rand.Intn(len(p.NotFound))]) p.Bot.Send(bot.Message, message.Channel, p.NotFound[rand.Intn(len(p.NotFound))])
return true return true
} }
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *Factoid) Help(channel string, parts []string) { func (p *Factoid) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "I can learn facts and spit them back out. You can say \"this is that\" or \"he <has> $5\". Later, trigger the factoid by just saying the trigger word, \"this\" or \"he\" in these examples.") p.Bot.Send(bot.Message, channel, "I can learn facts and spit them back out. You can say \"this is that\" or \"he <has> $5\". Later, trigger the factoid by just saying the trigger word, \"this\" or \"he\" in these examples.")
p.Bot.SendMessage(channel, "I can also figure out some variables including: $nonzero, $digit, $nick, and $someone.") p.Bot.Send(bot.Message, channel, "I can also figure out some variables including: $nonzero, $digit, $nick, and $someone.")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -40,7 +40,7 @@ func (p *RememberPlugin) Message(message msg.Message) bool {
if strings.ToLower(message.Body) == "quote" && message.Command { if strings.ToLower(message.Body) == "quote" && message.Command {
q := p.randQuote() q := p.randQuote()
p.Bot.SendMessage(message.Channel, q) p.Bot.Send(bot.Message, message.Channel, q)
// is it evil not to remember that the user said quote? // is it evil not to remember that the user said quote?
return true return true
@ -87,7 +87,7 @@ func (p *RememberPlugin) Message(message msg.Message) bool {
} }
if err := fact.save(p.db); err != nil { if err := fact.save(p.db); err != nil {
log.Println("ERROR!!!!:", err) log.Println("ERROR!!!!:", err)
p.Bot.SendMessage(message.Channel, "Tell somebody I'm broke.") p.Bot.Send(bot.Message, message.Channel, "Tell somebody I'm broke.")
} }
log.Println("Remembering factoid:", msg) log.Println("Remembering factoid:", msg)
@ -95,14 +95,14 @@ func (p *RememberPlugin) Message(message msg.Message) bool {
// sorry, not creative with names so we're reusing msg // sorry, not creative with names so we're reusing msg
msg = fmt.Sprintf("Okay, %s, remembering '%s'.", msg = fmt.Sprintf("Okay, %s, remembering '%s'.",
message.User.Name, msg) message.User.Name, msg)
p.Bot.SendMessage(message.Channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
p.recordMsg(message) p.recordMsg(message)
return true return true
} }
} }
p.Bot.SendMessage(message.Channel, "Sorry, I don't know that phrase.") p.Bot.Send(bot.Message, message.Channel, "Sorry, I don't know that phrase.")
p.recordMsg(message) p.recordMsg(message)
return true return true
} }
@ -118,7 +118,7 @@ func (p *RememberPlugin) Help(channel string, parts []string) {
"be any part of their message. Later on, you can ask for a random " + "be any part of their message. Later on, you can ask for a random " +
"!quote." "!quote."
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
// deliver a random quote out of the db. // deliver a random quote out of the db.

View File

@ -195,7 +195,7 @@ func (p *FirstPlugin) recordFirst(message msg.Message) {
func (p *FirstPlugin) announceFirst(message msg.Message) { func (p *FirstPlugin) announceFirst(message msg.Message) {
c := message.Channel c := message.Channel
if p.First != nil { if p.First != nil {
p.Bot.SendMessage(c, fmt.Sprintf("%s had first at %s with the message: \"%s\"", p.Bot.Send(bot.Message, c, fmt.Sprintf("%s had first at %s with the message: \"%s\"",
p.First.nick, p.First.time.Format("15:04"), p.First.body)) p.First.nick, p.First.time.Format("15:04"), p.First.body))
} }
} }
@ -209,7 +209,7 @@ func (p *FirstPlugin) LoadData() {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *FirstPlugin) Help(channel string, parts []string) { func (p *FirstPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Sorry, First does not do a goddamn thing.") p.Bot.Send(bot.Message, channel, "Sorry, First does not do a goddamn thing.")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -86,7 +86,7 @@ func (p *InventoryPlugin) Message(message msg.Message) bool {
log.Printf("I think I have more than 0 items: %+v, len(items)=%d", items, len(items)) log.Printf("I think I have more than 0 items: %+v, len(items)=%d", items, len(items))
say = fmt.Sprintf("I'm currently holding %s", strings.Join(items, ", ")) say = fmt.Sprintf("I'm currently holding %s", strings.Join(items, ", "))
} }
p.bot.SendMessage(message.Channel, say) p.bot.Send(bot.Message, message.Channel, say)
return true return true
} }
@ -197,7 +197,7 @@ func (p *InventoryPlugin) remove(i string) {
func (p *InventoryPlugin) addItem(m msg.Message, i string) bool { func (p *InventoryPlugin) addItem(m msg.Message, i string) bool {
if p.exists(i) { if p.exists(i) {
p.bot.SendMessage(m.Channel, fmt.Sprintf("I already have %s.", i)) p.bot.Send(bot.Message, m.Channel, fmt.Sprintf("I already have %s.", i))
return true return true
} }
var removed string var removed string
@ -210,9 +210,9 @@ func (p *InventoryPlugin) addItem(m msg.Message, i string) bool {
log.Printf("Error inserting new inventory item: %s", err) log.Printf("Error inserting new inventory item: %s", err)
} }
if removed != "" { if removed != "" {
p.bot.SendAction(m.Channel, fmt.Sprintf("dropped %s and took %s from %s", removed, i, m.User.Name)) p.bot.Send(bot.Action, m.Channel, fmt.Sprintf("dropped %s and took %s from %s", removed, i, m.User.Name))
} else { } else {
p.bot.SendAction(m.Channel, fmt.Sprintf("takes %s from %s", i, m.User.Name)) p.bot.Send(bot.Action, m.Channel, fmt.Sprintf("takes %s from %s", i, m.User.Name))
} }
return true return true
} }

View File

@ -42,20 +42,20 @@ func (p *LeftpadPlugin) Message(message msg.Message) bool {
padchar := parts[1] padchar := parts[1]
length, err := strconv.Atoi(parts[2]) length, err := strconv.Atoi(parts[2])
if err != nil { if err != nil {
p.bot.SendMessage(message.Channel, "Invalid padding number") p.bot.Send(bot.Message, message.Channel, "Invalid padding number")
return true return true
} }
maxLen, who := p.config.GetInt("LeftPad.MaxLen", 50), p.config.Get("LeftPad.Who", "Putin") maxLen, who := p.config.GetInt("LeftPad.MaxLen", 50), p.config.Get("LeftPad.Who", "Putin")
if length > maxLen && maxLen > 0 { if length > maxLen && maxLen > 0 {
msg := fmt.Sprintf("%s would kill me if I did that.", who) msg := fmt.Sprintf("%s would kill me if I did that.", who)
p.bot.SendMessage(message.Channel, msg) p.bot.Send(bot.Message, message.Channel, msg)
return true return true
} }
text := strings.Join(parts[3:], " ") text := strings.Join(parts[3:], " ")
res := leftpad.LeftPad(text, length, padchar) res := leftpad.LeftPad(text, length, padchar)
p.bot.SendMessage(message.Channel, res) p.bot.Send(bot.Message, message.Channel, res)
return true return true
} }

View File

@ -78,7 +78,7 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool {
} }
if description != "" && link != "" { if description != "" && link != "" {
p.bot.SendMessage(message.Channel, fmt.Sprintf("%s (%s)", description, link)) p.bot.Send(bot.Message, message.Channel, fmt.Sprintf("%s (%s)", description, link))
return true return true
} }
} }
@ -88,7 +88,7 @@ func (p *NerdepediaPlugin) Message(message msg.Message) bool {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *NerdepediaPlugin) Help(channel string, parts []string) { func (p *NerdepediaPlugin) Help(channel string, parts []string) {
p.bot.SendMessage(channel, "nerd stuff") p.bot.Send(bot.Message, channel, "nerd stuff")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -36,14 +36,14 @@ func (p *PickerPlugin) Message(message msg.Message) bool {
n, items, err := p.parse(message.Body) n, items, err := p.parse(message.Body)
if err != nil { if err != nil {
p.Bot.SendMessage(message.Channel, err.Error()) p.Bot.Send(bot.Message, message.Channel, err.Error())
return true return true
} }
if n == 1 { if n == 1 {
item := items[rand.Intn(len(items))] item := items[rand.Intn(len(items))]
out := fmt.Sprintf("I've chosen %q for you.", strings.TrimSpace(item)) out := fmt.Sprintf("I've chosen %q for you.", strings.TrimSpace(item))
p.Bot.SendMessage(message.Channel, out) p.Bot.Send(bot.Message, message.Channel, out)
return true return true
} }
@ -59,7 +59,7 @@ func (p *PickerPlugin) Message(message msg.Message) bool {
fmt.Fprintf(&b, ", %q", item) fmt.Fprintf(&b, ", %q", item)
} }
b.WriteString(" }") b.WriteString(" }")
p.Bot.SendMessage(message.Channel, b.String()) p.Bot.Send(bot.Message, message.Channel, b.String())
return true return true
} }
@ -109,7 +109,7 @@ func (p *PickerPlugin) parse(body string) (int, []string, error) {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *PickerPlugin) Help(channel string, parts []string) { func (p *PickerPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Choose from a list of options. Try \"pick {a,b,c}\".") p.Bot.Send(bot.Message, channel, "Choose from a list of options. Try \"pick {a,b,c}\".")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -56,7 +56,7 @@ func (p *ReactionPlugin) Message(message msg.Message) bool {
reaction = p.Config.GetArray("Reaction.NegativeReactions", []string{})[index] reaction = p.Config.GetArray("Reaction.NegativeReactions", []string{})[index]
} }
p.Bot.React(message.Channel, reaction, message) p.Bot.Send(bot.Reaction, message.Channel, reaction, message)
} }
return false return false

View File

@ -85,7 +85,7 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
dur, err := time.ParseDuration(parts[3]) dur, err := time.ParseDuration(parts[3])
if err != nil { if err != nil {
p.Bot.SendMessage(channel, "Easy cowboy, not sure I can parse that duration.") p.Bot.Send(bot.Message, channel, "Easy cowboy, not sure I can parse that duration.")
return true return true
} }
@ -113,7 +113,7 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
//remind who every dur for dur2 blah //remind who every dur for dur2 blah
dur2, err := time.ParseDuration(parts[5]) dur2, err := time.ParseDuration(parts[5])
if err != nil { if err != nil {
p.Bot.SendMessage(channel, "Easy cowboy, not sure I can parse that duration.") p.Bot.Send(bot.Message, channel, "Easy cowboy, not sure I can parse that duration.")
return true return true
} }
@ -124,7 +124,7 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
max := p.config.GetInt("Reminder.MaxBatchAdd", 10) max := p.config.GetInt("Reminder.MaxBatchAdd", 10)
for i := 0; when.Before(endTime); i++ { for i := 0; when.Before(endTime); i++ {
if i >= max { if i >= max {
p.Bot.SendMessage(channel, "Easy cowboy, that's a lot of reminders. I'll add some of them.") p.Bot.Send(bot.Message, channel, "Easy cowboy, that's a lot of reminders. I'll add some of them.")
doConfirm = false doConfirm = false
break break
} }
@ -141,14 +141,14 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
when = when.Add(dur) when = when.Add(dur)
} }
} else { } else {
p.Bot.SendMessage(channel, "Easy cowboy, not sure I comprehend what you're asking.") p.Bot.Send(bot.Message, channel, "Easy cowboy, not sure I comprehend what you're asking.")
return true return true
} }
if doConfirm && from == who { if doConfirm && from == who {
p.Bot.SendMessage(channel, fmt.Sprintf("Okay. I'll remind you.")) p.Bot.Send(bot.Message, channel, fmt.Sprintf("Okay. I'll remind you."))
} else if doConfirm { } else if doConfirm {
p.Bot.SendMessage(channel, fmt.Sprintf("Sure %s, I'll remind %s.", from, who)) p.Bot.Send(bot.Message, channel, fmt.Sprintf("Sure %s, I'll remind %s.", from, who))
} }
p.queueUpNextReminder() p.queueUpNextReminder()
@ -168,22 +168,22 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
} }
} }
if err != nil { if err != nil {
p.Bot.SendMessage(channel, "listing failed.") p.Bot.Send(bot.Message, channel, "listing failed.")
} else { } else {
p.Bot.SendMessage(channel, response) p.Bot.Send(bot.Message, channel, response)
} }
return true return true
} else if len(parts) == 3 && strings.ToLower(parts[0]) == "cancel" && strings.ToLower(parts[1]) == "reminder" { } else if len(parts) == 3 && strings.ToLower(parts[0]) == "cancel" && strings.ToLower(parts[1]) == "reminder" {
id, err := strconv.ParseInt(parts[2], 10, 64) id, err := strconv.ParseInt(parts[2], 10, 64)
if err != nil { if err != nil {
p.Bot.SendMessage(channel, fmt.Sprintf("couldn't parse id: %s", parts[2])) p.Bot.Send(bot.Message, channel, fmt.Sprintf("couldn't parse id: %s", parts[2]))
} else { } else {
err := p.deleteReminder(id) err := p.deleteReminder(id)
if err == nil { if err == nil {
p.Bot.SendMessage(channel, fmt.Sprintf("successfully canceled reminder: %s", parts[2])) p.Bot.Send(bot.Message, channel, fmt.Sprintf("successfully canceled reminder: %s", parts[2]))
} else { } else {
p.Bot.SendMessage(channel, fmt.Sprintf("failed to find and cancel reminder: %s", parts[2])) p.Bot.Send(bot.Message, channel, fmt.Sprintf("failed to find and cancel reminder: %s", parts[2]))
} }
} }
return true return true
@ -193,7 +193,7 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
} }
func (p *ReminderPlugin) Help(channel string, parts []string) { func (p *ReminderPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Pester someone with a reminder. Try \"remind <user> in <duration> message\".\n\nUnsure about duration syntax? Check https://golang.org/pkg/time/#ParseDuration") p.Bot.Send(bot.Message, channel, "Pester someone with a reminder. Try \"remind <user> in <duration> message\".\n\nUnsure about duration syntax? Check https://golang.org/pkg/time/#ParseDuration")
} }
func (p *ReminderPlugin) Event(kind string, message msg.Message) bool { func (p *ReminderPlugin) Event(kind string, message msg.Message) bool {
@ -353,7 +353,7 @@ func reminderer(p *ReminderPlugin) {
message = fmt.Sprintf("Hey %s, %s wanted you to be reminded: %s", reminder.who, reminder.from, reminder.what) message = fmt.Sprintf("Hey %s, %s wanted you to be reminded: %s", reminder.who, reminder.from, reminder.what)
} }
p.Bot.SendMessage(reminder.channel, message) p.Bot.Send(bot.Message, reminder.channel, message)
if err := p.deleteReminder(reminder.id); err != nil { if err := p.deleteReminder(reminder.id); err != nil {
log.Print(reminder.id) log.Print(reminder.id)

View File

@ -107,9 +107,9 @@ func New(b bot.Bot) *RPGPlugin {
func (p *RPGPlugin) Message(message msg.Message) bool { func (p *RPGPlugin) Message(message msg.Message) bool {
if strings.ToLower(message.Body) == "start rpg" { if strings.ToLower(message.Body) == "start rpg" {
b := NewRandomBoard() b := NewRandomBoard()
ts := p.Bot.SendMessage(message.Channel, b.toMessageString()) _, ts := p.Bot.Send(bot.Message, message.Channel, b.toMessageString())
p.listenFor[ts] = b p.listenFor[ts] = b
p.Bot.ReplyToMessageIdentifier(message.Channel, "Over here.", ts) p.Bot.Send(bot.Reply, message.Channel, "Over here.", ts)
return true return true
} }
return false return false
@ -120,7 +120,7 @@ func (p *RPGPlugin) LoadData() {
} }
func (p *RPGPlugin) Help(channel string, parts []string) { func (p *RPGPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Go find a walkthrough or something.") p.Bot.Send(bot.Message, channel, "Go find a walkthrough or something.")
} }
func (p *RPGPlugin) Event(kind string, message msg.Message) bool { func (p *RPGPlugin) Event(kind string, message msg.Message) bool {
@ -155,12 +155,12 @@ func (p *RPGPlugin) ReplyMessage(message msg.Message, identifier string) bool {
switch res { switch res {
case OK: case OK:
p.Bot.Edit(message.Channel, b.toMessageString(), identifier) p.Bot.Send(bot.Edit, message.Channel, b.toMessageString(), identifier)
case WIN: case WIN:
p.Bot.Edit(message.Channel, b.toMessageString(), identifier) p.Bot.Send(bot.Edit, message.Channel, b.toMessageString(), identifier)
p.Bot.ReplyToMessageIdentifier(message.Channel, "congratulations, you beat the easiest level imaginable.", identifier) p.Bot.Send(bot.Reply, message.Channel, "congratulations, you beat the easiest level imaginable.", identifier)
case INVALID: case INVALID:
p.Bot.ReplyToMessageIdentifier(message.Channel, fmt.Sprintf("you can't move %s", message.Body), identifier) p.Bot.Send(bot.Reply, message.Channel, fmt.Sprintf("you can't move %s", message.Body), identifier)
} }
return true return true
} }

View File

@ -64,13 +64,13 @@ func (p *RSSPlugin) Message(message msg.Message) bool {
if numTokens == 2 && strings.ToLower(tokens[0]) == "rss" { if numTokens == 2 && strings.ToLower(tokens[0]) == "rss" {
if item, ok := p.cache[strings.ToLower(tokens[1])]; ok && time.Now().Before(item.expiration) { if item, ok := p.cache[strings.ToLower(tokens[1])]; ok && time.Now().Before(item.expiration) {
p.Bot.SendMessage(message.Channel, item.getCurrentPage(p.maxLines)) p.Bot.Send(bot.Message, message.Channel, item.getCurrentPage(p.maxLines))
return true return true
} else { } else {
fp := gofeed.NewParser() fp := gofeed.NewParser()
feed, err := fp.ParseURL(tokens[1]) feed, err := fp.ParseURL(tokens[1])
if err != nil { if err != nil {
p.Bot.SendMessage(message.Channel, fmt.Sprintf("RSS error: %s", err.Error())) p.Bot.Send(bot.Message, message.Channel, fmt.Sprintf("RSS error: %s", err.Error()))
return true return true
} }
item := &cacheItem{ item := &cacheItem{
@ -86,7 +86,7 @@ func (p *RSSPlugin) Message(message msg.Message) bool {
p.cache[strings.ToLower(tokens[1])] = item p.cache[strings.ToLower(tokens[1])] = item
p.Bot.SendMessage(message.Channel, item.getCurrentPage(p.maxLines)) p.Bot.Send(bot.Message, message.Channel, item.getCurrentPage(p.maxLines))
return true return true
} }
} }
@ -100,7 +100,7 @@ func (p *RSSPlugin) LoadData() {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *RSSPlugin) Help(channel string, parts []string) { func (p *RSSPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "try '!rss http://rss.cnn.com/rss/edition.rss'") p.Bot.Send(bot.Message, channel, "try '!rss http://rss.cnn.com/rss/edition.rss'")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -37,17 +37,17 @@ type game struct {
nextAns int nextAns int
} }
func NewRandomGame(bot bot.Bot, channel, who string) *game { func NewRandomGame(b bot.Bot, channel, who string) *game {
size := rand.Intn(9) + 2 size := rand.Intn(9) + 2
g := game{ g := game{
channel: channel, channel: channel,
bot: bot, bot: b,
who: who, who: who,
start: time.Now(), start: time.Now(),
size: size, size: size,
current: size / 2, current: size / 2,
} }
g.id = bot.SendMessage(channel, g.toMessageString()) _, g.id = b.Send(bot.Message, channel, g.toMessageString())
g.schedulePush() g.schedulePush()
g.scheduleDecrement() g.scheduleDecrement()
@ -98,11 +98,11 @@ func (g *game) endGame() {
func (g *game) handleDecrement() { func (g *game) handleDecrement() {
g.current++ g.current++
g.bot.Edit(g.channel, g.toMessageString(), g.id) g.bot.Send(bot.Edit, g.channel, g.toMessageString(), g.id)
if g.current > g.size-2 { if g.current > g.size-2 {
g.bot.ReplyToMessageIdentifier(g.channel, "you lose", g.id) g.bot.Send(bot.Reply, g.channel, "you lose", g.id)
msg := fmt.Sprintf("%s just lost the game after %s", g.who, time.Now().Sub(g.start)) msg := fmt.Sprintf("%s just lost the game after %s", g.who, time.Now().Sub(g.start))
g.bot.SendMessage(g.channel, msg) g.bot.Send(bot.Message, g.channel, msg)
g.endGame() g.endGame()
} else { } else {
g.scheduleDecrement() g.scheduleDecrement()
@ -110,7 +110,7 @@ func (g *game) handleDecrement() {
} }
func (g *game) handleNotify() { func (g *game) handleNotify() {
g.bot.ReplyToMessageIdentifier(g.channel, "You can push now.\n"+g.generateQuestion(), g.id) g.bot.Send(bot.Reply, g.channel, "You can push now.\n"+g.generateQuestion(), g.id)
} }
func (g *game) generateQuestion() string { func (g *game) generateQuestion() string {
@ -172,14 +172,14 @@ func (p *SisyphusPlugin) Message(message msg.Message) bool {
if strings.ToLower(message.Body) == "start sisyphus" { if strings.ToLower(message.Body) == "start sisyphus" {
b := NewRandomGame(p.Bot, message.Channel, message.User.Name) b := NewRandomGame(p.Bot, message.Channel, message.User.Name)
p.listenFor[b.id] = b p.listenFor[b.id] = b
p.Bot.ReplyToMessageIdentifier(message.Channel, "Over here.", b.id) p.Bot.Send(bot.Reply, message.Channel, "Over here.", b.id)
return true return true
} }
return false return false
} }
func (p *SisyphusPlugin) Help(channel string, parts []string) { func (p *SisyphusPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "https://en.wikipedia.org/wiki/Sisyphus") p.Bot.Send(bot.Message, channel, "https://en.wikipedia.org/wiki/Sisyphus")
} }
func (p *SisyphusPlugin) Event(kind string, message msg.Message) bool { func (p *SisyphusPlugin) Event(kind string, message msg.Message) bool {
@ -211,18 +211,18 @@ func (p *SisyphusPlugin) ReplyMessage(message msg.Message, identifier string) bo
if time.Now().After(g.nextPush) { if time.Now().After(g.nextPush) {
if g.checkAnswer(message.Body) { if g.checkAnswer(message.Body) {
p.Bot.Edit(message.Channel, g.toMessageString(), identifier) p.Bot.Send(bot.Edit, message.Channel, g.toMessageString(), identifier)
g.schedulePush() g.schedulePush()
msg := fmt.Sprintf("Ok. You can push again in %s", g.nextPush.Sub(time.Now())) msg := fmt.Sprintf("Ok. You can push again in %s", g.nextPush.Sub(time.Now()))
p.Bot.ReplyToMessageIdentifier(message.Channel, msg, identifier) p.Bot.Send(bot.Reply, message.Channel, msg, identifier)
} else { } else {
p.Bot.ReplyToMessageIdentifier(message.Channel, "you lose", identifier) p.Bot.Send(bot.Reply, message.Channel, "you lose", identifier)
msg := fmt.Sprintf("%s just lost the sisyphus game after %s", g.who, time.Now().Sub(g.start)) msg := fmt.Sprintf("%s just lost the sisyphus game after %s", g.who, time.Now().Sub(g.start))
p.Bot.SendMessage(message.Channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
g.endGame() g.endGame()
} }
} else { } else {
p.Bot.ReplyToMessageIdentifier(message.Channel, "you cannot push yet", identifier) p.Bot.Send(bot.Reply, message.Channel, "you cannot push yet", identifier)
} }
return true return true
} }

View File

@ -57,7 +57,7 @@ func (p *TalkerPlugin) Message(message msg.Message) bool {
// TODO: This ought to be space split afterwards to remove any punctuation // TODO: This ought to be space split afterwards to remove any punctuation
if message.Command && strings.HasPrefix(lowermessage, "say") { if message.Command && strings.HasPrefix(lowermessage, "say") {
msg := strings.TrimSpace(body[3:]) msg := strings.TrimSpace(body[3:])
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
return true return true
} }
@ -73,7 +73,7 @@ func (p *TalkerPlugin) Message(message msg.Message) bool {
line = strings.Replace(line, "{nick}", nick, 1) line = strings.Replace(line, "{nick}", nick, 1)
output += line + "\n" output += line + "\n"
} }
p.Bot.SendMessage(channel, output) p.Bot.Send(bot.Message, channel, output)
return true return true
} }
@ -81,7 +81,7 @@ func (p *TalkerPlugin) Message(message msg.Message) bool {
} }
func (p *TalkerPlugin) Help(channel string, parts []string) { func (p *TalkerPlugin) Help(channel string, parts []string) {
p.Bot.SendMessage(channel, "Hi, this is talker. I like to talk about FredFelps!") p.Bot.Send(bot.Message, channel, "Hi, this is talker. I like to talk about FredFelps!")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -26,13 +26,13 @@ func (t *TellPlugin) Message(message msg.Message) bool {
newMessage := strings.Join(parts[2:], " ") newMessage := strings.Join(parts[2:], " ")
newMessage = fmt.Sprintf("Hey, %s. %s said: %s", target, message.User.Name, newMessage) newMessage = fmt.Sprintf("Hey, %s. %s said: %s", target, message.User.Name, newMessage)
t.users[target] = append(t.users[target], newMessage) t.users[target] = append(t.users[target], newMessage)
t.b.SendMessage(message.Channel, fmt.Sprintf("Okay. I'll tell %s.", target)) t.b.Send(bot.Message, message.Channel, fmt.Sprintf("Okay. I'll tell %s.", target))
return true return true
} }
uname := strings.ToLower(message.User.Name) uname := strings.ToLower(message.User.Name)
if msg, ok := t.users[uname]; ok && len(msg) > 0 { if msg, ok := t.users[uname]; ok && len(msg) > 0 {
for _, m := range msg { for _, m := range msg {
t.b.SendMessage(message.Channel, string(m)) t.b.Send(bot.Message, message.Channel, string(m))
} }
t.users[uname] = []string{} t.users[uname] = []string{}
return true return true

View File

@ -140,7 +140,7 @@ func (p *TwitchPlugin) LoadData() {
func (p *TwitchPlugin) Help(channel string, parts []string) { func (p *TwitchPlugin) Help(channel string, parts []string) {
msg := "There's no help for you here." msg := "There's no help for you here."
p.Bot.SendMessage(channel, msg) p.Bot.Send(bot.Message, channel, msg)
} }
func (p *TwitchPlugin) twitchLoop(channel string) { func (p *TwitchPlugin) twitchLoop(channel string) {
@ -223,18 +223,18 @@ func (p *TwitchPlugin) checkTwitch(channel string, twitcher *Twitcher, alwaysPri
} }
if alwaysPrintStatus { if alwaysPrintStatus {
if game == "" { if game == "" {
p.Bot.SendMessage(channel, twitcher.name+" is not streaming.") p.Bot.Send(bot.Message, channel, twitcher.name+" is not streaming.")
} else { } else {
p.Bot.SendMessage(channel, twitcher.name+" is streaming "+game+" at "+twitcher.URL()) p.Bot.Send(bot.Message, channel, twitcher.name+" is streaming "+game+" at "+twitcher.URL())
} }
} else if game == "" { } else if game == "" {
if twitcher.game != "" { if twitcher.game != "" {
p.Bot.SendMessage(channel, twitcher.name+" just stopped streaming.") p.Bot.Send(bot.Message, channel, twitcher.name+" just stopped streaming.")
} }
twitcher.game = "" twitcher.game = ""
} else { } else {
if twitcher.game != game { if twitcher.game != game {
p.Bot.SendMessage(channel, twitcher.name+" just started streaming "+game+" at "+twitcher.URL()) p.Bot.Send(bot.Message, channel, twitcher.name+" just started streaming "+game+" at "+twitcher.URL())
} }
twitcher.game = game twitcher.game = game
} }

View File

@ -43,7 +43,7 @@ func (p *YourPlugin) Message(message msg.Message) bool {
} }
} }
if msg != message.Body { if msg != message.Body {
p.bot.SendMessage(message.Channel, msg) p.bot.Send(bot.Message, message.Channel, msg)
return true return true
} }
return false return false
@ -51,7 +51,7 @@ func (p *YourPlugin) Message(message msg.Message) bool {
// Help responds to help requests. Every plugin must implement a help function. // Help responds to help requests. Every plugin must implement a help function.
func (p *YourPlugin) Help(channel string, parts []string) { func (p *YourPlugin) Help(channel string, parts []string) {
p.bot.SendMessage(channel, "Your corrects people's grammar.") p.bot.Send(bot.Message, channel, "Your corrects people's grammar.")
} }
// Empty event handler because this plugin does not do anything on event recv // Empty event handler because this plugin does not do anything on event recv

View File

@ -26,7 +26,7 @@ type ZorkPlugin struct {
zorks map[string]io.WriteCloser zorks map[string]io.WriteCloser
} }
func New(b bot.Bot) bot.Handler { func New(b bot.Bot) bot.Plugin {
return &ZorkPlugin{ return &ZorkPlugin{
bot: b, bot: b,
zorks: make(map[string]io.WriteCloser), zorks: make(map[string]io.WriteCloser),
@ -75,7 +75,7 @@ func (p *ZorkPlugin) runZork(ch string) error {
m := strings.Replace(s.Text(), ">", "", -1) m := strings.Replace(s.Text(), ">", "", -1)
m = strings.Replace(m, "\n", "\n>", -1) m = strings.Replace(m, "\n", "\n>", -1)
m = ">" + m + "\n" m = ">" + m + "\n"
p.bot.SendMessage(ch, m) p.bot.Send(bot.Message, ch, m)
} }
}() }()
go func() { go func() {
@ -104,7 +104,7 @@ func (p *ZorkPlugin) Message(message msg.Message) bool {
defer p.Unlock() defer p.Unlock()
if p.zorks[ch] == nil { if p.zorks[ch] == nil {
if err := p.runZork(ch); err != nil { if err := p.runZork(ch); err != nil {
p.bot.SendMessage(ch, "failed to run zork: "+err.Error()) p.bot.Send(bot.Message, ch, "failed to run zork: "+err.Error())
return true return true
} }
} }
@ -118,7 +118,7 @@ func (p *ZorkPlugin) Event(_ string, _ msg.Message) bool { return false }
func (p *ZorkPlugin) BotMessage(_ msg.Message) bool { return false } func (p *ZorkPlugin) BotMessage(_ msg.Message) bool { return false }
func (p *ZorkPlugin) Help(ch string, _ []string) { func (p *ZorkPlugin) Help(ch string, _ []string) {
p.bot.SendMessage(ch, "Play zork using 'zork <zork command>'.") p.bot.Send(bot.Message, ch, "Play zork using 'zork <zork command>'.")
} }
func (p *ZorkPlugin) RegisterWeb() *string { return nil } func (p *ZorkPlugin) RegisterWeb() *string { return nil }