From 52801b4de1d63cd01191acf7fcee137977140ec0 Mon Sep 17 00:00:00 2001 From: lexicade Date: Fri, 27 Jan 2023 21:06:30 +0000 Subject: Project init --- cogs/Help.py | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 cogs/Help.py (limited to 'cogs/Help.py') diff --git a/cogs/Help.py b/cogs/Help.py new file mode 100644 index 0000000..2a79784 --- /dev/null +++ b/cogs/Help.py @@ -0,0 +1,61 @@ +from discord.ext import commands +import discord +import importlib +import utils +import itertools +import math +importlib.reload(utils) + + +class Help(commands.Cog): + def __init__(self, bot): + self.bot = bot + "https://api.openweathermap.org/data/2.5/weather?q=jersey&appid=d83a0ac0ba2d9d59007724f54bd4f960" + + @commands.command(usage="!help", aliases=['commands'], application_command_meta=commands.ApplicationCommandMeta(options=[])) + async def help(self, ctx): + """Shows this help message.""" + str_cmds = "" + cmds = {} + + # Reorder list + cmds_set = self.bot.commands + + for cmd in cmds_set: + if not cmd.hidden: + cmds[cmd.name] = {"help": cmd.help} + + cmds = dict(sorted(cmds.items(), key=lambda x: x[0].lower())) + await pagify(self, cmds, 5, 2) + for cmd in cmds: + str_cmds = f"{str_cmds}\n•**{cmd}** - {cmds[cmd]['help']}" + + emb = await utils.embed(ctx, "Help commands", str_cmds) + await ctx.send(embed=emb) + + +async def pagify(self, input, items_per_page, page_wanted=1): + total_items = len(input) + # total items = 25 + pages = 1 + + if total_items > items_per_page: + pages = int(math.floor(total_items / items_per_page)) + + return_list = [] + for i, item in enumerate(input): + if int(math.floor(i / pages)) == page_wanted: + return_list.append({item: input[item]["help"]}) + + print(return_list) + return return_list + + +def setup(bot): + print("INFO: Loading [Help]... ", end="") + bot.add_cog(Help(bot)) + print("Done!") + + +def teardown(bot): + print("INFO: Unloading [Help]") -- cgit v1.2.3