diff --git a/.gitignore b/.gitignore index 01d1d66..d3f4f1f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ +.vscode/ update/ .dockerignore -Dockerfile -src/tokens.py +src/tokens.env src/cogs/music_old.py diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..1f0f76d --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM python:3.8.6-slim + +RUN apt update && \ + apt install -y --no-install-recommends ffmpeg git && \ + apt autoremove +RUN /usr/local/bin/python -m pip install --upgrade pip + +COPY requirements.txt . +RUN pip install -r requirements.txt + +COPY src . + +CMD [ "python", "-u", "./main.py" ] diff --git a/README.md b/README.md index a039636..1950276 100644 --- a/README.md +++ b/README.md @@ -4,25 +4,28 @@ - Python 3.8.6 - [requirements.txt](requirements.txt) +- Docker #### __Setting up__ -- A `tokens.py` file that contains: +You have to replace `TOKEN_DISCORD`, `TOKEN_GENIUS`, `TOKEN_REDDIT_CLIENT_ID`, `TOKEN_REDDIT_CLIENT_SECRET` and `TOKEN_REDDIT_USER_AGENT` with your desired values. +With a [docker-compose](docker-compose.yml) or in command line: -```py -token_discord = "your discord token" -token_genius = "your genius token" -token_reddit = {"client_id": "your client id", "client_secret": "your secret pass", "user_agent": "your reddit's username"} +``` +docker run -d \ + --name="kassoubot" \ + mylloon/kassoubot \ + --TOKEN_DISCORD="yourValue" \ + --TOKEN_GENIUS="yourValue" \ + --TOKEN_REDDIT_CLIENT_ID="yourValue" \ + --TOKEN_REDDIT_CLIENT_SECRET="yourValue" \ + --TOKEN_REDDIT_USER_AGENT="yourValue" ``` To find reddit tokens, go to [this site](https://www.reddit.com/prefs/apps) and here are the instructions: ![instructions](https://i.imgur.com/tEzYKDA.png) *redirection uri (for copy/paste) : http://localhost:8080* -#### __Starting up__ - -- Run [main.py](main.py) - #### __Add the bot to your server__ - [This site](https://discordapi.com/permissions.html) allows you to choose which permissions to add by default to the bot. diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..2272774 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "2.1" +services: + kassoubot: + image: mylloon/kassoubot + container_name: kassoubot + environment: + - TOKEN_DISCORD=your-token-discord + - TOKEN_GENIUS=your-token-genius + - TOKEN_REDDIT_CLIENT_ID=your-reddit-client-id + - TOKEN_REDDIT_CLIENT_SECRET=your-reddit-client-secret + - TOKEN_REDDIT_USER_AGENT=your-reddit-user-agent + restart: unless-stopped diff --git a/src/cogs/internet.py b/src/cogs/internet.py index 93f4c9a..8633a21 100644 --- a/src/cogs/internet.py +++ b/src/cogs/internet.py @@ -1,7 +1,6 @@ -import discord, praw, json, requests, time, feedparser +import discord, praw, json, requests, time, feedparser, os from discord.ext import commands from random import randint, choice -from tokens import token_reddit as token # à l'importation de l'extension, le fichier se retrouve dans le '/' et non dans 'cogs/', ignorez l'erreur pylint def setup(client): client.add_cog(Internet(client)) @@ -34,7 +33,7 @@ class Internet(commands.Cog): async def _memes(self, ctx, *, args = ""): """Envois un meme de reddit.\n ➡ Syntaxe: .memes/meme [subreddit]⁢⁢⁢⁢⁢⁢⁢⁢⁢⁢""" try: - reddit = praw.Reddit(client_id = token['client_id'], client_secret = token['client_secret'], user_agent = f"disreddit /u/{token['user_agent']}, http://localhost:8080") + reddit = praw.Reddit(client_id = os.environ['TOKEN_REDDIT_CLIENT_ID'], client_secret = os.environ['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{os.environ['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") if args != "": # si il y a un arg différent d'un meme subredditchoix = args diff --git a/src/cogs/music.py b/src/cogs/music.py index a6603f5..66e8ef0 100644 --- a/src/cogs/music.py +++ b/src/cogs/music.py @@ -20,8 +20,8 @@ from discord.ext import commands # Genius API import lyricsgenius import time -from tokens import token_genius as token # à l'importation de l'extension, music.py se retrouve dans le '/' et non dans 'cogs/', ignorez l'erreur -genius = lyricsgenius.Genius(token) +import os +genius = lyricsgenius.Genius(os.environ['TOKEN_GENIUS']) # Silence useless bug reports messages youtube_dl.utils.bug_reports_message = lambda: '' diff --git a/src/main.py b/src/main.py index 009e809..a851d14 100644 --- a/src/main.py +++ b/src/main.py @@ -1,11 +1,10 @@ print("Connexion à Discord...") -import discord, re, pytz +import discord, re, pytz, os from discord.ext import commands from random import choice from datetime import datetime from pytz import timezone -from tokens import token_discord as token client = commands.Bot(command_prefix = ".", case_insensitive = True, intents = discord.Intents.all()) @@ -20,7 +19,7 @@ client.load_extension("cogs.autopublish") @client.event async def on_connect(): - print(f"Connecté avec le token : {token}.") + print(f"Connecté.") @client.event async def on_ready(): @@ -212,4 +211,4 @@ def user_or_nick(user): else: return f"{user.name}#{user.discriminator}" -client.run(token) +client.run(os.environ['TOKEN_DISCORD'])