diff --git a/.gitignore b/.gitignore index 01d1d66..c8f4f3d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ update/ .dockerignore Dockerfile -src/tokens.py +src/tokens.env src/cogs/music_old.py diff --git a/README.md b/README.md index a039636..08a7067 100644 --- a/README.md +++ b/README.md @@ -4,25 +4,25 @@ - Python 3.8.6 - [requirements.txt](requirements.txt) +- Docker #### __Setting up__ -- A `tokens.py` file that contains: +docker...in progress... + +env: + +TOKEN_DISCORD="your token discord" +TOKEN_GENIUS="your genius token" +TOKEN_REDDIT_CLIENT_ID="your client id" +TOKEN_REDDIT_CLIENT_SECRET="your client secret" +TOKEN_REDDIT_USER_AGENT="your user agent" -```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"} -``` 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/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'])