Added possibility to disable cogs with an environment variable (mainly for Docker)
This commit is contained in:
parent
c123d04631
commit
e494990673
3 changed files with 23 additions and 5 deletions
|
@ -21,6 +21,9 @@ docker run -d \
|
||||||
-v /here/your/path/:/db
|
-v /here/your/path/:/db
|
||||||
```
|
```
|
||||||
|
|
||||||
|
You can add the environment variable `DEACTIVATE` to disable some cogs (separate the cogs with commas and no spaces between).
|
||||||
|
You may have to recreate the container on Docker to re-enable the disabled cogs.
|
||||||
|
|
||||||
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*
|
||||||
|
|
||||||
|
|
13
src/main.py
13
src/main.py
|
@ -1,17 +1,26 @@
|
||||||
print("Chargement des extensions & librairie...", end = " ")
|
print("Chargement des extensions & librairie...", end = " ")
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from os import listdir
|
from os import listdir, rename, getcwd
|
||||||
from discord_slash import SlashCommand
|
from discord_slash import SlashCommand
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from utils.reminder import Reminder
|
from utils.reminder import Reminder
|
||||||
from utils.core import load
|
from utils.core import load
|
||||||
keys = load(["PREFIX", "TOKEN_DISCORD"])
|
keys = load(["PREFIX", "TOKEN_DISCORD", "DEACTIVATION"])
|
||||||
customPrefix = keys["PREFIX"]
|
customPrefix = keys["PREFIX"]
|
||||||
|
|
||||||
client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all())
|
client = commands.Bot(command_prefix = customPrefix, case_insensitive = True, intents = discord.Intents.all())
|
||||||
slash = SlashCommand(client, sync_commands = True)
|
slash = SlashCommand(client, sync_commands = True)
|
||||||
|
|
||||||
|
if keys["DEACTIVATION"] != "None":
|
||||||
|
path = getcwd()
|
||||||
|
for file in keys["DEACTIVATION"]:
|
||||||
|
try:
|
||||||
|
rename(f"{path}/cogs/{file}.py", f"{path}/cogs/-{file}.py") # désactivation
|
||||||
|
except:
|
||||||
|
print(f"\nNo file {file} found, check your \"DEACTIVATION\" variable.")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
for file in listdir("cogs"):
|
for file in listdir("cogs"):
|
||||||
if file.endswith(".py") and file.startswith("-") == False:
|
if file.endswith(".py") and file.startswith("-") == False:
|
||||||
client.load_extension(f"cogs.{file[:-3]}")
|
client.load_extension(f"cogs.{file[:-3]}")
|
||||||
|
|
|
@ -171,9 +171,15 @@ def load(variables):
|
||||||
load_dotenv() # load .env file
|
load_dotenv() # load .env file
|
||||||
for var in variables:
|
for var in variables:
|
||||||
try:
|
try:
|
||||||
keys[var] = environ[var]
|
res = environ[var]
|
||||||
|
if var == "DEACTIVATION":
|
||||||
|
res = list(set(res.split(',')) - {""}) # create a list for the cogs we need to deactivate and remove blank channels and doubles
|
||||||
|
keys[var] = res
|
||||||
except KeyError:
|
except KeyError:
|
||||||
print(f"Please set the environment variable {var} (.env file supported)")
|
if var == "DEACTIVATION":
|
||||||
exit(1)
|
keys[var] = "None"
|
||||||
|
else:
|
||||||
|
print(f"Please set the environment variable {var} (.env file supported)")
|
||||||
|
exit(1)
|
||||||
|
|
||||||
return keys
|
return keys
|
||||||
|
|
Reference in a new issue