Skip to content

Instantly share code, notes, and snippets.

@Akarys42
Last active December 31, 2019 13:35
Show Gist options
  • Save Akarys42/989dcfa41536c9f3b15c844ea4f04d72 to your computer and use it in GitHub Desktop.
Save Akarys42/989dcfa41536c9f3b15c844ea4f04d72 to your computer and use it in GitHub Desktop.
How-to guide about setup the site and the bot without docker for Win 10 Home Users

Requirements

Working with the site

The bot rely on the site to provide access to his database. It mean that if you want your local bot to have access to a database, which is required for most of his functionalities. Learn how to setup the site here

Fork the project

You will need access to a copy of the git repository of your own that will allow you to edit the code and push your commits to. Creating a copy of a repository under your own account is called a fork.

  • Learn how to create a fork of the repository here. This is where all your changes and commits will be pushed to, and from where your PRs will originate from. For any staff member or contributor, since you have write permissions already to the original repository, you can just create a feature branch to push your commits to instead.

Development environment

  1. Clone your fork to a local project directory
  2. Install the project's dependencies

Test server and bot account

You will need your own test server and bot account on Discord to test your changes to the bot.

Channels

  • #ot-offtopics (at least one)
  • #help-0 (at least one)
  • #bot-commands
  • #reddit
  • #dev-log
  • #mods
  • #defcon
  • #mod-alerts
  • #talent-pool
  • #big-brother
  • #mod-log
  • #user-log
  • #message-change-log

Roles

  • @Admins
  • @Moderators
  • @Developers (to act as verified role, same as in-server)
  • @Muted

Configure the bot

Configuration file

Most of the configuration settings default of the bot are inside the comfig-default.yml file. However, this file is checked out by git, so you shouldn't edit this file, except for adding new entries. Instead of modifying this file, you can duplicate it and name it config.yml, and the bot will use it to override default values. You need to change the following values in the config.yml fle:

  • Copy the test server id and copy it to the id entry in the guild category. If you are not sure about how to copy the guild and channel IDs, check out the information over here.
  • Change the channel and role IDs in the guild too to match the ones in your test server.
  • Create a webhook in each of #talent-pool, #big-brother and #reddit and copy the IDs for them into the config file also.
  • Go down to the urls category and set site to "pythondiscord.local:8000".
  • In the same category set also site_schema to "http://".

Environment variables

We use some environment variables to safely store a couple of settings. Instead of creating actual environment variables, we are going to put them in a .env file to keep everything securized. Variable are defined one per line using a key=value syntax. First thing first, we need to create this file inside the root of your local clone, but Windows doesn't allow you to simply rename a file .env, so we need to bypass this restriction using command line.

echo. > .env

Then, you can type in the file the following :

BOT_API_KEY=badbot13m0n8f570f942013fc818f234916ca531
BOT_TOKEN=<bot token here>

And replace <bot token here> by your actual bot token.

Run the project

If you also run the site, start it first, and then use pipenv to launch the bot.

pipenv run start

Working with Git

Now that you have everything setup, it is finally time to make changes to the bot! If you have not yet read the contributing guidelines, now is a good time. Contributions that do not adhere to the guidelines may be rejected. Notably, version control of our projects is done using Git and Github. It can be intimidating at first, so feel free to ask for any help in the server. Click here to see the basic Git workflow when contributing to one of our projects. Have fun!

Requirements

Fork the project

You will need access to a copy of the git repository of your own that will allow you to edit the code and push your commits to. Creating a copy of a repository under your own account is called a fork.

  • Learn how to create a fork of the repository here. This is where all your changes and commits will be pushed to, and from where your PRs will originate from. For any staff member or contributor, since you have write permissions already to the original repository, you can just create a feature branch to push your commits to instead.

Development environment

  1. Clone your fork to a local project directory
  2. Install the project's dependencies

Prepare your hosts files

What's a Host file?

The host file maps a hostname/domain to an IP address, allowing you to visit a given domain on your browser and have it resolve by your system to the given IP address, even if it's pointed back to your own system or network. When staging a local Site project, you will need to add some entries to your hosts file so you can visit the site with the domain http://pythondiscord.local:8000.

How to add it?

  1. Open Notepad as Administrator.
  2. Open the file C:\Windows\System32\Drivers\etc\hosts.
  3. Add this content at the bottom of the file :
127.0.0.1   pythondiscord.local
127.0.0.1   api.pythondiscord.local
127.0.0.1   staff.pythondiscord.local
127.0.0.1   admin.pythondiscord.local

Setup the database

PostgreSQL is installed, we now need to create the user that the site will use to connect to the database, and the database itself. Open a terminal and enter this command to connect to the Postrges.

psql -qd postgres -U postgres

Once you are connected, you can now enter those two commands:

  • CREATE USER pysite WITH SUPERUSER CREATEDB PASSWORD 'pysite'; to create a new superuser named pysite.
  • CREATE DATABASE pysite WITH OWNER pysite; to create a new database owned by the user pysite we created previously. The database is now ready to go, you can now type \q to disconnect.

Environment variables

We use some environment variables to alter some of the Django settings. Instead of creating actual environment variables, we are going to put them in a .env file to keep everything clustered. Variable are defined one per line using a key=value syntax. First thing first, we need to create this file inside the root of your local clone, but Windows doesn't allow you to simply rename a file .env, so we need to bypass this restriction using command line.

echo. > .env

Then, you can type in the file the following :

DATABASE_URL=postgres://pysite:pysite@localhost:5432/pysite
SECRET_KEY=suitable-for-development-only
STATIC_ROOT=C:/Users/%username%/AppData/Local/Temp/django
DEBUG=1

Run the project

To run the project, launch it using pipenv and visit it at http://pythondiscord.local:8000/

pipenv run start

Use CTRL + BREAK to stop it.

Working on the project

The development environment will watch for code changes in your project directory and will restart the server when a module has been edited automatically. You shouldn't need to manually restart the container during a developing session. Click here to see the basic Git workflow when contributing to one of our projects.

Django admin site

Django provides an interface for administration with which you can view and edit the models among other things. It can be found at http://admin.pythondiscord.local:8000. The default credentials are admin for the username and admin for the password.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment