This project contains the source code for the Brainbox.cc TriviaBot. Written in C++17 using the D++ library.
It was originally FruitLoopy Trivia on irc.chatspike.net and i've been running this bot in some form since 2004.
This source code repository is for reference and learning only as it won't work without a TriviaBot API key, which i'm not prepared to give out to people (no, this isn't "open trivia database"). Without this key, the bot will start, but will be unable to start any games, or retrieve any statistics or update the cache.
Currently only Linux is supported, but other UNIX-style platforms should build and run the bot fine. I build the bot under Debian Linux 10.
- cmake (version 3.13+)
- g++ (version 8+)
- D++ (development branch)
- PCRE (whichever -dev package comes with your OS)
- MySQL Client Libraries (whichever -dev package comes with your OS)
- spdlog
mkdir build
cmake ..
make -j8
Replace the number after -j with a number suitable for your setup, usually the same as the number of cores on your machine.
You should have a database configured with the mysql schemas from the mysql-schemas directory. use mysqlimport to import this. Note that the database schema included only has the bare minimum tables to boot the client bot. There is no question database structure, or API schema included in this dump.
Edit the config-example.json file and save it as config.json. The configuration variables are documented below:
Key Name | Description |
---|---|
devtoken | Discord bot token for a development version of the bot, allowing you to keep development and live copies separate |
livetoken | Discord bot token for live version of the bot (see above) |
shardcount | Number of shards in total, split across clusters |
dbhost | Hostname or IP address of MySQL server where the triviabot client schema is hosted |
dbuser | Username for MySQL server |
dbpass | Password for MySQL server |
dbname | Database name for MySQL database on the server containing the triviabot schema |
dbport | TCP Port number for the MySQL server |
utr_readonly_key | Readonly API key for uptimerobot, used to update status pages if you are using uptimerobot to monitor uptime |
error_recipient | E-Mail address to receive core files in the event of a client crash (!) |
owner | Snowflake ID of the bot owner. There can only be one bot owner |
apikey | TriviaBot API key. This is NOT an Open Trivia Database key. Speak to Brain#0001 about API keys. |
modules | A list of modules to load. For basic functionality you should load at least module_diagnostics.so and module_trivia.so |
shitlist | An array of snowflake IDs of guilds where trivia cannot be started. Instead, the person issuing the !trivia start command will get a friendly message encouraging them to invite the bot to their own server. Put places like bot lists in here. |
Before the initial startup, you should first make a log directory inside your build directory:
mkdir my-bot-dir/build/log
Once this is done, you will be able to start the bot so long as you've set up the database and configuration file, above.
cd my-bot-dir
./run.sh
run.sh will restart the bot executable continually if it dies. If the bot quits, run.sh
will trigger mail-core-fire.sh
which will email a coredump to the admin user, if GDB is installed.
./bot [--dev|--test] [--members] [--clusterid <id> --maxclusters <n>]
Argument | Meaning |
---|---|
--dev | Run using the development token in the config file. Mutually exclusive with --test |
--test | Run using the live token in the config file, but squelch all outbound messages unless they originate from the test server (also defined in the config file) |
--members | Send a GUILD_MEMBERS intent when identifying to the discord gateway. Note that you'll need this after October 2020 for bots in over 100 servers. |
--clusterid | The id of this process in a cluster of maxclusters processes. Shards are equally shared between all clusters, e.g. if you have two clusters and ten shards each cluster process will have 5 shards on it. |
--maxclusters | Number of cluster processes to share shards across. You must launch at least this many processes, each of which has a unique cluster id between 0 and max - 1 as it's id using the --clusterid command line parameter |
Version/Date | Protocol | Platform/Libraries | Language | Status |
---|---|---|---|---|
1.0 / 2004 | IRC | WinBot 2.3 | WinBotScript (WBS) | Discontinued |
2.0 / 2005 | IRC | WinBot 2.3 | PlugPerl (Perl 5.6) | Discontinued |
3.0 / 2005 | IRC | Botnix 1.0 Beta 1 | Perl 5.6 | Discontinued |
4.0 / 2020 | Discord | Sporks, aegis.cpp | C++17 | Discontinued |
5.0 / 2021 | Discord | Sporks, D++ | C++17 | Active |