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