Ejemplo n.º 1
0
async def vision(ctx: MrvnCommandContext, image: Option(Attachment)):
    if not image.content_type.startswith("image"):
        await ctx.respond_embed(
            Style.ERROR,
            ctx.translate("vision_command_vision_invalid_content_type"))

        return

    await ctx.defer()

    session = aiohttp.ClientSession(timeout=ClientTimeout(20))

    try:
        response = await session.post(
            SERVICE_URL,
            data="userlink=%s" % parse.quote(image.url, safe=''),
            headers={
                "Cookie": "textonly=true; imageonly=true; qronly=false",
                "Content-Type": "application/x-www-form-urlencoded"
            })
    except (aiohttp.ClientConnectionError, asyncio.TimeoutError):
        await ctx.respond_embed(
            Style.ERROR,
            ctx.translate("vision_command_vision_connection_error"))

        return
    finally:
        await session.close()

    text = await response.text()

    response.close()

    soup = BeautifulSoup(text, "html.parser")
    results = soup.find_all("div", {"class": "success description"})

    if not len(results):
        await ctx.respond_embed(Style.ERROR,
                                ctx.translate("vision_command_vision_fail"))
        return

    embed = ctx.get_embed(Style.INFO, results[0].text,
                          ctx.translate("vision_command_vision_title"))
    embed.set_image(url=image.url)

    await ctx.respond(embed=embed)
Ejemplo n.º 2
0
async def commands(ctx: MrvnCommandContext):
    await ctx.defer()

    command_entries = sorted(await StatsCommandEntry.filter(guild_id=ctx.guild_id), key=lambda k: k.count,
                             reverse=True)[:10]
    command_stats = "\n".join([f"**{x.command_name}** - `{x.count}`" for x in command_entries])

    user_entries = sorted(await StatsUserCommandsEntry.filter(guild_id=ctx.guild_id), key=lambda k: k.count,
                          reverse=True)[:10]
    user_stats = "\n".join([f"{get_user_mention(x.user_id)} - `{x.count}`" for x in user_entries])

    embed = ctx.get_embed(Style.INFO, title=ctx.translate("statistics_command_commands_title"))
    embed.description = f"""
{ctx.translate("statistics_command_commands_command_top")}
{command_stats}
{ctx.translate("statistics_command_commands_user_top")}
{user_stats}
"""

    await ctx.respond(embed=embed)
Ejemplo n.º 3
0
async def info(ctx: MrvnCommandContext):
    embed = ctx.get_embed(Style.INFO,
                          title=ctx.translate("std_command_info_title"))

    embed.add_field(name=ctx.translate("std_command_info_version"),
                    value=f"`{current_version}`",
                    inline=False)
    embed.add_field(name=ctx.translate("std_command_info_extensions"),
                    value=", ".join([
                        f"**{x}**"
                        for x in extension_manager.extensions.keys()
                    ]),
                    inline=False)
    embed.add_field(name=ctx.translate("std_command_info_commands"),
                    value=f"**{len(runtime.bot.unique_app_commands)}**",
                    inline=False)
    # Still hardcoding author names in 2022 kek
    embed.add_field(name=ctx.translate("std_command_info_authors"),
                    value="**Iterator, HeroBrine1st**",
                    inline=False)

    await ctx.respond(embed=embed)
Ejemplo n.º 4
0
async def man(ctx: MrvnCommandContext, cmd_name: ParseUntilEndsOption(str)):
    cmd_split = iter(cmd_name.split())

    name = next(cmd_split)

    for cmd in runtime.bot.application_commands:
        if isinstance(cmd, (SlashCommand, SlashCommandGroup)
                      ) and cmd.name == name and ctx.guild_id in cmd.guild_ids:
            command = cmd
            break
    else:
        await ctx.respond_embed(
            Style.ERROR, ctx.translate("std_command_help_command_not_found"))

        return

    root = command

    try:
        while isinstance(command, SlashCommandGroup):
            sub_cmd_name = next(cmd_split)

            command = next(
                filter(lambda it: it.name == sub_cmd_name,
                       command.subcommands))
    except StopIteration:
        await ctx.respond_embed(
            Style.INFO, runtime.bot.get_command_desc(root, ctx, as_tree=True))

        return

    embed = ctx.get_embed(Style.INFO)

    embed.add_field(name=runtime.bot.get_command_desc(command, ctx),
                    value=command.description)

    await ctx.respond(embed=embed)