Added a skeleton plugin (and beers based on that) and improved the help function

a bit.
This commit is contained in:
Chris Sexton 2012-08-17 19:22:37 -04:00
parent ad2e0f13e2
commit 59b42b1556
4 changed files with 77 additions and 3 deletions

View File

@ -48,7 +48,7 @@ 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)
}

View File

@ -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)

36
plugins/beers.go Normal file
View File

@ -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.")
}

36
plugins/skeleton.go Normal file
View File

@ -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.")
}