2020-04-08 17:11:23 +02:00
|
|
|
from discord.ext import commands
|
2020-07-23 21:32:43 +02:00
|
|
|
from discord.ext.commands import CommandNotFound, MissingRequiredArgument, BadArgument, MissingPermissions, \
|
2021-02-04 10:53:26 +01:00
|
|
|
NoPrivateMessage, NotOwner
|
2021-01-06 17:02:15 +01:00
|
|
|
from discord_slash import SlashContext
|
2020-07-23 21:22:47 +02:00
|
|
|
|
2020-11-05 14:15:58 +01:00
|
|
|
from administrator.check import ExtensionDisabled
|
2020-07-23 21:22:47 +02:00
|
|
|
from administrator.logger import logger
|
2020-04-08 17:11:23 +02:00
|
|
|
|
|
|
|
|
|
|
|
extension_name = "help"
|
|
|
|
logger = logger.getChild(extension_name)
|
|
|
|
|
|
|
|
|
2020-07-23 21:22:47 +02:00
|
|
|
class Help(commands.Cog):
|
|
|
|
def __init__(self, bot: commands.Bot):
|
|
|
|
self.bot = bot
|
|
|
|
|
2020-07-23 21:34:32 +02:00
|
|
|
def description(self):
|
|
|
|
return "Give help and command list"
|
|
|
|
|
2020-07-23 21:22:47 +02:00
|
|
|
@commands.Cog.listener()
|
|
|
|
async def on_command_error(self, ctx: commands.Context, error):
|
2021-01-06 17:02:15 +01:00
|
|
|
await self.error_handler(ctx, error)
|
|
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
|
async def on_slash_command_error(self, ctx: SlashContext, error: Exception):
|
|
|
|
await self.error_handler(ctx, error)
|
|
|
|
|
2021-02-04 10:53:26 +01:00
|
|
|
async def error_handler(self, ctx, error: Exception):
|
2020-07-23 21:22:47 +02:00
|
|
|
if isinstance(error, CommandNotFound):
|
2021-02-04 10:53:26 +01:00
|
|
|
await self.reaction(ctx, "\u2753")
|
2020-07-23 21:22:47 +02:00
|
|
|
elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument):
|
2021-02-04 10:53:26 +01:00
|
|
|
await self.reaction(ctx, "\u274C")
|
2021-01-06 17:02:15 +01:00
|
|
|
elif isinstance(error, NotOwner) or isinstance(error, MissingPermissions) \
|
2020-07-23 21:32:43 +02:00
|
|
|
or isinstance(error, NoPrivateMessage):
|
2021-02-04 10:53:26 +01:00
|
|
|
await self.reaction(ctx, "\U000026D4")
|
2020-11-05 14:15:58 +01:00
|
|
|
elif isinstance(error, ExtensionDisabled):
|
2021-02-04 10:53:26 +01:00
|
|
|
await self.reaction(ctx, "\U0001F6AB")
|
2020-07-23 21:22:47 +02:00
|
|
|
else:
|
2021-01-06 17:02:15 +01:00
|
|
|
await ctx.send(content="An error occurred !")
|
2020-07-23 21:22:47 +02:00
|
|
|
raise error
|
2020-04-08 17:11:23 +02:00
|
|
|
|
2021-02-04 10:53:26 +01:00
|
|
|
@staticmethod
|
|
|
|
async def reaction(ctx, react: str):
|
|
|
|
m = getattr(ctx, "message", None)
|
|
|
|
if m:
|
|
|
|
await m.add_reaction(react)
|
|
|
|
else:
|
|
|
|
await ctx.send(content=react)
|
|
|
|
|
2020-04-08 17:11:23 +02:00
|
|
|
|
|
|
|
def setup(bot):
|
|
|
|
logger.info(f"Loading...")
|
|
|
|
try:
|
|
|
|
bot.help_command = None
|
2020-07-23 21:22:47 +02:00
|
|
|
bot.add_cog(Help(bot))
|
2020-04-08 17:11:23 +02:00
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Error loading: {e}")
|
|
|
|
else:
|
|
|
|
logger.info(f"Load successful")
|
|
|
|
|
|
|
|
|
|
|
|
def teardown(bot):
|
|
|
|
logger.info(f"Unloading...")
|
|
|
|
try:
|
2020-07-23 21:22:47 +02:00
|
|
|
bot.remove_cog("Help")
|
2020-04-08 17:11:23 +02:00
|
|
|
except Exception as e:
|
|
|
|
logger.error(f"Error unloading: {e}")
|
|
|
|
else:
|
|
|
|
logger.info(f"Unload successful")
|