Skip to content

Commit

Permalink
changed how we obtain discord token to come from env variable (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
SonOfLope authored Feb 4, 2023
1 parent a21db64 commit 71f3051
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 31 deletions.
1 change: 0 additions & 1 deletion .github/workflows/deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ jobs:
tags: ${{ secrets.DOCKER_HUB_REPOSITORY }}:latest
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
build-args: token=${{ secrets.DISCORD_TOKEN }}
- name: Image digest


Expand Down
14 changes: 6 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
# Light based python image
FROM python:3.9-alpine

# Git is required for requirements.txt
RUN apk update
RUN apk add git

# Work in /app for the application from container
WORKDIR /app
# Copy actual directory in /app
COPY . .

# Read token from argument
ARG token
# Define an environnement Variable
ENV JETON=${token}

# run necessary command to install all modules
RUN pip install -r requirements.txt

RUN pip install git+https://github.com/Pycord-Development/pycord
# run trema
CMD python -u trema.py -j ${JETON}
CMD python -u trema.py
20 changes: 14 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,20 @@ données.

### Lancement de Trëma

Lancez le robot en ligne de commande en lui donnant son jeton
d'authentification.
Définissez la variable d'environnement suivante :
- DISCORD_TOKEN : Discord bot token

Installer les dépendances en ligne de commande.

```bash
pip install -r requirements.txt
pip install git+https://github.com/Pycord-Development/pycord
```

Lancez le robot en ligne de commande.

```bash
python trema.py -j [jeton]
python trema.py
```

## Docker
Expand All @@ -63,7 +72,7 @@ Se placer à la racine du projet.
Exectuer la commande suivante :

```bash
docker build -t trema --build-arg token=<jeton> .
docker build -t trema .
```

### Lancer l'image
Expand Down Expand Up @@ -92,5 +101,4 @@ pytest -v ./tests/[nom du fichier].py
Pour lancer un seul test d'un fichier, lancez la commande
suivante.
```
pytest -v ./tests/[nom du fichier].py::[nom de la fonction]
pytest -v ./tests/[nom du fichier].py::[nom de la fonction]
1 change: 0 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
jsonschema==4.7.2
py-cord==2.0.0b7
pymongo==4.1.1
pytest~=7.2.0
discord~=2.1.0
21 changes: 6 additions & 15 deletions trema.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
Discord des clubs étudiants de l'ÉTS.
"""


from argparse import ArgumentParser
import os
import discord
import sys

from events import\
create_event_reactions
Expand All @@ -16,21 +16,12 @@
from trema_database import\
get_trema_database


def _make_arg_parser():
parser = ArgumentParser(description=__doc__)
parser.add_argument("-j", "--jeton", type=str,
help="Le jeton d'authentification de ce robot logiciel")
return parser


arg_parser = _make_arg_parser()
args = arg_parser.parse_args()

bot_token = args.jeton
bot_token = os.getenv('DISCORD_TOKEN')
if not bot_token:
print('ERROR: Token var is missing: DISCORD_TOKEN')
sys.exit(-1)

intents = discord.Intents.default()
intents.members = True

trema = discord.Bot(intents=intents)

Expand Down

0 comments on commit 71f3051

Please sign in to comment.