From 59b42b155614ada26cd0d384f3da55b7ecd2686d Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Fri, 17 Aug 2012 19:22:37 -0400 Subject: [PATCH] Added a skeleton plugin (and beers based on that) and improved the help function a bit. --- bot/handlers.go | 4 ++-- main.go | 4 +++- plugins/beers.go | 36 ++++++++++++++++++++++++++++++++++++ plugins/skeleton.go | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 plugins/beers.go create mode 100644 plugins/skeleton.go diff --git a/bot/handlers.go b/bot/handlers.go index c010685..b76fd27 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -48,9 +48,9 @@ func (b *Bot) Msg_recieved(conn *irc.Conn, line *irc.Line) { if len(parts) > 0 && parts[0] == "help" { if len(parts) == 1 { // just print out a list of help topics - topics := "Help topics: About" + topics := "Help topics: about" for name, _ := range b.Plugins { - topics = fmt.Sprintf("%s, %s ", topics, name) + topics = fmt.Sprintf("%s, %s", topics, name) } b.SendMessage(channel, topics) } else { diff --git a/main.go b/main.go index dec5e34..be576b5 100644 --- a/main.go +++ b/main.go @@ -43,7 +43,9 @@ func main() { b := bot.NewBot(config, c) // b.AddHandler(plugins.NewTestPlugin(b)) - b.AddHandler("Talker", plugins.NewTalkerPlugin(b)) + b.AddHandler("talker", plugins.NewTalkerPlugin(b)) + b.AddHandler("beers", plugins.NewBeersPlugin(b)) + b.AddHandler("skeleton", plugins.NewSkeletonPlugin(b)) c.AddHandler("PRIVMSG", func(conn *irc.Conn, line *irc.Line) { b.Msg_recieved(conn, line) diff --git a/plugins/beers.go b/plugins/beers.go new file mode 100644 index 0000000..aee3017 --- /dev/null +++ b/plugins/beers.go @@ -0,0 +1,36 @@ +package plugins + +import "bitbucket.org/phlyingpenguin/godeepintir/bot" + +// This is a skeleton plugin to serve as an example and quick copy/paste for new plugins. + +type BeersPlugin struct { + Bot *bot.Bot +} + +// NewBeersPlugin creates a new BeersPlugin with the Plugin interface +func NewBeersPlugin(bot *bot.Bot) *BeersPlugin { + return &BeersPlugin{ + Bot: bot, + } +} + +// 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. +// Otherwise, the function returns false and the bot continues execution of other plugins. +func (p *BeersPlugin) Message(message bot.Message) bool { + // This bot does not reply to anything + return false +} + +// LoadData imports any configuration data into the plugin. This is not strictly necessary other +// than the fact that the Plugin interface demands it exist. This may be deprecated at a later +// date. +func (p *BeersPlugin) LoadData() { + // This bot has no data to load +} + +// Help responds to help requests. Every plugin must implement a help function. +func (p *BeersPlugin) Help(channel string, parts []string) { + p.Bot.SendMessage(channel, "Sorry, Beers does not do a goddamn thing.") +} diff --git a/plugins/skeleton.go b/plugins/skeleton.go new file mode 100644 index 0000000..bac69e1 --- /dev/null +++ b/plugins/skeleton.go @@ -0,0 +1,36 @@ +package plugins + +import "bitbucket.org/phlyingpenguin/godeepintir/bot" + +// This is a skeleton plugin to serve as an example and quick copy/paste for new plugins. + +type SkeletonPlugin struct { + Bot *bot.Bot +} + +// NewSkeletonPlugin creates a new SkeletonPlugin with the Plugin interface +func NewSkeletonPlugin(bot *bot.Bot) *SkeletonPlugin { + return &SkeletonPlugin{ + Bot: bot, + } +} + +// 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. +// Otherwise, the function returns false and the bot continues execution of other plugins. +func (p *SkeletonPlugin) Message(message bot.Message) bool { + // This bot does not reply to anything + return false +} + +// LoadData imports any configuration data into the plugin. This is not strictly necessary other +// than the fact that the Plugin interface demands it exist. This may be deprecated at a later +// date. +func (p *SkeletonPlugin) LoadData() { + // This bot has no data to load +} + +// Help responds to help requests. Every plugin must implement a help function. +func (p *SkeletonPlugin) Help(channel string, parts []string) { + p.Bot.SendMessage(channel, "Sorry, Skeleton does not do a goddamn thing.") +}