Exemplo n.º 1
0
async def getHelp(ctx, cmd):
    """Gets the help embed for a command."""
    wikiMods = discord.utils.get(ctx.message.author.guild.roles,
                                 name="Wiki Moderator")
    cmdInfo = next(
        (c for c in COMMAND_INFO if c["name"] == cmd or cmd in c["aliases"]),
        None)
    if cmdInfo == None:
        return assembleEmbed(
            title=f"`{cmd}`",
            desc="Cannot find command with this name. Try again buddy.",
            webcolor="red")
    else:
        roles = [(discord.utils.get(ctx.message.author.guild.roles, name=r))
                 for r in cmdInfo['access']]
        commandFields = [{
            "name":
            "Parameters",
            "value":
            "\n".join([
                f"`{p['name']}` - {p['description']}"
                for p in cmdInfo['parameters']
            ]) if len(cmdInfo['parameters']) > 0 else "`none`",
            "inline":
            False
        }]
        # If command has flags show those, if not do nothing
        if 'flags' in cmdInfo:
            commandFields.append({
                "name":
                "Flags",
                "value":
                "\n".join([
                    f"`-{u['name']}` - {u['description']}"
                    for u in cmdInfo['flags']
                ]),
                "inline":
                False
            })
        # Add available roles
        commandFields.extend([{
            "name":
            "Usage",
            "value":
            "\n".join(
                [f"`{u['cmd']}` - {u['result']}" for u in cmdInfo['usage']]),
            "inline":
            False
        }, {
            "name":
            "Available To",
            "value":
            "\n".join([f"{r.mention}" for r in roles]),
            "inline":
            False
        }])
        return assembleEmbed(title=f"`!{cmdInfo['name']}`",
                             desc=f"{cmdInfo['description']}",
                             fields=commandFields,
                             webcolor="gold")
Exemplo n.º 2
0
async def cembed(ctx, *, jsonInput):
    """Helps to create an embed to be sent to a channel."""
    jso = json.loads(jsonInput)
    title = jso['title'] if 'title' in jso else ""
    desc = jso['description'] if 'description' in jso else ""
    titleUrl = jso['titleUrl'] if 'titleUrl' in jso else ""
    hexcolor = jso['hexColor'] if 'hexColor' in jso else "#C7B1A3"
    webcolor = jso['webColor'] if 'webColor' in jso else ""
    thumbnailUrl = jso['thumbnailUrl'] if 'thumbnailUrl' in jso else ""
    authorName = jso['authorName'] if 'authorName' in jso else ""
    authorUrl = jso['authorUrl'] if 'authorUrl' in jso else ""
    authorIcon = jso['authorIcon'] if 'authorIcon' in jso else ""
    if 'author' in jso:
        authorName = ctx.message.author.name
        authorIcon = ctx.message.author.avatar_url_as(format="jpg")
    fields = jso['fields'] if 'fields' in jso else ""
    footerText = jso['footerText'] if 'footerText' in jso else ""
    footerUrl = jso['footerUrl'] if 'footerUrl' in jso else ""
    imageUrl = jso['imageUrl'] if 'imageUrl' in jso else ""

    embed = assembleEmbed(title=title,
                          desc=desc,
                          titleUrl=titleUrl,
                          hexcolor=hexcolor,
                          webcolor=webcolor,
                          thumbnailUrl=thumbnailUrl,
                          authorName=authorName,
                          authorUrl=authorUrl,
                          authorIcon=authorIcon,
                          fields=fields,
                          footerText=footerText,
                          footerUrl=footerUrl,
                          imageUrl=imageUrl)
    await ctx.send(embed=embed)
Exemplo n.º 3
0
async def getList(ctx):
    """Gets the list of commands a user can access."""
    availableCommands = await _generateList(ctx.message.author, False)
    return assembleEmbed(
        title=f"Full List of Available Commands for {ctx.message.author}",
        desc="\n".join([
            f"`{c['name']}` - {c['description']}" for c in availableCommands
        ]))
Exemplo n.º 4
0
async def getList(author, page):
    """Gets the list of commands a user can access."""
    availableCommands = await _generateList(author, False)
    availableCommands.sort(key=lambda x: x['name'])
    totalPages = math.floor(len(availableCommands) / 10) + 1
    if page == 100:
        page = totalPages
    if page > totalPages or page < 1:
        return False
    availableCommands = availableCommands[(page - 1) * 10:(page) * 10]
    return assembleEmbed(
        title=f"List of Commands for `{author}` (Page {page}/{totalPages})",
        desc="\n".join([
            f"`{c['name']}` - {c['description']}" for c in availableCommands
        ]))
Exemplo n.º 5
0
async def getQuickList(ctx):
    """Gets the quick list of commands a user can access."""
    availableCommands = await _generateList(ctx.message.author, True)
    return assembleEmbed(
        title=f"Quick List of Available Commands for {ctx.message.author}",
        desc="To view full list, please type `!list all`.",
        fields=[{
            "name":
            "Commands",
            "value":
            "\n".join([
                f"`{c['name']}` - {c['description']}"
                for c in availableCommands
            ]),
            "inline":
            False
        }])