How to install DuckHunt and DuckHunt community on your server
This article is a step-by-step tutorial on how to install DuckHunt, and the support server bot, DuckHunt Community. If you want to help developing the bot, this tutorial is the official way to setup your developpement environnemnt
Let’s start by a recap of what DuckHunt (DH), and DuckHunt-Community (DHC) is.
What is DuckHunt
DuckHunt is a discord game bot, created following MenzAgitat own DuckHunt IRC bot. The primary goal of the game is to kill ducks. To make the game more fun and entertaining, a big number of commands, shop items, special ducks, have been added since the first version.
Of course, hosting a big game across so many discord servers (guilds) require a great support team. The support is provided, on the official DuckHunt Support Server. To help with moderating the previous server, a custom bot has been developed : DuckHunt-Community
Both bots use the latest version of python on discord.py at the time of writing, respectively 3.6 and the rewrite branch.
The game has been open-sourced on GitHub.
Where can I find help on the DuckHunt Bot
If you don’t want to install DuckHunt, but just want to use it, you are in the wrong place. An up-to-date website with the command list, the settings, usage, FAQs, and the installation tutorial to get the official bot on your server are available on the Bot Website
Prerequisites
If you want to proceed with the bot installation, you’ll need :
- A VPS or a linux (ubuntu) box to run the bot. You can get them for cheap at ScaleWay (a START1-M or L will do just fine, depending on the guild count) or DigitalOcean, but you can’t get them for free
- An internet connection
- A basic understanding of terminal, and discord bots
- A discord account
Additionally, the configuration used in this tutorial is as follow.
- A START1-M VPS bought at ScaleWay
- The latest ubuntu LTS version : Bionic Beaver (18.04)
- IPv6 Disabled, we don’t need it to connect to Discord.
Feel free to change this configuration if needed, but you may need to adapt some parts of the tutorial.
Roadmap
We’ll start by installing dependencies to both bots, then we will fully install DuckHunt, and to finish things up DuckHunt Commmunity
Customize this post
Installation
Dependencies
Let’s connect to our new server using
ssh root@§§server_IP§§
Now, let’s get the system up-to-date and install dependencies:
apt update
apt upgrade -y
apt install -y apt-utils git htop screen apache2 php php-mysql python3-pip python3-dev mysql-client mysql-server libmysqlclient-dev
Create the DuckHunt User
adduser duckhunt
And provide a password if asked.
Download the code of both bots in the specified directories.
su - duckhunt
git clone https://github.com/DuckHunt-discord/DHV3.git §§DH_installation_folder§§
git clone https://github.com/DuckHunt-discord/DuckHunt-Community-Rewrite.git §§DHC_installation_folder§§
exit
Let’s install python requirements for DuckHunt
cd §§DH_installation_folder§§
pip3 install -r requirements.txt
DuckHunt
Database
Time have come to create the database for DuckHunt.
Login as the root user on the DataBase:
mysql -u root -proot
In the MySQL prompt, to create the user and the database, write
create database §§DH_mysql_db_name§§;
grant all privileges on §§DH_mysql_db_name§§.* to '§§DH_mysql_db_user§§'@'localhost' identified by "§§DH_mysql_db_password§§";
flush privileges;
exit;
Then, load the schema into the database.
mysql --database=§§DH_mysql_db_name§§ -u §§DH_mysql_db_user§§ -p§§DH_mysql_db_password§§ < §§DH_installation_folder§§/schema.sql
Configuration
Now that the database is correctly setup, give the bot the credentials to connect to discord.
For this, create a credentials.json
file using
nano §§DH_installation_folder§§/credentials.json
In this file, add the following :
{
"token": "§§DH_token§§",
"bots_discord_pw_key" : "",
"discordbots_org_key" : ""
}
Then, save and quit (CTRL-X + Y).
Open the configuration file with
nano §§DH_installation_folder§§/cogs/helpers/config.py
At least, locate the lines concerning the database settings and update them to look like this:
# > Database settings < #
# User used to connect to the Mysql DB
bot.database_user = "§§DH_mysql_db_user§§"
# Password for the user used to connect to the Mysql DB
bot.database_password = "§§DH_mysql_db_password§§"
# Name of the table used in the Mysql DB
bot.database_name = "§§DH_mysql_db_name§§"
Of course, you can update other settings there.
Then, save and exit (CTRL-X + Y).
Starting
DuckHunt should now be working \o/. To test and start it, type
cd §§DH_installation_folder§§ && python3 ./bot.py
WebSite
Let’s start by configuring the DB for it :
nano §§DH_installation_folder§§/web/duckstats.php
Locate the lines like this and replace them:
$dbname = "§§DH_mysql_db_name§§";
$username = "§§DH_mysql_db_user§§";
$password = "§§DH_mysql_db_password§§";
You can also change the server name in web/live-ducks.php
if needed
A simple symlink should do the trick to serve it:
rm -Rv /var/www/html
ln -s §§DH_installation_folder§§/web /var/www/html
Finally, to save the data from the stats API periodically, open the crontab
su - duckhunt
crontab -e
Add the following :
0 * * * * cd §§DH_installation_folder§§/web ; python3 ./save_historical_to_csv.py
Exit nano as usual, and type exit
to return to the root prompt
DuckHunt Community
DuckHunt Community should be really easier to install, since we don’t require a database for it.
Create necessary directories
To let DuckHunt-Community store data about bans and stuff, we’ll need the following directory structure.
mkdir §§DHC_installation_folder§§/mods
mkdir §§DHC_installation_folder§§/mods/cases
mkdir §§DHC_installation_folder§§/mods/users
echo '1' > §§DHC_installation_folder§§/mods/current_case.txt
mkdir §§DHC_installation_folder§§/users
Configuration
Again, give the bot the credentials to connect to discord.
For this, create a credentials.json
file using
nano §§DHC_installation_folder§§/credentials.json
In this file, add the following :
{
"token": "§§DHC_token§§"
}
Last Steps
Auto-restart
You’ll probably want the bot to restart every time it fails, or when you use the dhexit
command. Feel free to use this tutorial for this.