2020-07-23 21:30:42 +02:00
|
|
|
from discord import Embed
|
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, \
|
2020-11-01 18:35:53 +01:00
|
|
|
NoPrivateMessage, CommandError, NotOwner
|
2020-07-23 21:22:47 +02:00
|
|
|
|
2020-07-23 21:30:42 +02:00
|
|
|
from administrator import config
|
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.command("help", pass_context=True)
|
|
|
|
async def help(self, ctx: commands.Context):
|
2020-07-23 21:30:42 +02:00
|
|
|
embed = Embed(title="Help")
|
2020-07-23 21:34:32 +02:00
|
|
|
|
|
|
|
for c in filter(lambda x: x != "Help", self.bot.cogs):
|
|
|
|
cog = self.bot.cogs[c]
|
|
|
|
try:
|
|
|
|
if await getattr(cog, c.lower()).can_run(ctx):
|
|
|
|
embed.add_field(name=c,
|
|
|
|
value=cog.description() + "\n" +
|
|
|
|
f"`{config.get('prefix')}{c.lower()} help` for more information",
|
|
|
|
inline=False)
|
|
|
|
except CommandError:
|
|
|
|
pass
|
|
|
|
|
2020-07-23 21:30:42 +02:00
|
|
|
await ctx.send(embed=embed)
|
2020-07-23 21:22:47 +02:00
|
|
|
|
|
|
|
@commands.Cog.listener()
|
|
|
|
async def on_command_error(self, ctx: commands.Context, error):
|
|
|
|
if isinstance(error, CommandNotFound):
|
|
|
|
await ctx.message.add_reaction("\u2753")
|
|
|
|
elif isinstance(error, MissingRequiredArgument) or isinstance(error, BadArgument):
|
|
|
|
await ctx.message.add_reaction("\u274C")
|
2020-07-23 21:32:43 +02:00
|
|
|
elif isinstance(error, NotOwner) or isinstance(error, MissingPermissions)\
|
|
|
|
or isinstance(error, NoPrivateMessage):
|
2020-11-05 14:15:58 +01:00
|
|
|
await ctx.message.add_reaction("\U000026D4")
|
|
|
|
elif isinstance(error, ExtensionDisabled):
|
|
|
|
await ctx.message.add_reaction("\U0001F6AB")
|
2020-07-23 21:22:47 +02:00
|
|
|
else:
|
|
|
|
await ctx.send("An error occurred !")
|
|
|
|
raise error
|
|
|
|
await ctx.message.delete(delay=30)
|
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")
|