Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker deployment #107

Merged
merged 13 commits into from
Mar 22, 2022
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

### 2.5.0
- Fix `rl!new` showing unsuccessful reaction when the message creation was actually successful
- Add support for translations. To translate the bot's responses make a copy of [en-gb.json](https://github.com/eibex/reaction-light/blob/master/files/i18n/en-gb.json) and translate the associated strings. Consider sharing your translation as a pull request ([#74](https://github.com/eibex/reaction-light/issues/74) closed by [#77](https://github.com/eibex/reaction-light/pull/77) by [eibex](https://github.com/eibex), [Edwinexd](https://github.com/Edwinexd), and [d7415](https://github.com/d7415)).
- Add support for translations. To translate the bot's responses make a copy of [en-gb.json](https://github.com/eibex/reaction-light/blob/master/i18n/en-gb.json) and translate the associated strings. Consider sharing your translation as a pull request ([#74](https://github.com/eibex/reaction-light/issues/74) closed by [#77](https://github.com/eibex/reaction-light/pull/77) by [eibex](https://github.com/eibex), [Edwinexd](https://github.com/Edwinexd), and [d7415](https://github.com/d7415)).

### 2.4.3
- Fix deletion of wrong database entries under certain circumstances. Please check that all your messages are working before updating, and restore a backup if necessary ([#73](https://github.com/eibex/reaction-light/issues/73) closed by [#78](https://github.com/eibex/reaction-light/pull/78) by [Edwinexd](https://github.com/Edwinexd))
Expand Down
13 changes: 13 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM python:3.9

COPY ./ /bot/

RUN python3.9 -m pip install -r /bot/requirements.txt

# Remove local copies as these files gets mounted instead.
RUN rm -r /bot/files
RUN rm -r /bot/config.ini

WORKDIR /bot

CMD ["python3.9", "bot.py"]
81 changes: 58 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ Light yet powerful reaction role bot coded in Python.
You can host the bot yourself by configuring the `config.ini` file (manually or via `setup.py`).

## Contents
- [Requirements](#requirements)
- [Setup](#setup)
- [Running the bot](#running-the-bot)
- [Deployment](#deployment)
- [Docker](#docker)
- [Git and Zip](#git-and-zip)
- [Commands](#commands)
- [Usage Example](#usage-example)
- [Updating](#updating)
- [Update a git install with a command](#update-a-git-install-with-a-command)
- [Manually updating a Docker installation](#manually-updating-a-docker-installation)
- [Manually updating a git install](#manually-updating-a-git-install)
- [Manually updating a zip install](#manually-updating-a-zip-install)
- [Roadmap](#roadmap)
Expand All @@ -37,17 +38,38 @@ You can host the bot yourself by configuring the `config.ini` file (manually or
- [Contribute](#contribute)
- [License](#license)

## Requirements
This bot requires [disnake](https://github.com/DisnakeDev/disnake) and Python 3.8+.

You can get disnake via PyPI or GitHub:
```
python3 -m pip install -r requirements.txt
```

## Setup
## Deployment
### Docker
- Clone the repository using `git clone https://github.com/eibex/reaction-light.git` (or download it as a `*.zip` file and extract it - it is recommended to use git instead of the zip archive)
- `git` comes pre-installed on most Linux-based operating systems. On Windows, if you are not familiar with git, you can use [GitHub Desktop](https://desktop.github.com/)
- Run `setup.py` and follow the instructions or create a `config.ini` file (example provided in `config.ini.sample`) or edit it manually
- Insert the token of your bot (found at: https://discord.com/developers/applications/)
- You can set most of the other values via commands later (set manually `name` and `logo`, which appear in the footer of each embed)
- Activate the message content intent for your bot (found at: https://discord.com/developers/applications/ under the bot section)
- **Optional**: Edit the `activities.csv` file (example provided in `activities.csv.sample`):
- In each row (line), add the activity the bot will display (`playing <activity>`). The bot will loop through them every 30 seconds.
- If you want a static activity just add one line.
- Do not use commas `,`.
- Build the Docker image using `docker build -t reaction-light .`
- Create and start a container using
```bash
docker run -d \
--name reaction-light \
--restart always \
-v /path/to/reaction-light/files:/bot/files \
-v /path/to/reaction-light/config.ini:/bot/config.ini \
reaction-light
```
- Invite the bot to your server(s) with enough permissions (Manage Roles, Manage Channels, Send Messages, Manage Messages, Add Reactions)
- You can use this link (need to replace **CLIENT_ID** with your bot's ID, visible under the general information tab):
- `https://discord.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot%20applications.commands&permissions=2415978560`
- On your Discord server, go to: `Server Settings > Roles` and move `Reaction Light` in a position that is above all roles that it needs to add/remove. The bot only has permission to manage the roles below its own role.
- Run `rl!admin @Role` to give users with that role permission to create reaction-role messages (even administrators need it). You need to be a server administrator to use this command.
### Git and Zip
- Download and install python 3.8+ and pip via your preferred method (e.g. `apt-get install python3 python3-pip`)
- Clone the repository using `git clone https://github.com/eibex/reaction-light.git` (or download it as a `*.zip` file and extract it - it is recommended to use git instead of the zip archive)
- `git` comes pre-installed on most Linux-based operating systems. On Windows, if you are not familiar with git, you can use [GitHub Desktop](https://desktop.github.com/)
- Install requirements via pip using `python3 -m pip install -r requirements.txt`
- Run `setup.py` and follow the instructions or create a `config.ini` file (example provided in `config.ini.sample`) or edit it manually
- Insert the token of your bot (found at: https://discord.com/developers/applications/)
- You can set most of the other values via commands later (set manually `name` and `logo`, which appear in the footer of each embed)
Expand All @@ -59,16 +81,14 @@ https://discord.com/oauth2/authorize?&client_id=CLIENT_ID&scope=bot%20applicatio
- On your Discord server, go to: `Server Settings > Roles` and move `Reaction Light` (or your bot's name) in a position that is above all roles that it needs to add/remove. The bot only has permission to manage the roles below its own role.
- Run `/admin add @Role` to give users with that role permission to create reaction-role messages (even administrators need it). You need to be a server administrator to use this command.

## Running the bot
The bot can be run by using:
```
python3 bot.py
```

To run it as a background task (recommended unless debugging):
```
nohup python3 bot.py &
```
- The bot can be run by using:
```
python3 bot.py
```
- To run it as a background task (recommended unless debugging):
```
nohup python3 bot.py &
```

## Commands
All commands require an admin role which you can set by using `/admin add` (requires administrator permissions on the server). The bot will reply with missing permissions otherwise. Executing a command without any argument will prompt the bot to provide you with instructions on how to use the command effectively.
Expand Down Expand Up @@ -126,6 +146,21 @@ If you set a system channel in `config.ini`, your bot will check for new version
### Update a git install with a command
Type `/bot update` to update the bot and restart it.

### Manually updating a Docker installation
- Navigate to the reaction-light directory
- Run `git pull origin master`
- Stop and delete the reaction-light container using `docker stop reaction-light && docker rm reaction-light`
- Rebuild the Docker image using `docker build -t reaction-light .`
- Create and start a new container using
```bash
docker run -d \
--name reaction-light \
--restart always \
-v /path/to/reaction-light/files:/bot/files \
-v /path/to/reaction-light/config.ini:/bot/config.ini \
reaction-light
```

### Manually updating a git install
- Navigate to the reaction-light directory
- Run `git pull origin master`
Expand Down Expand Up @@ -171,7 +206,7 @@ If you would like to contribute to this project, fork it and then create a pull
black --line-length=130 .
```

Even if you are not a Python programmer, you can contribute to this project by reporting bugs, requesting new features, or translating the bot in your language. To translate the bot simply copy the [English file](https://github.com/eibex/reaction-light/blob/master/files/i18n/en-gb.json) and replace the text inside the second quotes of each line. Do not replace the text within `{}`. Click [here](https://github.com/eibex/reaction-light/blob/master/files/i18n/it-it.json) for an example.
Even if you are not a Python programmer, you can contribute to this project by reporting bugs, requesting new features, or translating the bot in your language. To translate the bot simply copy the [English file](https://github.com/eibex/reaction-light/blob/master/i18n/en-gb.json) and replace the text inside the second quotes of each line. Do not replace the text within `{}`. Click [here](https://github.com/eibex/reaction-light/blob/master/i18n/it-it.json) for an example.

## License
[MIT](https://github.com/eibex/reaction-light/blob/master/LICENSE)
2 changes: 1 addition & 1 deletion cogs/utils/i18n.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,4 @@ def get(self, item):

language = str(config.get("server", "language", fallback="en-gb"))

response = Response(f"{directory}/files/i18n", language)
response = Response(f"{directory}/i18n", language)
2 changes: 1 addition & 1 deletion files/i18n/en-gb.json → i18n/en-gb.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"other-author-error": "I can only edit messages that are created by me, please edit the message in some other way.",
"empty-message-error": "You can't use an empty message as role-reaction message.",
"edit-permission-error": "I do not have permissions to edit the message.",
"update-notification": "An update is available. Download Reaction Light **v{new_version}** at <https://github.com/eibex/reaction-light> or simply use `/bot update` (only works with git installations).",
"update-notification": "An update is available. Download Reaction Light **v{new_version}** at <https://github.com/eibex/reaction-light> or simply use `/bot update` (only works on Docker and git installations).",
"version": "I am currently running Reaction Light **v{version}**. The latest available version is **v{latest_version}**.",
"new-role-dm": "You now have the following role: **{role_name}**",
"removed-role-dm": "You do not have the following role anymore: **{role_name}**",
Expand Down
2 changes: 1 addition & 1 deletion files/i18n/it-it.json → i18n/it-it.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"other-author-error": "Posso solo modificare i messaggi creati da me, modifica il messaggio in un'altra maniera.",
"empty-message-error": "Non puoi usare un messaggio vuoto.",
"edit-permission-error": "Non ho i permessi per modificare il messaggio.",
"update-notification": "Un aggiornamento è disponibile. Scarica Reaction Light **v{new_version}** su <https://github.com/eibex/reaction-light> o usa semplicemente `/bot update` (funziona solamente su installazioni create con git).",
"update-notification": "Un aggiornamento è disponibile. Scarica Reaction Light **v{new_version}** su <https://github.com/eibex/reaction-light> o usa semplicemente `/bot update` (funziona solamente su installazioni create con Docker e git).",
"version": "La mia versione attuale è Reaction Light **v{version}**. L'ultima versione disponibile è **v{latest_version}**.",
"new-role-dm": "Hai ottenuto il seguente ruolo: **{role_name}**",
"removed-role-dm": "Non hai più il seguente ruolo: **{role_name}**",
Expand Down