1
0
mirror of https://gitlab.com/ddorn/tfjm-discord-bot.git synced 2024-11-26 10:47:09 +00:00

shortcut to reload constants + reload fallback to load

This commit is contained in:
ddorn 2020-05-04 16:18:09 +02:00
parent 7dd6ed2273
commit 184596870b

View File

@ -1,10 +1,9 @@
import asyncio import asyncio
import code
from pprint import pprint from pprint import pprint
import discord import discord
from discord import TextChannel, PermissionOverwrite from discord import TextChannel, PermissionOverwrite
from discord.ext.commands import command, has_role, Bot, Cog from discord.ext.commands import command, has_role, Bot, Cog, ExtensionNotLoaded
from discord.utils import get from discord.utils import get
from ptpython.repl import embed from ptpython.repl import embed
@ -12,6 +11,7 @@ from src.constants import *
from src.core import CustomBot from src.core import CustomBot
COGS_SHORTCUTS = { COGS_SHORTCUTS = {
"c": "src.constants",
"d": "tirages", "d": "tirages",
"e": "errors", "e": "errors",
"m": "misc", "m": "misc",
@ -20,8 +20,6 @@ COGS_SHORTCUTS = {
"v": "dev", "v": "dev",
} }
KeyboardInterrupt
class DevCog(Cog, name="Dev tools"): class DevCog(Cog, name="Dev tools"):
def __init__(self, bot: CustomBot): def __init__(self, bot: CustomBot):
@ -86,19 +84,18 @@ class DevCog(Cog, name="Dev tools"):
await ctx.send(":tada: The bot was reloaded !") await ctx.send(":tada: The bot was reloaded !")
return return
names = [name] if name else list(COGS_SHORTCUTS.values()) name = self.full_cog_name(name)
for name in names: try:
self.bot.reload_extension(name)
name = self.full_cog_name(name) except ExtensionNotLoaded:
await ctx.invoke(self.load_cmd, name)
try: return
self.bot.reload_extension(name) except:
except: await ctx.send(f":grimacing: **{name}** n'a pas pu être rechargée.")
await ctx.send(f":grimacing: **{name}** n'a pas pu être rechargée.") raise
raise else:
else: await ctx.send(f":tada: L'extension **{name}** a bien été rechargée.")
await ctx.send(f":tada: L'extension **{name}** a bien été rechargée.")
@command(name="load", aliases=["l"]) @command(name="load", aliases=["l"])
@has_role(Role.DEV) @has_role(Role.DEV)