remove tokens.py and adding environnement variable

This commit is contained in:
Mylloon 2021-03-17 20:25:10 +01:00
parent be4412224e
commit 131b452e14
5 changed files with 18 additions and 20 deletions

2
.gitignore vendored
View file

@ -1,5 +1,5 @@
update/ update/
.dockerignore .dockerignore
Dockerfile Dockerfile
src/tokens.py src/tokens.env
src/cogs/music_old.py src/cogs/music_old.py

View file

@ -4,25 +4,25 @@
- Python 3.8.6 - Python 3.8.6
- [requirements.txt](requirements.txt) - [requirements.txt](requirements.txt)
- Docker
#### __Setting up__ #### __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) 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* *redirection uri (for copy/paste) : http://localhost:8080*
#### __Starting up__
- Run [main.py](main.py)
#### __Add the bot to your server__ #### __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. - [This site](https://discordapi.com/permissions.html) allows you to choose which permissions to add by default to the bot.

View file

@ -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 discord.ext import commands
from random import randint, choice 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): def setup(client):
client.add_cog(Internet(client)) client.add_cog(Internet(client))
@ -34,7 +33,7 @@ class Internet(commands.Cog):
async def _memes(self, ctx, *, args = ""): async def _memes(self, ctx, *, args = ""):
"""Envois un meme de reddit.\n ➡ Syntaxe: .memes/meme [subreddit]""" """Envois un meme de reddit.\n ➡ Syntaxe: .memes/meme [subreddit]"""
try: 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 if args != "": # si il y a un arg différent d'un meme
subredditchoix = args subredditchoix = args

View file

@ -20,8 +20,8 @@ from discord.ext import commands
# Genius API # Genius API
import lyricsgenius import lyricsgenius
import time 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 import os
genius = lyricsgenius.Genius(token) genius = lyricsgenius.Genius(os.environ['TOKEN_GENIUS'])
# Silence useless bug reports messages # Silence useless bug reports messages
youtube_dl.utils.bug_reports_message = lambda: '' youtube_dl.utils.bug_reports_message = lambda: ''

View file

@ -1,11 +1,10 @@
print("Connexion à Discord...") print("Connexion à Discord...")
import discord, re, pytz import discord, re, pytz, os
from discord.ext import commands from discord.ext import commands
from random import choice from random import choice
from datetime import datetime from datetime import datetime
from pytz import timezone from pytz import timezone
from tokens import token_discord as token
client = commands.Bot(command_prefix = ".", case_insensitive = True, intents = discord.Intents.all()) client = commands.Bot(command_prefix = ".", case_insensitive = True, intents = discord.Intents.all())
@ -20,7 +19,7 @@ client.load_extension("cogs.autopublish")
@client.event @client.event
async def on_connect(): async def on_connect():
print(f"Connecté avec le token : {token}.") print(f"Connecté.")
@client.event @client.event
async def on_ready(): async def on_ready():
@ -212,4 +211,4 @@ def user_or_nick(user):
else: else:
return f"{user.name}#{user.discriminator}" return f"{user.name}#{user.discriminator}"
client.run(token) client.run(os.environ['TOKEN_DISCORD'])