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"
|
2021-05-04 17:57:57 +00:00
|
|
|
"io"
|
2018-07-23 17:00:19 +00:00
|
|
|
"math/rand"
|
2019-03-07 16:35:42 +00:00
|
|
|
"os"
|
2018-07-23 17:00:19 +00:00
|
|
|
"time"
|
2014-04-20 16:54:01 +00:00
|
|
|
|
2021-02-14 21:57:22 +00:00
|
|
|
"github.com/velour/catbase/bot/msg"
|
2020-08-31 16:20:52 +00:00
|
|
|
"github.com/velour/catbase/connectors/discord"
|
2021-11-30 15:28:34 +00:00
|
|
|
"github.com/velour/catbase/plugins/gifmeme"
|
2021-03-01 04:13:27 +00:00
|
|
|
"github.com/velour/catbase/plugins/giphy"
|
2021-11-19 16:24:20 +00:00
|
|
|
"github.com/velour/catbase/plugins/gpt3"
|
2021-04-27 16:36:34 +00:00
|
|
|
"github.com/velour/catbase/plugins/last"
|
2021-10-14 01:11:35 +00:00
|
|
|
"github.com/velour/catbase/plugins/mayi"
|
2021-08-05 14:47:34 +00:00
|
|
|
"github.com/velour/catbase/plugins/quotegame"
|
2021-05-19 15:46:23 +00:00
|
|
|
"github.com/velour/catbase/plugins/rest"
|
2021-11-20 20:28:53 +00:00
|
|
|
"github.com/velour/catbase/plugins/roles"
|
2021-05-20 13:59:28 +00:00
|
|
|
"github.com/velour/catbase/plugins/secrets"
|
2020-08-20 21:20:35 +00:00
|
|
|
|
2020-04-20 09:56:49 +00:00
|
|
|
"github.com/velour/catbase/plugins/achievements"
|
2019-12-01 04:57:00 +00:00
|
|
|
"github.com/velour/catbase/plugins/aoc"
|
2020-11-30 19:55:35 +00:00
|
|
|
"github.com/velour/catbase/plugins/countdown"
|
2020-05-26 15:38:55 +00:00
|
|
|
"github.com/velour/catbase/plugins/goals"
|
2020-04-28 15:32:52 +00:00
|
|
|
"github.com/velour/catbase/plugins/meme"
|
2020-05-14 20:48:41 +00:00
|
|
|
"github.com/velour/catbase/plugins/sms"
|
2019-10-21 00:55:13 +00:00
|
|
|
"github.com/velour/catbase/plugins/twitter"
|
|
|
|
|
2019-03-07 16:35:42 +00:00
|
|
|
"github.com/rs/zerolog"
|
|
|
|
"github.com/rs/zerolog/log"
|
|
|
|
|
2016-01-17 18:00:44 +00:00
|
|
|
"github.com/velour/catbase/bot"
|
|
|
|
"github.com/velour/catbase/config"
|
2019-02-06 03:52:49 +00:00
|
|
|
"github.com/velour/catbase/connectors/irc"
|
|
|
|
"github.com/velour/catbase/connectors/slackapp"
|
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"
|
2019-10-20 13:21:27 +00:00
|
|
|
"github.com/velour/catbase/plugins/cli"
|
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"
|
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"
|
2019-10-26 19:01:29 +00:00
|
|
|
"github.com/velour/catbase/plugins/git"
|
2020-03-13 14:16:32 +00:00
|
|
|
"github.com/velour/catbase/plugins/impossible"
|
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"
|
2019-10-20 13:21:27 +00:00
|
|
|
"github.com/velour/catbase/plugins/newsbid"
|
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"
|
2019-02-15 18:22:54 +00:00
|
|
|
"github.com/velour/catbase/plugins/remember"
|
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"
|
2019-06-07 18:32:20 +00:00
|
|
|
"github.com/velour/catbase/plugins/stock"
|
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"
|
2019-03-22 00:12:15 +00:00
|
|
|
"github.com/velour/catbase/plugins/tldr"
|
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"
|
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 (
|
2019-03-07 16:35:42 +00:00
|
|
|
key = flag.String("set", "", "Configuration key to set")
|
|
|
|
val = flag.String("val", "", "Configuration value to set")
|
2021-07-21 18:52:45 +00:00
|
|
|
initDB = flag.Bool("init", false, "Initialize the configuration db")
|
2019-03-07 16:35:42 +00:00
|
|
|
prettyLog = flag.Bool("pretty", false, "Use pretty console logger")
|
|
|
|
debug = flag.Bool("debug", false, "Turn on debug logging")
|
2019-01-21 19:24:03 +00:00
|
|
|
)
|
|
|
|
|
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.
|
|
|
|
|
2021-05-04 17:57:57 +00:00
|
|
|
var output io.Writer = os.Stdout
|
2019-03-07 16:35:42 +00:00
|
|
|
if *prettyLog {
|
2021-05-04 17:57:57 +00:00
|
|
|
output = zerolog.ConsoleWriter{Out: output}
|
2019-03-07 16:35:42 +00:00
|
|
|
}
|
2021-05-04 17:57:57 +00:00
|
|
|
log.Logger = log.Output(output).With().Caller().Stack().Logger()
|
|
|
|
|
2019-03-07 16:35:42 +00:00
|
|
|
zerolog.SetGlobalLevel(zerolog.InfoLevel)
|
|
|
|
if *debug {
|
|
|
|
zerolog.SetGlobalLevel(zerolog.DebugLevel)
|
|
|
|
}
|
|
|
|
|
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)
|
2019-03-07 16:35:42 +00:00
|
|
|
log.Info().Msgf("Set config %s: %s", *key, *val)
|
2019-01-21 19:24:03 +00:00
|
|
|
return
|
|
|
|
}
|
2019-01-22 00:16:57 +00:00
|
|
|
if (*initDB && len(flag.Args()) != 2) || (!*initDB && c.GetInt("init", 0) != 1) {
|
2019-03-07 16:35:42 +00:00
|
|
|
log.Fatal().Msgf(`You must run "catbase -init <channel> <nick>"`)
|
2019-01-21 19:24:03 +00:00
|
|
|
} 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-02-06 03:52:49 +00:00
|
|
|
switch c.Get("type", "slackapp") {
|
2016-03-10 18:37:07 +00:00
|
|
|
case "irc":
|
|
|
|
client = irc.New(c)
|
2019-02-06 03:52:49 +00:00
|
|
|
case "slackapp":
|
|
|
|
client = slackapp.New(c)
|
2020-08-31 16:20:52 +00:00
|
|
|
case "discord":
|
|
|
|
client = discord.New(c)
|
2016-03-10 18:37:07 +00:00
|
|
|
default:
|
2019-03-07 16:35:42 +00:00
|
|
|
log.Fatal().Msgf("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
|
|
|
|
2021-07-28 15:32:59 +00:00
|
|
|
if r, path := client.GetRouter(); r != nil {
|
|
|
|
b.RegisterWeb(r, path)
|
|
|
|
}
|
|
|
|
|
2019-02-05 21:10:36 +00:00
|
|
|
b.AddPlugin(admin.New(b))
|
2021-11-20 20:28:53 +00:00
|
|
|
b.AddPlugin(roles.New(b))
|
2021-11-20 14:55:11 +00:00
|
|
|
b.AddPlugin(gpt3.New(b))
|
2021-05-20 13:59:28 +00:00
|
|
|
b.AddPlugin(secrets.New(b))
|
2021-10-14 01:11:35 +00:00
|
|
|
b.AddPlugin(mayi.New(b))
|
2021-03-01 04:13:27 +00:00
|
|
|
b.AddPlugin(giphy.New(b))
|
2019-02-05 21:10:36 +00:00
|
|
|
b.AddPlugin(emojifyme.New(b))
|
2021-04-27 16:36:34 +00:00
|
|
|
b.AddPlugin(last.New(b))
|
2019-02-05 21:10:36 +00:00
|
|
|
b.AddPlugin(first.New(b))
|
|
|
|
b.AddPlugin(leftpad.New(b))
|
|
|
|
b.AddPlugin(talker.New(b))
|
|
|
|
b.AddPlugin(dice.New(b))
|
|
|
|
b.AddPlugin(picker.New(b))
|
|
|
|
b.AddPlugin(beers.New(b))
|
2019-02-15 18:22:54 +00:00
|
|
|
b.AddPlugin(remember.New(b))
|
2019-02-05 21:10:36 +00:00
|
|
|
b.AddPlugin(your.New(b))
|
|
|
|
b.AddPlugin(counter.New(b))
|
2020-05-25 18:05:21 +00:00
|
|
|
b.AddPlugin(goals.New(b))
|
2019-02-05 21:10:36 +00:00
|
|
|
b.AddPlugin(reminder.New(b))
|
|
|
|
b.AddPlugin(babbler.New(b))
|
|
|
|
b.AddPlugin(rss.New(b))
|
|
|
|
b.AddPlugin(reaction.New(b))
|
|
|
|
b.AddPlugin(twitch.New(b))
|
|
|
|
b.AddPlugin(inventory.New(b))
|
|
|
|
b.AddPlugin(rpgORdie.New(b))
|
|
|
|
b.AddPlugin(sisyphus.New(b))
|
|
|
|
b.AddPlugin(tell.New(b))
|
|
|
|
b.AddPlugin(couldashouldawoulda.New(b))
|
|
|
|
b.AddPlugin(nerdepedia.New(b))
|
2019-03-22 00:12:15 +00:00
|
|
|
b.AddPlugin(tldr.New(b))
|
2019-06-07 18:32:20 +00:00
|
|
|
b.AddPlugin(stock.New(b))
|
2019-07-15 20:55:35 +00:00
|
|
|
b.AddPlugin(newsbid.New(b))
|
2019-10-21 00:55:13 +00:00
|
|
|
b.AddPlugin(twitter.New(b))
|
2019-10-26 19:01:29 +00:00
|
|
|
b.AddPlugin(git.New(b))
|
2020-03-13 14:16:32 +00:00
|
|
|
b.AddPlugin(impossible.New(b))
|
2019-05-27 23:21:53 +00:00
|
|
|
b.AddPlugin(cli.New(b))
|
2019-12-01 04:57:00 +00:00
|
|
|
b.AddPlugin(aoc.New(b))
|
2021-11-30 15:28:34 +00:00
|
|
|
b.AddPlugin(gifmeme.New(b))
|
2020-04-28 15:32:52 +00:00
|
|
|
b.AddPlugin(meme.New(b))
|
2020-04-20 09:56:49 +00:00
|
|
|
b.AddPlugin(achievements.New(b))
|
2020-05-14 20:48:41 +00:00
|
|
|
b.AddPlugin(sms.New(b))
|
2020-11-30 19:55:35 +00:00
|
|
|
b.AddPlugin(countdown.New(b))
|
2021-05-19 15:46:23 +00:00
|
|
|
b.AddPlugin(rest.New(b))
|
2021-08-05 14:47:34 +00:00
|
|
|
b.AddPlugin(quotegame.New(b))
|
2013-06-02 01:59:55 +00:00
|
|
|
// catches anything left, will always return true
|
2019-02-05 21:10:36 +00:00
|
|
|
b.AddPlugin(fact.New(b))
|
2013-01-23 00:22:32 +00:00
|
|
|
|
2019-02-07 19:45:59 +00:00
|
|
|
if err := client.Serve(); err != nil {
|
2019-03-07 16:35:42 +00:00
|
|
|
log.Fatal().Err(err)
|
2017-09-07 04:32:53 +00:00
|
|
|
}
|
2019-02-07 19:45:59 +00:00
|
|
|
|
2021-02-14 21:57:22 +00:00
|
|
|
b.Receive(client, bot.Startup, msg.Message{})
|
|
|
|
|
2021-07-21 18:52:45 +00:00
|
|
|
b.ListenAndServe()
|
2012-08-17 20:38:15 +00:00
|
|
|
}
|