plugins: add callback handler registrations

This commit is contained in:
Chris Sexton 2019-02-05 14:41:38 -05:00
parent 933e514ddd
commit 90e7b11308
22 changed files with 205 additions and 385 deletions

View File

@ -38,8 +38,8 @@ type untappdUser struct {
} }
// New BeersPlugin creates a new BeersPlugin with the Plugin interface // New BeersPlugin creates a new BeersPlugin with the Plugin interface
func New(bot bot.Bot) *BeersPlugin { func New(b bot.Bot) *BeersPlugin {
if _, err := bot.DB().Exec(`create table if not exists untappd ( if _, err := b.DB().Exec(`create table if not exists untappd (
id integer primary key, id integer primary key,
untappdUser string, untappdUser string,
channel string, channel string,
@ -49,19 +49,21 @@ func New(bot bot.Bot) *BeersPlugin {
log.Fatal(err) log.Fatal(err)
} }
p := BeersPlugin{ p := BeersPlugin{
Bot: bot, Bot: b,
db: bot.DB(), db: b.DB(),
} }
for _, channel := range bot.Config().GetArray("Untappd.Channels", []string{}) { for _, channel := range b.Config().GetArray("Untappd.Channels", []string{}) {
go p.untappdLoop(channel) go p.untappdLoop(channel)
} }
b.Register(p, bot.Message, p.message)
b.Register(p, bot.Help, p.help)
return &p return &p
} }
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *BeersPlugin) Message(message msg.Message) bool { func (p *BeersPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
parts := strings.Fields(message.Body) parts := strings.Fields(message.Body)
if len(parts) == 0 { if len(parts) == 0 {
@ -190,17 +192,13 @@ func (p *BeersPlugin) Message(message msg.Message) bool {
return false return false
} }
// Empty event handler because this plugin does not do anything on event recv
func (p *BeersPlugin) Event(kind string, message msg.Message) bool {
return false
}
// 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 *BeersPlugin) Help(channel string, parts []string) { func (p *BeersPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
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.Send(bot.Message, channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
return true
} }
func getUserBeers(db *sqlx.DB, user string) counter.Item { func getUserBeers(db *sqlx.DB, user string) counter.Item {
@ -439,14 +437,7 @@ func (p *BeersPlugin) untappdLoop(channel string) {
} }
} }
// Handler for bot's own messages
func (p *BeersPlugin) BotMessage(message msg.Message) bool {
return false
}
// Register any web URLs desired // Register any web URLs desired
func (p *BeersPlugin) RegisterWeb() *string { func (p BeersPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *BeersPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -17,13 +17,15 @@ type CSWPlugin struct {
Config *config.Config Config *config.Config
} }
func New(bot bot.Bot) *CSWPlugin { func New(b bot.Bot) *CSWPlugin {
return &CSWPlugin{ csw := &CSWPlugin{
Bot: bot, Bot: b,
} }
b.Register(csw, bot.Message, csw.message)
return csw
} }
func (p *CSWPlugin) Message(message msg.Message) bool { func (p *CSWPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if !message.Command { if !message.Command {
return false return false
} }
@ -70,18 +72,6 @@ func (p *CSWPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *CSWPlugin) Help(channel string, parts []string) {}
func (p *CSWPlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *CSWPlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *CSWPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
func (p *CSWPlugin) RegisterWeb() *string { func (p *CSWPlugin) RegisterWeb() *string {
return nil return nil
} }

View File

@ -172,31 +172,34 @@ func (i *Item) Delete() error {
} }
// NewCounterPlugin creates a new CounterPlugin with the Plugin interface // NewCounterPlugin creates a new CounterPlugin with the Plugin interface
func New(bot bot.Bot) *CounterPlugin { func New(b bot.Bot) *CounterPlugin {
tx := bot.DB().MustBegin() tx := b.DB().MustBegin()
bot.DB().MustExec(`create table if not exists counter ( b.DB().MustExec(`create table if not exists counter (
id integer primary key, id integer primary key,
nick string, nick string,
item string, item string,
count integer count integer
);`) );`)
bot.DB().MustExec(`create table if not exists counter_alias ( b.DB().MustExec(`create table if not exists counter_alias (
id integer PRIMARY KEY AUTOINCREMENT, id integer PRIMARY KEY AUTOINCREMENT,
item string NOT NULL UNIQUE, item string NOT NULL UNIQUE,
points_to string NOT NULL points_to string NOT NULL
);`) );`)
tx.Commit() tx.Commit()
return &CounterPlugin{ cp := &CounterPlugin{
Bot: bot, Bot: b,
DB: bot.DB(), DB: b.DB(),
} }
b.Register(cp, bot.Message, cp.message)
b.Register(cp, bot.Help, cp.help)
return cp
} }
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the // This function returns true if the plugin responds in a meaningful way to the
// users message. Otherwise, the function returns false and the bot continues // users message. Otherwise, the function returns false and the bot continues
// execution of other plugins. // execution of other plugins.
func (p *CounterPlugin) Message(message msg.Message) bool { func (p *CounterPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
// This bot does not reply to anything // This bot does not reply to anything
nick := message.User.Name nick := message.User.Name
channel := message.Channel channel := message.Channel
@ -444,21 +447,12 @@ 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(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "You can set counters incrementally by using "+ p.Bot.Send(bot.Message, 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\".")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *CounterPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *CounterPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
@ -466,8 +460,6 @@ func (p *CounterPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *CounterPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
func (p *CounterPlugin) checkMatch(message msg.Message) bool { func (p *CounterPlugin) checkMatch(message msg.Message) bool {
nick := message.User.Name nick := message.User.Name
channel := message.Channel channel := message.Channel

View File

@ -19,10 +19,13 @@ type DicePlugin struct {
} }
// NewDicePlugin creates a new DicePlugin with the Plugin interface // NewDicePlugin creates a new DicePlugin with the Plugin interface
func New(bot bot.Bot) *DicePlugin { func New(b bot.Bot) *DicePlugin {
return &DicePlugin{ dp := &DicePlugin{
Bot: bot, Bot: b,
} }
b.Register(dp, bot.Message, dp.message)
b.Register(dp, bot.Help, dp.help)
return dp
} }
func rollDie(sides int) int { func rollDie(sides int) int {
@ -32,7 +35,7 @@ func rollDie(sides int) int {
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *DicePlugin) Message(message msg.Message) bool { func (p *DicePlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if !message.Command { if !message.Command {
return false return false
} }
@ -67,23 +70,12 @@ func (p *DicePlugin) 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 *DicePlugin) Help(channel string, parts []string) { func (p *DicePlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "Roll dice using notation XdY. Try \"3d20\".") p.Bot.Send(bot.Message, message.Channel, "Roll dice using notation XdY. Try \"3d20\".")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *DicePlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *DicePlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
func (p *DicePlugin) RegisterWeb() *string { func (p *DicePlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *DicePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -20,7 +20,7 @@ type EmojifyMePlugin struct {
Emoji map[string]string Emoji map[string]string
} }
func New(bot bot.Bot) *EmojifyMePlugin { func New(b bot.Bot) *EmojifyMePlugin {
resp, err := http.Get("https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json") resp, err := http.Get("https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json")
if err != nil { if err != nil {
log.Fatalf("Error generic emoji list: %s", err) log.Fatalf("Error generic emoji list: %s", err)
@ -48,14 +48,16 @@ func New(bot bot.Bot) *EmojifyMePlugin {
} }
} }
return &EmojifyMePlugin{ ep := &EmojifyMePlugin{
Bot: bot, Bot: b,
GotBotEmoji: false, GotBotEmoji: false,
Emoji: emojiMap, Emoji: emojiMap,
} }
b.Register(ep, bot.Message, ep.message)
return ep
} }
func (p *EmojifyMePlugin) Message(message msg.Message) bool { func (p *EmojifyMePlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if !p.GotBotEmoji { if !p.GotBotEmoji {
p.GotBotEmoji = true p.GotBotEmoji = true
emojiMap := p.Bot.GetEmojiList() emojiMap := p.Bot.GetEmojiList()
@ -97,24 +99,10 @@ func (p *EmojifyMePlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *EmojifyMePlugin) Help(channel string, parts []string) {
}
func (p *EmojifyMePlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *EmojifyMePlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *EmojifyMePlugin) RegisterWeb() *string { func (p *EmojifyMePlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *EmojifyMePlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }
func stringsContain(haystack []string, needle string) bool { func stringsContain(haystack []string, needle string) bool {
for _, s := range haystack { for _, s := range haystack {
if s == needle { if s == needle {

View File

@ -314,6 +314,9 @@ func New(botInst bot.Bot) *Factoid {
}(channel) }(channel)
} }
botInst.Register(p, bot.Message, p.message)
botInst.Register(p, bot.Help, p.help)
return p return p
} }
@ -609,7 +612,7 @@ func (p *Factoid) changeFact(message msg.Message) bool {
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *Factoid) Message(message msg.Message) bool { func (p *Factoid) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if strings.ToLower(message.Body) == "what was that?" { if strings.ToLower(message.Body) == "what was that?" {
return p.tellThemWhatThatWas(message) return p.tellThemWhatThatWas(message)
} }
@ -669,14 +672,10 @@ func (p *Factoid) 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 *Factoid) Help(channel string, parts []string) { func (p *Factoid) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
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.Send(bot.Message, 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.Send(bot.Message, channel, "I can also figure out some variables including: $nonzero, $digit, $nick, and $someone.") p.Bot.Send(bot.Message, message.Channel, "I can also figure out some variables including: $nonzero, $digit, $nick, and $someone.")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *Factoid) Event(kind string, message msg.Message) bool {
return false
} }
// Pull a fact at random from the database // Pull a fact at random from the database
@ -737,11 +736,6 @@ func (p *Factoid) factTimer(channel string) {
} }
} }
// Handler for bot's own messages
func (p *Factoid) BotMessage(message msg.Message) bool {
return false
}
// Register any web URLs desired // Register any web URLs desired
func (p *Factoid) RegisterWeb() *string { func (p *Factoid) RegisterWeb() *string {
http.HandleFunc("/factoid/req", p.serveQuery) http.HandleFunc("/factoid/req", p.serveQuery)
@ -784,5 +778,3 @@ func (p *Factoid) serveQuery(w http.ResponseWriter, r *http.Request) {
log.Println(err) log.Println(err)
} }
} }
func (p *Factoid) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -29,6 +29,8 @@ func NewRemember(b bot.Bot) *RememberPlugin {
Log: make(map[string][]msg.Message), Log: make(map[string][]msg.Message),
db: b.DB(), db: b.DB(),
} }
b.Register(p, bot.Message, p.message)
b.Register(p, bot.Message, p.help)
return &p return &p
} }
@ -36,7 +38,7 @@ func NewRemember(b bot.Bot) *RememberPlugin {
// This function returns true if the plugin responds in a meaningful way to the // This function returns true if the plugin responds in a meaningful way to the
// users message. Otherwise, the function returns false and the bot continues // users message. Otherwise, the function returns false and the bot continues
// execution of other plugins. // execution of other plugins.
func (p *RememberPlugin) Message(message msg.Message) bool { func (p *RememberPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if strings.ToLower(message.Body) == "quote" && message.Command { if strings.ToLower(message.Body) == "quote" && message.Command {
q := p.randQuote() q := p.randQuote()
@ -111,14 +113,15 @@ func (p *RememberPlugin) 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 *RememberPlugin) Help(channel string, parts []string) { func (p *RememberPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
msg := "!remember will let you quote your idiot friends. Just type " + msg := "!remember will let you quote your idiot friends. Just type " +
"!remember <nick> <snippet> to remember what they said. Snippet can " + "!remember <nick> <snippet> to remember what they said. Snippet can " +
"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.Send(bot.Message, channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
return true
} }
// deliver a random quote out of the db. // deliver a random quote out of the db.
@ -150,19 +153,8 @@ func (p *RememberPlugin) randQuote() string {
return f.Tidbit return f.Tidbit
} }
// Empty event handler because this plugin does not do anything on event recv
func (p *RememberPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Record what the bot says in the log
func (p *RememberPlugin) BotMessage(message msg.Message) bool {
p.recordMsg(message)
return false
}
// Register any web URLs desired // Register any web URLs desired
func (p *RememberPlugin) RegisterWeb() *string { func (p RememberPlugin) RegisterWeb() *string {
return nil return nil
} }
@ -170,5 +162,3 @@ func (p *RememberPlugin) recordMsg(message msg.Message) {
log.Printf("Logging message: %s: %s", message.User.Name, message.Body) log.Printf("Logging message: %s: %s", message.User.Name, message.Body)
p.Log[message.Channel] = append(p.Log[message.Channel], message) p.Log[message.Channel] = append(p.Log[message.Channel], message)
} }
func (p *RememberPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -66,11 +66,14 @@ func New(b bot.Bot) *FirstPlugin {
log.Fatal("Could not initialize first plugin: ", err) log.Fatal("Could not initialize first plugin: ", err)
} }
return &FirstPlugin{ fp := &FirstPlugin{
Bot: b, Bot: b,
db: b.DB(), db: b.DB(),
First: first, First: first,
} }
b.Register(fp, bot.Message, fp.message)
b.Register(fp, bot.Help, fp.help)
return fp
} }
func getLastFirst(db *sqlx.DB) (*FirstEntry, error) { func getLastFirst(db *sqlx.DB) (*FirstEntry, error) {
@ -123,7 +126,7 @@ func isToday(t time.Time) bool {
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *FirstPlugin) Message(message msg.Message) bool { func (p *FirstPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
// This bot does not reply to anything // This bot does not reply to anything
if p.First == nil && p.allowed(message) { if p.First == nil && p.allowed(message) {
@ -208,23 +211,12 @@ 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(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "Sorry, First does not do a goddamn thing.") p.Bot.Send(bot.Message, message.Channel, "Sorry, First does not do a goddamn thing.")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *FirstPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *FirstPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
func (p *FirstPlugin) RegisterWeb() *string { func (p *FirstPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *FirstPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -24,8 +24,8 @@ type InventoryPlugin struct {
} }
// New creates a new InventoryPlugin with the Plugin interface // New creates a new InventoryPlugin with the Plugin interface
func New(bot bot.Bot) *InventoryPlugin { func New(b bot.Bot) *InventoryPlugin {
config := bot.Config() config := b.Config()
nick := config.Get("nick", "bot") nick := config.Get("nick", "bot")
r1, err := regexp.Compile("take this (.+)") r1, err := regexp.Compile("take this (.+)")
checkerr(err) checkerr(err)
@ -38,15 +38,15 @@ func New(bot bot.Bot) *InventoryPlugin {
r5, err := regexp.Compile(fmt.Sprintf("gives (.+) to %s([^a-zA-Z].*)?", nick)) r5, err := regexp.Compile(fmt.Sprintf("gives (.+) to %s([^a-zA-Z].*)?", nick))
checkerr(err) checkerr(err)
p := InventoryPlugin{ p := &InventoryPlugin{
DB: bot.DB(), DB: b.DB(),
bot: bot, bot: b,
config: config, config: config,
r1: r1, r2: r2, r3: r3, r4: r4, r5: r5, r1: r1, r2: r2, r3: r3, r4: r4, r5: r5,
} }
bot.RegisterFilter("$item", p.itemFilter) b.RegisterFilter("$item", p.itemFilter)
bot.RegisterFilter("$giveitem", p.giveItemFilter) b.RegisterFilter("$giveitem", p.giveItemFilter)
_, err = p.DB.Exec(`create table if not exists inventory ( _, err = p.DB.Exec(`create table if not exists inventory (
item string primary key item string primary key
@ -56,7 +56,9 @@ func New(bot bot.Bot) *InventoryPlugin {
log.Fatal(err) log.Fatal(err)
} }
return &p b.Register(p, bot.Message, p.message)
return p
} }
func (p *InventoryPlugin) giveItemFilter(input string) string { func (p *InventoryPlugin) giveItemFilter(input string) string {
@ -75,7 +77,7 @@ func (p *InventoryPlugin) itemFilter(input string) string {
return input return input
} }
func (p *InventoryPlugin) Message(message msg.Message) bool { func (p *InventoryPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
m := message.Body m := message.Body
log.Printf("inventory trying to read %+v", message) log.Printf("inventory trying to read %+v", message)
if message.Command { if message.Command {
@ -223,20 +225,7 @@ func checkerr(e error) {
} }
} }
func (p *InventoryPlugin) Event(e string, message msg.Message) bool {
return false
}
func (p *InventoryPlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *InventoryPlugin) Help(e string, m []string) {
}
func (p *InventoryPlugin) RegisterWeb() *string { func (p *InventoryPlugin) RegisterWeb() *string {
// nothing to register // nothing to register
return nil return nil
} }
func (p *InventoryPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -20,19 +20,20 @@ type LeftpadPlugin struct {
} }
// New creates a new LeftpadPlugin with the Plugin interface // New creates a new LeftpadPlugin with the Plugin interface
func New(bot bot.Bot) *LeftpadPlugin { func New(b bot.Bot) *LeftpadPlugin {
p := LeftpadPlugin{ p := &LeftpadPlugin{
bot: bot, bot: b,
config: bot.Config(), config: b.Config(),
} }
return &p b.Register(p, bot.Message, p.message)
return p
} }
type leftpadResp struct { type leftpadResp struct {
Str string Str string
} }
func (p *LeftpadPlugin) Message(message msg.Message) bool { func (p *LeftpadPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if !message.Command { if !message.Command {
return false return false
} }
@ -62,20 +63,7 @@ func (p *LeftpadPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *LeftpadPlugin) Event(e string, message msg.Message) bool {
return false
}
func (p *LeftpadPlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *LeftpadPlugin) Help(e string, m []string) {
}
func (p *LeftpadPlugin) RegisterWeb() *string { func (p *LeftpadPlugin) RegisterWeb() *string {
// nothing to register // nothing to register
return nil return nil
} }
func (p *LeftpadPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -27,17 +27,20 @@ type NerdepediaPlugin struct {
} }
// NewNerdepediaPlugin creates a new NerdepediaPlugin with the Plugin interface // NewNerdepediaPlugin creates a new NerdepediaPlugin with the Plugin interface
func New(bot bot.Bot) *NerdepediaPlugin { func New(b bot.Bot) *NerdepediaPlugin {
return &NerdepediaPlugin{ np := &NerdepediaPlugin{
bot: bot, bot: b,
config: bot.Config(), config: b.Config(),
} }
b.Register(np, bot.Message, np.message)
b.Register(np, bot.Help, np.help)
return np
} }
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *NerdepediaPlugin) Message(message msg.Message) bool { func (p *NerdepediaPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
lowerCase := strings.ToLower(message.Body) lowerCase := strings.ToLower(message.Body)
query := "" query := ""
if lowerCase == "may the force be with you" || lowerCase == "help me obi-wan" { if lowerCase == "may the force be with you" || lowerCase == "help me obi-wan" {
@ -87,23 +90,12 @@ 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(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.bot.Send(bot.Message, channel, "nerd stuff") p.bot.Send(bot.Message, message.Channel, "nerd stuff")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *NerdepediaPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *NerdepediaPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
func (p *NerdepediaPlugin) RegisterWeb() *string { func (p *NerdepediaPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *NerdepediaPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -20,16 +20,19 @@ type PickerPlugin struct {
} }
// NewPickerPlugin creates a new PickerPlugin with the Plugin interface // NewPickerPlugin creates a new PickerPlugin with the Plugin interface
func New(bot bot.Bot) *PickerPlugin { func New(b bot.Bot) *PickerPlugin {
return &PickerPlugin{ pp := &PickerPlugin{
Bot: bot, Bot: b,
} }
b.Register(pp, bot.Message, pp.message)
b.Register(pp, bot.Help, pp.help)
return pp
} }
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *PickerPlugin) Message(message msg.Message) bool { func (p *PickerPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if !strings.HasPrefix(message.Body, "pick") { if !strings.HasPrefix(message.Body, "pick") {
return false return false
} }
@ -108,18 +111,9 @@ 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(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "Choose from a list of options. Try \"pick {a,b,c}\".") p.Bot.Send(bot.Message, message.Channel, "Choose from a list of options. Try \"pick {a,b,c}\".")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *PickerPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *PickerPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired

View File

@ -15,14 +15,16 @@ type ReactionPlugin struct {
Config *config.Config Config *config.Config
} }
func New(bot bot.Bot) *ReactionPlugin { func New(b bot.Bot) *ReactionPlugin {
return &ReactionPlugin{ rp := &ReactionPlugin{
Bot: bot, Bot: b,
Config: bot.Config(), Config: b.Config(),
} }
b.Register(rp, bot.Message, rp.message)
return rp
} }
func (p *ReactionPlugin) Message(message msg.Message) bool { func (p *ReactionPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
harrass := false harrass := false
for _, nick := range p.Config.GetArray("Reaction.HarrassList", []string{}) { for _, nick := range p.Config.GetArray("Reaction.HarrassList", []string{}) {
if message.User.Name == nick { if message.User.Name == nick {
@ -62,20 +64,6 @@ func (p *ReactionPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *ReactionPlugin) Help(channel string, parts []string) {
}
func (p *ReactionPlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *ReactionPlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *ReactionPlugin) RegisterWeb() *string { func (p *ReactionPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *ReactionPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -38,9 +38,9 @@ type Reminder struct {
channel string channel string
} }
func New(bot bot.Bot) *ReminderPlugin { func New(b bot.Bot) *ReminderPlugin {
log.SetFlags(log.LstdFlags | log.Lshortfile) log.SetFlags(log.LstdFlags | log.Lshortfile)
if _, err := bot.DB().Exec(`create table if not exists reminders ( if _, err := b.DB().Exec(`create table if not exists reminders (
id integer primary key, id integer primary key,
fromWho string, fromWho string,
toWho string, toWho string,
@ -56,21 +56,24 @@ func New(bot bot.Bot) *ReminderPlugin {
timer.Stop() timer.Stop()
plugin := &ReminderPlugin{ plugin := &ReminderPlugin{
Bot: bot, Bot: b,
db: bot.DB(), db: b.DB(),
mutex: &sync.Mutex{}, mutex: &sync.Mutex{},
timer: timer, timer: timer,
config: bot.Config(), config: b.Config(),
} }
plugin.queueUpNextReminder() plugin.queueUpNextReminder()
go reminderer(plugin) go reminderer(plugin)
b.Register(plugin, bot.Message, plugin.message)
b.Register(plugin, bot.Help, plugin.help)
return plugin return plugin
} }
func (p *ReminderPlugin) Message(message msg.Message) bool { func (p *ReminderPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
channel := message.Channel channel := message.Channel
from := message.User.Name from := message.User.Name
@ -192,16 +195,9 @@ func (p *ReminderPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *ReminderPlugin) Help(channel string, parts []string) { func (p *ReminderPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
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") p.Bot.Send(bot.Message, 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")
} return true
func (p *ReminderPlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *ReminderPlugin) BotMessage(message msg.Message) bool {
return false
} }
func (p *ReminderPlugin) RegisterWeb() *string { func (p *ReminderPlugin) RegisterWeb() *string {
@ -365,5 +361,3 @@ func reminderer(p *ReminderPlugin) {
p.queueUpNextReminder() p.queueUpNextReminder()
} }
} }
func (p *ReminderPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -98,13 +98,17 @@ func (b *board) checkAndMove(dx, dy int) int {
} }
func New(b bot.Bot) *RPGPlugin { func New(b bot.Bot) *RPGPlugin {
return &RPGPlugin{ rpg := &RPGPlugin{
Bot: b, Bot: b,
listenFor: map[string]*board{}, listenFor: map[string]*board{},
} }
b.Register(rpg, bot.Message, rpg.message)
b.Register(rpg, bot.Reply, rpg.replyMessage)
b.Register(rpg, bot.Help, rpg.help)
return rpg
} }
func (p *RPGPlugin) Message(message msg.Message) bool { func (p *RPGPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if strings.ToLower(message.Body) == "start rpg" { if strings.ToLower(message.Body) == "start rpg" {
b := NewRandomBoard() b := NewRandomBoard()
ts, _ := p.Bot.Send(bot.Message, message.Channel, b.toMessageString()) ts, _ := p.Bot.Send(bot.Message, message.Channel, b.toMessageString())
@ -115,27 +119,17 @@ func (p *RPGPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *RPGPlugin) LoadData() { func (p *RPGPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, message.Channel, "Go find a walkthrough or something.")
} return true
func (p *RPGPlugin) Help(channel string, parts []string) {
p.Bot.Send(bot.Message, channel, "Go find a walkthrough or something.")
}
func (p *RPGPlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *RPGPlugin) BotMessage(message msg.Message) bool {
return false
} }
func (p *RPGPlugin) RegisterWeb() *string { func (p *RPGPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *RPGPlugin) ReplyMessage(message msg.Message, identifier string) bool { func (p *RPGPlugin) replyMessage(kind bot.Kind, message msg.Message, args ...interface{}) bool {
identifier := args[0].(string)
if strings.ToLower(message.User.Name) != strings.ToLower(p.Bot.Config().Get("Nick", "bot")) { if strings.ToLower(message.User.Name) != strings.ToLower(p.Bot.Config().Get("Nick", "bot")) {
if b, ok := p.listenFor[identifier]; ok { if b, ok := p.listenFor[identifier]; ok {

View File

@ -49,16 +49,19 @@ func (c *cacheItem) getCurrentPage(maxLines int) string {
return page return page
} }
func New(bot bot.Bot) *RSSPlugin { func New(b bot.Bot) *RSSPlugin {
return &RSSPlugin{ rss := &RSSPlugin{
Bot: bot, Bot: b,
cache: map[string]*cacheItem{}, cache: map[string]*cacheItem{},
shelfLife: time.Minute * 20, shelfLife: time.Minute * time.Duration(b.Config().GetInt("rss.shelfLife", 20)),
maxLines: 5, maxLines: b.Config().GetInt("rss.maxLines", 5),
} }
b.Register(rss, bot.Message, rss.message)
b.Register(rss, bot.Help, rss.help)
return rss
} }
func (p *RSSPlugin) Message(message msg.Message) bool { func (p *RSSPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
tokens := strings.Fields(message.Body) tokens := strings.Fields(message.Body)
numTokens := len(tokens) numTokens := len(tokens)
@ -94,28 +97,13 @@ func (p *RSSPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *RSSPlugin) LoadData() {
// This bot has no data to load
}
// 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(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "try '!rss http://rss.cnn.com/rss/edition.rss'") p.Bot.Send(bot.Message, message.Channel, "try '!rss http://rss.cnn.com/rss/edition.rss'")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *RSSPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *RSSPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
func (p *RSSPlugin) RegisterWeb() *string { func (p *RSSPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *RSSPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -162,13 +162,17 @@ func (g *game) toMessageString() string {
} }
func New(b bot.Bot) *SisyphusPlugin { func New(b bot.Bot) *SisyphusPlugin {
return &SisyphusPlugin{ sp := &SisyphusPlugin{
Bot: b, Bot: b,
listenFor: map[string]*game{}, listenFor: map[string]*game{},
} }
b.Register(sp, bot.Message, sp.message)
b.Register(sp, bot.Reply, sp.replyMessage)
b.Register(sp, bot.Help, sp.help)
return sp
} }
func (p *SisyphusPlugin) Message(message msg.Message) bool { func (p *SisyphusPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) 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
@ -178,23 +182,17 @@ func (p *SisyphusPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *SisyphusPlugin) Help(channel string, parts []string) { func (p *SisyphusPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "https://en.wikipedia.org/wiki/Sisyphus") p.Bot.Send(bot.Message, message.Channel, "https://en.wikipedia.org/wiki/Sisyphus")
} return true
func (p *SisyphusPlugin) Event(kind string, message msg.Message) bool {
return false
}
func (p *SisyphusPlugin) BotMessage(message msg.Message) bool {
return false
} }
func (p *SisyphusPlugin) RegisterWeb() *string { func (p *SisyphusPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *SisyphusPlugin) ReplyMessage(message msg.Message, identifier string) bool { func (p *SisyphusPlugin) replyMessage(kind bot.Kind, message msg.Message, args ...interface{}) bool {
identifier := args[0].(string)
if strings.ToLower(message.User.Name) != strings.ToLower(p.Bot.Config().Get("Nick", "bot")) { if strings.ToLower(message.User.Name) != strings.ToLower(p.Bot.Config().Get("Nick", "bot")) {
if g, ok := p.listenFor[identifier]; ok { if g, ok := p.listenFor[identifier]; ok {

View File

@ -43,13 +43,16 @@ type TalkerPlugin struct {
sayings []string sayings []string
} }
func New(bot bot.Bot) *TalkerPlugin { func New(b bot.Bot) *TalkerPlugin {
return &TalkerPlugin{ tp := &TalkerPlugin{
Bot: bot, Bot: b,
} }
b.Register(tp, bot.Message, tp.message)
b.Register(tp, bot.Help, tp.help)
return tp
} }
func (p *TalkerPlugin) Message(message msg.Message) bool { func (p *TalkerPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
channel := message.Channel channel := message.Channel
body := message.Body body := message.Body
lowermessage := strings.ToLower(body) lowermessage := strings.ToLower(body)
@ -80,23 +83,12 @@ func (p *TalkerPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *TalkerPlugin) Help(channel string, parts []string) { func (p *TalkerPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.Bot.Send(bot.Message, channel, "Hi, this is talker. I like to talk about FredFelps!") p.Bot.Send(bot.Message, message.Channel, "Hi, this is talker. I like to talk about FredFelps!")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *TalkerPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *TalkerPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
func (p *TalkerPlugin) RegisterWeb() *string { func (p *TalkerPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *TalkerPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -16,10 +16,12 @@ type TellPlugin struct {
} }
func New(b bot.Bot) *TellPlugin { func New(b bot.Bot) *TellPlugin {
return &TellPlugin{b, make(map[string][]string)} tp := &TellPlugin{b, make(map[string][]string)}
b.Register(tp, bot.Message, tp.message)
return tp
} }
func (t *TellPlugin) Message(message msg.Message) bool { func (t *TellPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if strings.HasPrefix(strings.ToLower(message.Body), "tell") { if strings.HasPrefix(strings.ToLower(message.Body), "tell") {
parts := strings.Split(message.Body, " ") parts := strings.Split(message.Body, " ")
target := strings.ToLower(parts[1]) target := strings.ToLower(parts[1])
@ -40,8 +42,4 @@ func (t *TellPlugin) Message(message msg.Message) bool {
return false return false
} }
func (t *TellPlugin) Event(kind string, message msg.Message) bool { return false } func (t *TellPlugin) RegisterWeb() *string { return nil }
func (t *TellPlugin) ReplyMessage(msg.Message, string) bool { return false }
func (t *TellPlugin) BotMessage(message msg.Message) bool { return false }
func (t *TellPlugin) Help(channel string, parts []string) {}
func (t *TellPlugin) RegisterWeb() *string { return nil }

View File

@ -51,10 +51,10 @@ type stream struct {
} `json:"pagination"` } `json:"pagination"`
} }
func New(bot bot.Bot) *TwitchPlugin { func New(b bot.Bot) *TwitchPlugin {
p := &TwitchPlugin{ p := &TwitchPlugin{
Bot: bot, Bot: b,
config: bot.Config(), config: b.Config(),
twitchList: map[string]*Twitcher{}, twitchList: map[string]*Twitcher{},
} }
@ -70,13 +70,10 @@ func New(bot bot.Bot) *TwitchPlugin {
go p.twitchLoop(ch) go p.twitchLoop(ch)
} }
b.Register(p, bot.Message, p.message)
return p return p
} }
func (p *TwitchPlugin) BotMessage(message msg.Message) bool {
return false
}
func (p *TwitchPlugin) RegisterWeb() *string { func (p *TwitchPlugin) RegisterWeb() *string {
http.HandleFunc("/isstreaming/", p.serveStreaming) http.HandleFunc("/isstreaming/", p.serveStreaming)
tmp := "/isstreaming" tmp := "/isstreaming"
@ -114,7 +111,7 @@ func (p *TwitchPlugin) serveStreaming(w http.ResponseWriter, r *http.Request) {
} }
} }
func (p *TwitchPlugin) Message(message msg.Message) bool { func (p *TwitchPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
if strings.ToLower(message.Body) == "twitch status" { if strings.ToLower(message.Body) == "twitch status" {
channel := message.Channel channel := message.Channel
if users := p.config.GetArray("Twitch."+channel+".Users", []string{}); len(users) > 0 { if users := p.config.GetArray("Twitch."+channel+".Users", []string{}); len(users) > 0 {
@ -130,17 +127,10 @@ func (p *TwitchPlugin) Message(message msg.Message) bool {
return false return false
} }
func (p *TwitchPlugin) Event(kind string, message msg.Message) bool { func (p *TwitchPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
return false
}
func (p *TwitchPlugin) LoadData() {
}
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.Send(bot.Message, channel, msg) p.Bot.Send(bot.Message, message.Channel, msg)
return true
} }
func (p *TwitchPlugin) twitchLoop(channel string) { func (p *TwitchPlugin) twitchLoop(channel string) {
@ -240,5 +230,3 @@ func (p *TwitchPlugin) checkTwitch(channel string, twitcher *Twitcher, alwaysPri
twitcher.game = game twitcher.game = game
} }
} }
func (p *TwitchPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -17,17 +17,20 @@ type YourPlugin struct {
} }
// NewYourPlugin creates a new YourPlugin with the Plugin interface // NewYourPlugin creates a new YourPlugin with the Plugin interface
func New(bot bot.Bot) *YourPlugin { func New(b bot.Bot) *YourPlugin {
return &YourPlugin{ yp := &YourPlugin{
bot: bot, bot: b,
config: bot.Config(), config: b.Config(),
} }
b.Register(yp, bot.Message, yp.message)
b.Register(yp, bot.Help, yp.help)
return yp
} }
// Message responds to the bot hook on recieving messages. // Message responds to the bot hook on recieving messages.
// This function returns true if the plugin responds in a meaningful way to the users message. // This function returns true if the plugin responds in a meaningful way to the users message.
// Otherwise, the function returns false and the bot continues execution of other plugins. // Otherwise, the function returns false and the bot continues execution of other plugins.
func (p *YourPlugin) Message(message msg.Message) bool { func (p *YourPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
maxLen := p.config.GetInt("your.maxlength", 140) maxLen := p.config.GetInt("your.maxlength", 140)
if len(message.Body) > maxLen { if len(message.Body) > maxLen {
return false return false
@ -50,23 +53,12 @@ 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(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.bot.Send(bot.Message, channel, "Your corrects people's grammar.") p.bot.Send(bot.Message, message.Channel, "Your corrects people's grammar.")
} return true
// Empty event handler because this plugin does not do anything on event recv
func (p *YourPlugin) Event(kind string, message msg.Message) bool {
return false
}
// Handler for bot's own messages
func (p *YourPlugin) BotMessage(message msg.Message) bool {
return false
} }
// Register any web URLs desired // Register any web URLs desired
func (p *YourPlugin) RegisterWeb() *string { func (p *YourPlugin) RegisterWeb() *string {
return nil return nil
} }
func (p *YourPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }

View File

@ -27,10 +27,13 @@ type ZorkPlugin struct {
} }
func New(b bot.Bot) bot.Plugin { func New(b bot.Bot) bot.Plugin {
return &ZorkPlugin{ z := &ZorkPlugin{
bot: b, bot: b,
zorks: make(map[string]io.WriteCloser), zorks: make(map[string]io.WriteCloser),
} }
b.Register(z, bot.Message, z.message)
b.Register(z, bot.Help, z.help)
return z
} }
func (p *ZorkPlugin) runZork(ch string) error { func (p *ZorkPlugin) runZork(ch string) error {
@ -91,7 +94,7 @@ func (p *ZorkPlugin) runZork(ch string) error {
return nil return nil
} }
func (p *ZorkPlugin) Message(message msg.Message) bool { func (p *ZorkPlugin) message(kind bot.Kind, message msg.Message, args ...interface{}) bool {
m := strings.ToLower(message.Body) m := strings.ToLower(message.Body)
log.Printf("got message [%s]\n", m) log.Printf("got message [%s]\n", m)
if ts := strings.Fields(m); len(ts) < 1 || ts[0] != "zork" { if ts := strings.Fields(m); len(ts) < 1 || ts[0] != "zork" {
@ -113,14 +116,9 @@ func (p *ZorkPlugin) Message(message msg.Message) bool {
return true return true
} }
func (p *ZorkPlugin) Event(_ string, _ msg.Message) bool { return false } func (p *ZorkPlugin) help(kind bot.Kind, message msg.Message, args ...interface{}) bool {
p.bot.Send(bot.Message, message.Channel, "Play zork using 'zork <zork command>'.")
func (p *ZorkPlugin) BotMessage(_ msg.Message) bool { return false } return true
func (p *ZorkPlugin) Help(ch string, _ []string) {
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 }
func (p *ZorkPlugin) ReplyMessage(message msg.Message, identifier string) bool { return false }