From ac8bc9a145b54b82630452569d39169d92a94a80 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Sun, 26 Aug 2012 20:30:23 -0400 Subject: [PATCH] Added helptext to list variables --- bot/handlers.go | 19 ++++++++++++++++++- plugins/admin.go | 1 + 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/bot/handlers.go b/bot/handlers.go index 2c03b29..7ffb850 100644 --- a/bot/handlers.go +++ b/bot/handlers.go @@ -52,7 +52,7 @@ func (b *Bot) checkuser(nick string) *User { func (b *Bot) checkHelp(channel string, parts []string) { if len(parts) == 1 { // just print out a list of help topics - topics := "Help topics: about" + topics := "Help topics: about variables" for name, _ := range b.Plugins { topics = fmt.Sprintf("%s, %s", topics, name) } @@ -63,6 +63,10 @@ func (b *Bot) checkHelp(channel string, parts []string) { b.Help(channel, parts) return } + if parts[1] == "variables" { + b.listVars(channel, parts) + return + } plugin := b.Plugins[parts[1]] if plugin != nil { plugin.Help(channel, parts) @@ -206,6 +210,19 @@ func (b *Bot) Filter(message Message, input string) string { return input } +func (b *Bot) listVars(channel string, parts []string) { + var result []string + err := b.varColl.Find(bson.M{}).Distinct("variable", &result) + if err != nil { + panic(err) + } + msg := "I know: $who, $someone, $digit, $nonzero" + for _, variable := range result { + msg = fmt.Sprintf("%s, %s", msg, variable) + } + b.SendMessage(channel, msg) +} + func (b *Bot) Help(channel string, parts []string) { msg := fmt.Sprintf("Hi, I'm based on godeepintir version %s. I'm written in Go, and you "+ "can find my source code on the internet here: "+ diff --git a/plugins/admin.go b/plugins/admin.go index a23d903..ea4f941 100644 --- a/plugins/admin.go +++ b/plugins/admin.go @@ -31,6 +31,7 @@ func NewAdminPlugin(bot *bot.Bot) *AdminPlugin { // Otherwise, the function returns false and the bot continues execution of other plugins. func (p *AdminPlugin) Message(message bot.Message) bool { // This bot does not reply to anything + if !message.User.Admin { return false }