From 43a8bec86b1f8ac9fbf6a0ee7c763941e599fb77 Mon Sep 17 00:00:00 2001 From: Chris Sexton Date: Tue, 27 Aug 2013 21:52:27 -0400 Subject: [PATCH] Spit out a start up message to the chan --- config.json | 2 ++ config/config.go | 1 + plugins/factoid.go | 22 ++++++++++++++++++---- 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/config.json b/config.json index 61477d6..ecfd596 100644 --- a/config.json +++ b/config.json @@ -23,6 +23,8 @@ "TwitterUserKey": "", "TwitterUserSecret": "", + "StartupFact": "speed test", + "WelcomeMsgs": [ "Real men use screen, %s.", "Joins upset the hivemind's OCD, %s.", diff --git a/config/config.go b/config/config.go index 477795d..338016e 100644 --- a/config/config.go +++ b/config/config.go @@ -28,6 +28,7 @@ type Config struct { TwitterConsumerSecret string TwitterUserKey string TwitterUserSecret string + StartupFact string BadMsgs []string Bad struct { Msgs []string diff --git a/plugins/factoid.go b/plugins/factoid.go index 648c2bb..d079184 100644 --- a/plugins/factoid.go +++ b/plugins/factoid.go @@ -41,9 +41,9 @@ type FactoidPlugin struct { } // NewFactoidPlugin creates a new FactoidPlugin with the Plugin interface -func NewFactoidPlugin(bot *bot.Bot) *FactoidPlugin { +func NewFactoidPlugin(botInst *bot.Bot) *FactoidPlugin { p := &FactoidPlugin{ - Bot: bot, + Bot: botInst, Coll: nil, NotFound: []string{ "I don't know.", @@ -55,9 +55,23 @@ func NewFactoidPlugin(bot *bot.Bot) *FactoidPlugin { }, } p.LoadData() - for _, channel := range bot.Config.Channels { + for _, channel := range botInst.Config.Channels { go p.factTimer(channel) + + go func() { + // Some random time to start up + time.Sleep(time.Duration(10) * time.Second) + if ok, fact := p.findTrigger(p.Bot.Config.StartupFact); ok { + p.sayFact(bot.Message{ + Channel: channel, + Body: "speed test", + Command: true, + Action: false, + }, *fact) + } + }() } + return p } @@ -113,7 +127,7 @@ func (p *FactoidPlugin) findTrigger(message string) (bool, *Factoid) { iter := p.Coll.Find(bson.M{"trigger": strings.ToLower(message)}).Iter() err := iter.All(&results) if err != nil { - return false, nil + return false, nil } nfacts := len(results)