Skip to content

Commit 794418d

Browse files
authored
Add documentation for bot and server configuration (#223)
* Create docs/ directory * README: Update usage and deployment docs * Add support for Python 3.9 * configure-guild.py: Set default notification level to only_mentions * Update development documentation * Document Pretix Mock content * Fix pretix-mock endpoints * pretix-mock: shut down properly * Fix: Use actual name to greet user, not typed name
1 parent d7ebfb3 commit 794418d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+690
-29
lines changed

README.md

Lines changed: 77 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@ The bot has the following extensions ("Cogs"):
1818

1919
## Screenshots
2020
### Registration Channel:
21-
![Registration Channel](./img/registration-channel.png)
21+
![Registration Channel](docs/img/registration-channel.png)
2222

2323
### Registration Form:
24-
![Registration Form](./img/registration-form.png)
24+
![Registration Form](docs/img/registration-form.png)
2525

2626
### Programme Notification:
27-
![Programme Notification](./img/programme-notification.png)
27+
![Programme Notification](docs/img/programme-notification.png)
2828

2929
## Configuration
3030

@@ -47,10 +47,12 @@ Cache files (will be created if necessary):
4747
* `pretix_cache.json`: Local cache of Pretix ticket data
4848
* `schedule_cache.json`: Local cache of [programapi](https://github.com/europython/programapi) schedule
4949

50-
## Setup
51-
### Quickstart using `pip`
50+
## Usage
5251

53-
If you just want to try the bot and skip the development setup, you can use `pip` (requires Python >= 3.11):
52+
This section describes how to install and run the bot.
53+
Please see below for development and EuroPython-specific deployment instructions.
54+
55+
With pip:
5456

5557
```shell
5658
# create and activate virtual environment (optional, but recommended)
@@ -65,17 +67,65 @@ export DISCORD_BOT_TOKEN=... # Windows: $env:DISCORD_BOT_TOKEN = '...'
6567
export PRETIX_TOKEN=... # Windows: $env:PRETIX_TOKEN = '...'
6668

6769
# run the bot with a given config file
68-
run-bot --config your-config-file.toml
70+
run-bot --config-file your-config-file.toml
71+
```
72+
73+
With uv:
74+
75+
```shell
76+
# install dependencies in virtual environment
77+
uv sync
78+
79+
# set environment variables
80+
export DISCORD_BOT_TOKEN=... # Windows: $env:DISCORD_BOT_TOKEN = '...'
81+
export PRETIX_TOKEN=... # Windows: $env:PRETIX_TOKEN = '...'
82+
83+
# run the bot with a given config file
84+
uv run run-bot --config-file your-config-file.toml
6985
```
7086

71-
### Full Development Setup
87+
## Development Setup
7288

73-
* Install `uv` as documented [here](https://docs.astral.sh/uv/getting-started/installation/).
74-
* Run `uv sync --dev` to create/update a virtual environment with all dependencies according to [`uv.lock`](./uv.lock).
75-
* Run `. .venv/bin/activate` (Windows: `.venv/Scripts/activate`) to activate the virtual environment
89+
NOTE: This project uses [uv](https://docs.astral.sh/uv/) to manage Python versions and dependencies.
90+
If you don't plan to add/remove/update dependencies, you can also use [pip](https://pip.pypa.io/en/stable/), and any Python version >= 3.9.
91+
92+
### Discord Server and Bot Setup
93+
94+
Follow [Discord Server and Bot Setup](docs/discord-server-bot-setup.md)
95+
if you don't yet have a Bot and Server for developing the bot.
96+
97+
Expected outcome: You have a Discord Bot Token and can run a Discord Bot on a Discord Server.
98+
99+
### Discord Server Configuration
100+
101+
Follow [Discord Server Configuration](docs/discord-server-configuration.md)
102+
to configure your existing Discord Server with the expected channels, roles and messages.
103+
104+
Expected outcome: A Discord Server ready to be used for this bot.
105+
106+
### Pretix Integration
107+
108+
This bot connects to a Pretix instance to obtain a list of valid tickets.
109+
110+
Follow [Pretix Client Setup](docs/pretix-client-setup.md) to either connect to a real Pretix instance,
111+
or to use a mock.
112+
113+
### Python environment setup
114+
115+
* Using `uv`
116+
* Install `uv` as documented [here](https://docs.astral.sh/uv/getting-started/installation/)
117+
* Activate virtual environment: `. .venv/bin/activate` (macOS, Linux) or `.venv/Scripts/activate` (Windows)
118+
* Run `uv sync --dev` to create/update a virtual environment with all dependencies according to [uv.lock](./uv.lock).
119+
* Using `pip`
120+
* Create a virtual environment: `python3 -m venv .venv` (might require `apt install python3-venv` or similar on some systems)
121+
* Activate virtual environment: `. .venv/bin/activate` (macOS, Linux) or `.venv/Scripts/activate` (Windows)
122+
* Ensure `pip` version is >= 25.1.0: `python3 -m pip install --upgrade pip` (earlier versions don't support [PEP 735](https://peps.python.org/pep-0735/) Dependency Groups)
123+
* Install all dependencies according to [pyproject.toml](pyproject.toml): `python3 -m pip install -e . --group dev`
76124
* Run `pre-commit install` to install the [pre-commit](https://pre-commit.com/) hooks.
77125
* Run `pre-commit run --all-files` to verify your setup. All checks should pass.
78126

127+
### Run the bot
128+
79129
To run the bot, use the following:
80130

81131
```shell
@@ -87,7 +137,7 @@ export PRETIX_TOKEN=... # Windows: $env:PRETIX_TOKEN = '...'
87137
run-bot --config your-config-file.toml
88138
```
89139

90-
#### Working with `uv`
140+
### Working with `uv`
91141

92142
This is a list of useful commands when working with `uv`.
93143
Please refer to the [uv documentation](https://docs.astral.sh/uv) or `uv help` for details.
@@ -123,15 +173,23 @@ uv remove [package]
123173
* Check code style: `ruff check .`
124174
* Run tests: `pytest`
125175

126-
### Deployment
176+
## Deployment
127177

128-
The bot is deployed on a VPS using a GitHub Action.
178+
For the EuroPython conference, this bot is deployed on a VPS.
129179
It uses Ansible to configure the VPS, and Docker Compose to run the bot.
180+
The deployment process is executed via a GitHub Action.
130181

131182
Related files:
132183

133-
* [.github/workflows/deploy.yml](./.github/workflows/deploy.yml): The GitHub Action
134-
* [ansible/deploy-playbook.yml](./ansible/deploy-playbook.yml): The Ansible Playbook
135-
* [Dockerfile](./Dockerfile): The Docker container recipe
136-
* [compose.yaml](./compose.yaml): The Docker Compose recipe
137-
* [prod-config.toml](./prod-config.toml): The Prod bot configuration
184+
* In this repository:
185+
* [.github/workflows/deploy.yml](./.github/workflows/deploy.yml): GitHub Action
186+
* [ansible/deploy-playbook.yml](./ansible/deploy-playbook.yml): Ansible Playbook
187+
* [Dockerfile](./Dockerfile): Docker container recipe
188+
* [compose.yaml](./compose.yaml): Docker Compose recipe
189+
* [prod-config.toml](./prod-config.toml): Prod bot configuration
190+
* On the VPS:
191+
* `/root/.secrets`: Contains `DISCORD_BOT_TOKEN` and `PRETIX_TOKEN`
192+
* `/root/livestreams.toml`: Livestream URL configuration
193+
* `/home/bot/registered_log.txt`: Registration log
194+
* `/home/bot/pretix_cache.json`: Pretix cache
195+
* `/home/bot/schedule_cache.json`: Program cache

docs/discord-server-bot-setup.md

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# Discord Server and Bot Setup
2+
3+
Follow this guide to
4+
5+
* Create a Discord Server
6+
* Create a Discord Bot
7+
* Connect the Bot to the Server
8+
9+
NOTE: These steps require a Discord account with two-factor authentication enabled.
10+
11+
## Create the Server
12+
13+
In the left sidebar of the Discord Window, click the button "Add a Server":
14+
15+
![Discord: Add a Server](img/add-server.png)
16+
17+
Select "Create My Own":
18+
19+
![Discord: Create My Own](img/create-my-own.png)
20+
21+
Skip further questions:
22+
23+
![Discord: Skip question](img/skip-question.png)
24+
25+
Configure the server name and icon (can be updated later), then click "Create":
26+
27+
![Discord: Server name and icon](img/server-name-and-icon.png)
28+
29+
Congratulations, you now have your own Discord server.
30+
31+
## Create a Bot
32+
33+
Go to https://discord.com/developers/applications/ and log in.
34+
35+
In the top-right corner, click "New Application".
36+
37+
![Bot: New Application](img/new-application.png)
38+
39+
Configure the application name (can be updated later), agree to the terms of service, and click "Create".
40+
41+
![Bot: Create Application](img/create-application.png)
42+
43+
In the left sidebar, go to "General Information" and configure the bot's icon and description (optional, can be updated later).
44+
45+
![Bot: Icon and Description](img/bot-icon-and-description.png)
46+
47+
Scroll down and configure the Terms of Service and Privacy Policy (optional, can be updated later).
48+
49+
![Bot: ToS and Privacy Policy](img/bot-tos-privacy.png)
50+
51+
In the left sidebar, go to "Installation".
52+
Remove the option "User install" and set the Install Link to "None".
53+
54+
![Bot: Install configuration](img/bot-install-config.png)
55+
56+
In the left sidebar, go to "Bot", then scroll down to "Privileged Gateway Intents".
57+
Activate "Server Member Intent" and "Message Content Intent".
58+
Click "Save Changes".
59+
60+
![Bot: Configure Intents](img/configure-intents.png)
61+
62+
In the left sidebar, go to "OAuth2".
63+
Select the scope "bot" and the permission "Administrator".
64+
65+
![Bot: Scope and Permissions](img/bot-scopes-and-permissions.png)
66+
67+
Scroll down, configure the integration type "Guild Install", and copy the URL.
68+
69+
![Bot: Integration URL](img/bot-integration-url.png)
70+
71+
Open the copied URL in a web browser. You will be prompted to open the Discord app.
72+
73+
![Bot: Open in Discord](img/bot-open-in-discord.png)
74+
75+
Proceed to add the bot to your server.
76+
77+
![Bot: Add to Server](img/bot-add-to-server.png)
78+
79+
Confirm the assigned permissions.
80+
81+
![Bot: Confirm Permissions](img/bot-confirm-permissions.png)
82+
83+
Congratulations, you created a bot and added it to a server.
84+
85+
![Bot: Post-Installation Screen](img/bot-post-install-screen.png)
86+
87+
## Use the Bot
88+
89+
To use the bot from Python, you need an authorization token.
90+
91+
Go back to https://discord.com/developers/applications/.
92+
In the left sidebar, go to "Bot", and click "Reset Token".
93+
94+
![Bot: Reset Token](img/bot-reset-token.png)
95+
96+
Confirm that step. This might require a two-factor authentication confirmation.
97+
98+
![Bot: Confirm Token Reset](img/bot-confirm-token-reset.png)
99+
100+
Copy your new token and store it somewhere safe.
101+
102+
![Bot: Copy Token](img/bot-copy-token.png)
103+
104+
To confirm the installation, install the Python package [discord.py](https://pypi.org/project/discord.py/)
105+
(e.g. with `pip install discord.py`), and run the following script (add your bot token at `BOT_TOKEN = "..."`):
106+
107+
```python
108+
import asyncio
109+
110+
import discord
111+
from discord.ext import commands
112+
113+
BOT_TOKEN = "..."
114+
115+
116+
class Bot(commands.Bot):
117+
async def on_ready(self):
118+
print("ready", self.user.name, self.user.id)
119+
120+
121+
class Ping(commands.Cog):
122+
@commands.hybrid_command(name="ping")
123+
async def ping(self, context):
124+
await context.send("Pong!")
125+
126+
127+
async def main():
128+
prefix = commands.when_mentioned_or("$")
129+
130+
intents = discord.Intents(messages=True, message_content=True)
131+
async with Bot(command_prefix=prefix, intents=intents) as bot:
132+
await bot.add_cog(Ping())
133+
await bot.start(BOT_TOKEN)
134+
135+
136+
if __name__ == "__main__":
137+
asyncio.run(main())
138+
```
139+
140+
In Discord, go to your server and write the message `$ping` in a text channel.
141+
The bot should respond with `Pong!`.
142+
143+
![Bot: Ping Pong](img/bot-ping-pong.png)
144+
145+
You can now stop the Python script by pressing Ctrl+C.

docs/discord-server-configuration.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Discord Server Configuration
2+
3+
Follow this guide to configure an existing Discord Server.
4+
5+
NOTE: This guide requires you to run a Discord Bot on the Discord Server.
6+
7+
## Remove Current Configuration (optional)
8+
9+
If you are starting with a fresh Discord Server, it is recommended to delete all existing channels
10+
and categories.
11+
12+
To delete a channel or category, right-click it, then left-click the "Delete" option.
13+
14+
![Server: Delete Category](img/server-delete-category.png)
15+
16+
Repeat this step until the server is empty.
17+
18+
![Server: Empty Server](img/empty-server.png)
19+
20+
NOTE: If you skip this step, the configuration script will still work and will not delete anything.
21+
22+
Ensure that [discord.py](https://pypi.org/project/discord.py/) and [pydantic](https://pypi.org/project/pydantic) are installed.
23+
Set the environment variable `BOT_TOKEN` to your authorization token,
24+
then run the script [scripts/configure-guild.py](/scripts/configure-guild.py).
25+
26+
```shell
27+
# macOS, Linux:
28+
export BOT_TOKEN="..."
29+
30+
# Windows:
31+
$env:BOT_TOKEN = '...'
32+
33+
python scripts/configure-guild.py --verbose
34+
```
35+
36+
Your server should now be fully configured.
37+
38+
![Server: Full Configuration](img/server-full-configuration.png)

docs/img/add-server.png

2.86 KB
Loading

docs/img/bot-add-to-server.png

31 KB
Loading

docs/img/bot-confirm-permissions.png

29.2 KB
Loading

docs/img/bot-confirm-token-reset.png

15.5 KB
Loading

docs/img/bot-copy-token.png

11.6 KB
Loading

docs/img/bot-icon-and-description.png

67.9 KB
Loading

docs/img/bot-install-config.png

65.5 KB
Loading

docs/img/bot-integration-url.png

13 KB
Loading

docs/img/bot-open-in-discord.png

22.9 KB
Loading

docs/img/bot-ping-pong.png

15.1 KB
Loading

docs/img/bot-post-install-screen.png

24.7 KB
Loading

docs/img/bot-reset-token.png

87.3 KB
Loading
148 KB
Loading

docs/img/bot-tos-privacy.png

121 KB
Loading

docs/img/configure-intents.png

172 KB
Loading

docs/img/create-application.png

26.2 KB
Loading

docs/img/create-my-own.png

39.8 KB
Loading

docs/img/empty-server.png

2.76 KB
Loading

docs/img/new-application.png

1.54 KB
Loading
File renamed without changes.
File renamed without changes.
File renamed without changes.

docs/img/server-delete-category.png

31 KB
Loading
131 KB
Loading

docs/img/server-name-and-icon.png

35.3 KB
Loading

docs/img/skip-question.png

32.7 KB
Loading

0 commit comments

Comments
 (0)