summaryrefslogtreecommitdiff
path: root/cogs/Help.py
blob: 2a797841f6fb9e7647fff46ed298384e6e32f151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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]")