using new .env system
This commit is contained in:
parent
66c2e2c241
commit
54bee59aa8
7 changed files with 16 additions and 13 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,5 +1,5 @@
|
|||
.vscode/
|
||||
update/
|
||||
__pycache__/
|
||||
.envrc
|
||||
.env
|
||||
*.sqlite3
|
||||
|
|
|
@ -38,5 +38,5 @@ To find reddit tokens, go to [this site](https://www.reddit.com/prefs/apps) and
|
|||
- Using SQLite for the database.
|
||||
|
||||
## __Launching locally__
|
||||
If you want to run it without Docker, I personally use [direnv](https://direnv.net/) to store variables and have them only in the working folder.
|
||||
If you want to run it without Docker, create an .env file to store variables in the root folder.
|
||||
Simply run `python3 main.py` in `src` folder to launch the bot in the repo folder.
|
||||
|
|
|
@ -5,3 +5,4 @@ youtube-dl==2021.6.6 # music
|
|||
lyricsgenius==3.0.1 # lyrics
|
||||
feedparser==6.0.8 # rss feed (news)
|
||||
discord-py-slash-command==2.0.1 # slash commands
|
||||
python_dotenv==0.19.0 # using .env file
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
import discord
|
||||
from feedparser import parse
|
||||
from os import environ
|
||||
from discord.ext import commands
|
||||
from random import choice
|
||||
from asyncpraw import Reddit
|
||||
from discord_slash import cog_ext
|
||||
from utils.core import randomImage, isSlash, mySendHidden
|
||||
from utils.core import randomImage, isSlash, mySendHidden, load
|
||||
|
||||
def setup(client):
|
||||
client.add_cog(Internet(client))
|
||||
|
@ -14,6 +13,7 @@ class Internet(commands.Cog):
|
|||
"""Commandes relatives à ce qui provient d'internet."""
|
||||
def __init__(self, client):
|
||||
self.client = client
|
||||
self.keys = load(["TOKEN_REDDIT_CLIENT_ID", "TOKEN_REDDIT_CLIENT_SECRET", "TOKEN_REDDIT_USER_AGENT"])
|
||||
|
||||
@commands.command(name='memes', aliases = ['meme'])
|
||||
async def _memes(self, ctx, *args):
|
||||
|
@ -32,7 +32,7 @@ class Internet(commands.Cog):
|
|||
return await mySendHidden(ctx, fromSlash, f"Désolé, tu demandes du nsfw... Fais plutôt **{ctx.prefix}sexe**.")
|
||||
|
||||
try:
|
||||
async with Reddit(client_id = environ['TOKEN_REDDIT_CLIENT_ID'], client_secret = environ['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{environ['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") as reddit:
|
||||
async with Reddit(client_id = self.keys['TOKEN_REDDIT_CLIENT_ID'], client_secret = self.keys['TOKEN_REDDIT_CLIENT_SECRET'], user_agent = f"disreddit /u/{self.keys['TOKEN_REDDIT_USER_AGENT']}, http://localhost:8080") as reddit:
|
||||
subreddit = await reddit.subreddit(subredditchoix) # récupération du subreddit
|
||||
hot = subreddit.top(limit = 20) # récupération des memes avec une limite aux 10 premiers memes
|
||||
all_subs = [item async for item in hot] # liste des memes
|
||||
|
|
|
@ -19,10 +19,10 @@ from discord.ext import commands
|
|||
|
||||
# Genius API
|
||||
from lyricsgenius import Genius
|
||||
from os import environ
|
||||
from utils.core import ligneFormatage, userOrNick
|
||||
from utils.core import ligneFormatage, userOrNick, load
|
||||
from utils.time import nowCustom
|
||||
genius = Genius(environ['TOKEN_GENIUS'])
|
||||
|
||||
genius = Genius(load(["TOKEN_GENIUS"])["TOKEN_GENIUS"])
|
||||
|
||||
# Silence useless bug reports messages
|
||||
youtube_dl.utils.bug_reports_message = lambda: ''
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
print("Chargement des extensions & librairie...", end = " ")
|
||||
|
||||
import discord
|
||||
from os import environ, listdir
|
||||
from os import listdir
|
||||
from discord_slash import SlashCommand
|
||||
from discord.ext import commands
|
||||
from utils.reminder import Reminder
|
||||
customPrefix = environ['PREFIX']
|
||||
from utils.core import load
|
||||
keys = load(["PREFIX", "TOKEN_DISCORD"])
|
||||
customPrefix = keys["PREFIX"]
|
||||
|
||||
client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all())
|
||||
slash = SlashCommand(client, sync_commands = True)
|
||||
|
@ -54,4 +56,4 @@ async def on_message(message):
|
|||
await ctx.send(f">>> Coucou !\nMon préfix est `{prefix}` et ma commande d'aide est `{prefix}help`")
|
||||
|
||||
print("Connexion à Discord...", end = " ")
|
||||
client.run(environ['TOKEN_DISCORD'])
|
||||
client.run(keys["TOKEN_DISCORD"])
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
from os import environ
|
||||
from pytz import timezone
|
||||
from datetime import datetime, timedelta
|
||||
from re import findall
|
||||
from utils.core import load
|
||||
|
||||
myTimezone = environ['TIMEZONE']
|
||||
myTimezone = load(["TIMEZONE"])["TIMEZONE"]
|
||||
|
||||
def stringTempsVersSecondes(time):
|
||||
"""Convertis une durée rentrée par un utilisateur en string vers des secondes en int"""
|
||||
|
|
Reference in a new issue