2020-10-28 11:47:39 +00:00
|
|
|
import math
|
|
|
|
import discord
|
|
|
|
|
|
|
|
from discord.ext import commands
|
|
|
|
from functions import get_avatar
|
|
|
|
|
2020-12-02 21:59:01 +00:00
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
class Help(commands.Cog):
|
|
|
|
def __init__(self, bot):
|
|
|
|
self.bot = bot
|
|
|
|
self.bot.remove_command('help')
|
2020-12-02 21:59:01 +00:00
|
|
|
|
|
|
|
@commands.command(aliases=['h', '?'])
|
2020-10-28 11:47:39 +00:00
|
|
|
async def help(self, ctx, page=1):
|
|
|
|
'Displays the help command'
|
|
|
|
em = discord.Embed()
|
|
|
|
em.title = 'Help Command'
|
2020-12-02 21:36:04 +00:00
|
|
|
command_list = ''
|
|
|
|
cog_list = [c for c in self.bot.cogs.keys()]
|
2020-10-28 11:47:39 +00:00
|
|
|
page_count = math.ceil(len(cog_list) / 4)
|
2020-12-02 21:59:01 +00:00
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
page = int(page)
|
2020-12-02 21:59:01 +00:00
|
|
|
if page > page_count or page < 1:
|
2020-10-28 11:47:39 +00:00
|
|
|
await ctx.send(f'Page number \'{page}\' not found.')
|
|
|
|
return
|
2020-12-02 21:59:01 +00:00
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
cogs_needed = []
|
|
|
|
for i in range(4):
|
|
|
|
x = i + (int(page) - 1) * 4
|
|
|
|
try:
|
|
|
|
cogs_needed.append(cog_list[x])
|
|
|
|
except IndexError:
|
|
|
|
pass
|
2020-12-02 21:59:01 +00:00
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
for cog in cogs_needed:
|
|
|
|
command_list = ''
|
2020-10-30 16:02:35 +00:00
|
|
|
for command in self.bot.get_cog(cog).get_commands():
|
|
|
|
showcommand = True
|
2020-10-28 11:47:39 +00:00
|
|
|
if command.hidden:
|
2020-10-30 16:02:35 +00:00
|
|
|
showcommand = False
|
2020-10-28 11:47:39 +00:00
|
|
|
if command.parent:
|
2020-12-02 21:59:01 +00:00
|
|
|
showcommand = False
|
2020-10-30 16:02:35 +00:00
|
|
|
for check in command.checks:
|
|
|
|
try:
|
|
|
|
check(ctx)
|
|
|
|
except:
|
|
|
|
showcommand = False
|
|
|
|
if showcommand:
|
2020-12-02 21:59:01 +00:00
|
|
|
command_list += f'**{ctx.prefix}{command.name}** - {command.help}\n'
|
2020-10-30 16:02:35 +00:00
|
|
|
if command_list:
|
2020-12-02 21:59:01 +00:00
|
|
|
em.add_field(name=cog, value=command_list, inline=False)
|
|
|
|
em.set_footer(text=f'Requested by {ctx.message.author}', icon_url=get_avatar(
|
|
|
|
ctx.message.author))
|
2020-10-28 11:47:39 +00:00
|
|
|
await ctx.send(embed=em)
|
|
|
|
|
2020-12-02 21:59:01 +00:00
|
|
|
|
2020-10-28 11:47:39 +00:00
|
|
|
def setup(bot):
|
2020-10-30 16:02:35 +00:00
|
|
|
bot.add_cog(Help(bot))
|