2016-01-17 18:00:44 +00:00
|
|
|
// © 2013 the CatBase Authors under the WTFPL. See AUTHORS for the list of authors.
|
2013-12-10 23:37:07 +00:00
|
|
|
|
2012-08-17 20:38:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2013-05-09 22:30:15 +00:00
|
|
|
"flag"
|
2013-06-02 01:59:55 +00:00
|
|
|
"log"
|
2018-07-23 17:00:19 +00:00
|
|
|
"math/rand"
|
|
|
|
"time"
|
2014-04-20 16:54:01 +00:00
|
|
|
|
2016-01-17 18:00:44 +00:00
|
|
|
"github.com/velour/catbase/bot"
|
|
|
|
"github.com/velour/catbase/config"
|
2016-03-10 18:37:07 +00:00
|
|
|
"github.com/velour/catbase/irc"
|
2016-03-24 17:32:40 +00:00
|
|
|
"github.com/velour/catbase/plugins/admin"
|
2016-05-15 18:13:34 +00:00
|
|
|
"github.com/velour/catbase/plugins/babbler"
|
2016-03-24 17:32:40 +00:00
|
|
|
"github.com/velour/catbase/plugins/beers"
|
2018-06-22 18:25:43 +00:00
|
|
|
"github.com/velour/catbase/plugins/couldashouldawoulda"
|
2016-04-04 14:33:32 +00:00
|
|
|
"github.com/velour/catbase/plugins/counter"
|
2018-02-22 22:41:48 +00:00
|
|
|
"github.com/velour/catbase/plugins/db"
|
2016-03-24 17:32:40 +00:00
|
|
|
"github.com/velour/catbase/plugins/dice"
|
2017-07-24 19:09:27 +00:00
|
|
|
"github.com/velour/catbase/plugins/emojifyme"
|
2016-03-24 17:32:40 +00:00
|
|
|
"github.com/velour/catbase/plugins/fact"
|
2017-08-18 09:59:46 +00:00
|
|
|
"github.com/velour/catbase/plugins/first"
|
2017-09-29 04:58:21 +00:00
|
|
|
"github.com/velour/catbase/plugins/inventory"
|
2016-03-25 16:25:00 +00:00
|
|
|
"github.com/velour/catbase/plugins/leftpad"
|
2019-01-19 00:48:12 +00:00
|
|
|
"github.com/velour/catbase/plugins/nerdepedia"
|
2017-12-19 18:37:47 +00:00
|
|
|
"github.com/velour/catbase/plugins/picker"
|
2017-06-17 20:20:06 +00:00
|
|
|
"github.com/velour/catbase/plugins/reaction"
|
2016-05-09 17:09:17 +00:00
|
|
|
"github.com/velour/catbase/plugins/reminder"
|
2017-10-31 10:22:36 +00:00
|
|
|
"github.com/velour/catbase/plugins/rpgORdie"
|
2017-05-10 19:15:24 +00:00
|
|
|
"github.com/velour/catbase/plugins/rss"
|
2017-11-03 18:01:49 +00:00
|
|
|
"github.com/velour/catbase/plugins/sisyphus"
|
2016-03-24 17:32:40 +00:00
|
|
|
"github.com/velour/catbase/plugins/talker"
|
2017-11-16 22:06:48 +00:00
|
|
|
"github.com/velour/catbase/plugins/tell"
|
2017-09-27 18:39:36 +00:00
|
|
|
"github.com/velour/catbase/plugins/twitch"
|
2016-03-24 17:32:40 +00:00
|
|
|
"github.com/velour/catbase/plugins/your"
|
2016-05-15 18:13:34 +00:00
|
|
|
"github.com/velour/catbase/plugins/zork"
|
2016-03-11 02:11:52 +00:00
|
|
|
"github.com/velour/catbase/slack"
|
2013-06-02 01:59:55 +00:00
|
|
|
)
|
2012-08-17 20:38:15 +00:00
|
|
|
|
2019-01-21 19:24:03 +00:00
|
|
|
var (
|
|
|
|
key = flag.String("set", "", "Configuration key to set")
|
|
|
|
val = flag.String("val", "", "Configuration value to set")
|
|
|
|
initDB = flag.Bool("init", false, "Initialize the configuration DB")
|
|
|
|
)
|
|
|
|
|
2013-06-02 01:59:55 +00:00
|
|
|
func main() {
|
2018-07-23 17:00:19 +00:00
|
|
|
rand.Seed(time.Now().Unix())
|
|
|
|
|
2019-01-20 20:21:26 +00:00
|
|
|
var dbpath = flag.String("db", "catbase.db",
|
|
|
|
"Database file to load. (Defaults to catbase.db)")
|
2012-08-17 20:38:15 +00:00
|
|
|
flag.Parse() // parses the logging flags.
|
|
|
|
|
2019-01-20 20:21:26 +00:00
|
|
|
c := config.ReadConfig(*dbpath)
|
2019-01-21 19:24:03 +00:00
|
|
|
|
|
|
|
if *key != "" && *val != "" {
|
|
|
|
c.Set(*key, *val)
|
|
|
|
log.Printf("Set config %s: %s", *key, *val)
|
|
|
|
return
|
|
|
|
}
|
2019-01-22 00:16:57 +00:00
|
|
|
if (*initDB && len(flag.Args()) != 2) || (!*initDB && c.GetInt("init", 0) != 1) {
|
2019-01-21 19:24:03 +00:00
|
|
|
log.Fatal(`You must run "catbase -init <channel> <nick>"`)
|
|
|
|
} else if *initDB {
|
|
|
|
c.SetDefaults(flag.Arg(0), flag.Arg(1))
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2016-03-10 18:37:07 +00:00
|
|
|
var client bot.Connector
|
2013-06-02 01:59:55 +00:00
|
|
|
|
2019-01-22 00:16:57 +00:00
|
|
|
switch c.Get("type", "slack") {
|
2016-03-10 18:37:07 +00:00
|
|
|
case "irc":
|
|
|
|
client = irc.New(c)
|
2016-03-11 02:11:52 +00:00
|
|
|
case "slack":
|
|
|
|
client = slack.New(c)
|
2016-03-10 18:37:07 +00:00
|
|
|
default:
|
2019-01-22 00:16:57 +00:00
|
|
|
log.Fatalf("Unknown connection type: %s", c.Get("type", "UNSET"))
|
2013-06-02 01:59:55 +00:00
|
|
|
}
|
|
|
|
|
2016-03-30 14:00:20 +00:00
|
|
|
b := bot.New(c, client)
|
2016-03-10 18:37:07 +00:00
|
|
|
|
2019-02-05 15:54:13 +00:00
|
|
|
b.AddPlugin("admin", admin.New(b))
|
|
|
|
b.AddPlugin("first", first.New(b))
|
|
|
|
b.AddPlugin("leftpad", leftpad.New(b))
|
|
|
|
b.AddPlugin("talker", talker.New(b))
|
|
|
|
b.AddPlugin("dice", dice.New(b))
|
|
|
|
b.AddPlugin("picker", picker.New(b))
|
|
|
|
b.AddPlugin("beers", beers.New(b))
|
|
|
|
b.AddPlugin("remember", fact.NewRemember(b))
|
|
|
|
b.AddPlugin("your", your.New(b))
|
|
|
|
b.AddPlugin("counter", counter.New(b))
|
|
|
|
b.AddPlugin("reminder", reminder.New(b))
|
|
|
|
b.AddPlugin("babbler", babbler.New(b))
|
|
|
|
b.AddPlugin("zork", zork.New(b))
|
|
|
|
b.AddPlugin("rss", rss.New(b))
|
|
|
|
b.AddPlugin("reaction", reaction.New(b))
|
|
|
|
b.AddPlugin("emojifyme", emojifyme.New(b))
|
|
|
|
b.AddPlugin("twitch", twitch.New(b))
|
|
|
|
b.AddPlugin("inventory", inventory.New(b))
|
|
|
|
b.AddPlugin("rpgORdie", rpgORdie.New(b))
|
|
|
|
b.AddPlugin("sisyphus", sisyphus.New(b))
|
|
|
|
b.AddPlugin("tell", tell.New(b))
|
|
|
|
b.AddPlugin("couldashouldawoulda", couldashouldawoulda.New(b))
|
|
|
|
b.AddPlugin("nedepedia", nerdepedia.New(b))
|
2013-06-02 01:59:55 +00:00
|
|
|
// catches anything left, will always return true
|
2019-02-05 15:54:13 +00:00
|
|
|
b.AddPlugin("factoid", fact.New(b))
|
|
|
|
b.AddPlugin("db", db.New(b))
|
2013-01-23 00:22:32 +00:00
|
|
|
|
2017-09-07 04:32:53 +00:00
|
|
|
for {
|
|
|
|
err := client.Serve()
|
|
|
|
log.Println(err)
|
|
|
|
}
|
2012-08-17 20:38:15 +00:00
|
|
|
}
|