示例#1
0
 async def template_check_pixelplanet(self, ctx):
     ts = [
         x for x in sql.template_get_all_by_guild_id(ctx.guild.id)
         if x.canvas == 'pixelplanet'
     ]
     if len(ts) <= 0:
         ctx.command.parent.reset_cooldown(ctx)
         raise NoTemplatesError(True)
     ts = sorted(ts, key=lambda tx: tx.name)
     msg = await _check_canvas(ctx, ts, "pixelplanet")
     await msg.delete()
     await _build_template_report(ctx, ts)
示例#2
0
    async def template(self, ctx, *args):
        gid = ctx.guild.id
        iter_args = iter(args)
        page = next(iter_args, 1)
        if page == "-f":
            fac = next(iter_args, None)
            if fac is None:
                await ctx.send(ctx.s("error.missing_arg_faction"))
                return
            faction = sql.guild_get_by_faction_name_or_alias(fac)
            if not faction:
                raise FactionNotFoundError
            gid = faction.id
            page = next(iter_args, 1)
        try:
            page = int(page)
        except ValueError:
            page = 1

        ts = sql.template_get_all_by_guild_id(gid)
        if len(ts) < 1:
            raise NoTemplatesError()

        pages = 1 + len(ts) // 10
        page = min(max(page, 1), pages)
        w1 = max(
            max(map(lambda tx: len(tx.name), ts)) + 2, len(ctx.s("bot.name")))
        msg = [
            "**{}** - {} {}/{}".format(ctx.s("template.list_header"),
                                       ctx.s("bot.page"), page, pages),
            "```xl", "{0:<{w1}}  {1:<14}  {2}".format(ctx.s("bot.name"),
                                                      ctx.s("bot.canvas"),
                                                      ctx.s("bot.coordinates"),
                                                      w1=w1)
        ]
        for t in ts[(page - 1) * 10:page * 10]:
            coords = "({}, {})".format(t.x, t.y)
            name = '"{}"'.format(t.name)
            canvas_name = canvases.pretty_print[t.canvas]
            msg.append("{0:<{w1}}  {1:<14}  {2}".format(name,
                                                        canvas_name,
                                                        coords,
                                                        w1=w1))
        msg.append("")
        msg.append("// " + ctx.s("template.list_footer_1").format(ctx.gprefix))
        msg.append("// " + ctx.s("template.list_footer_2").format(ctx.gprefix))
        msg.append("```")
        await ctx.send('\n'.join(msg))
示例#3
0
    async def template_check(self, ctx):
        if not ctx.invoked_subcommand or ctx.invoked_subcommand.name == "check":
            ts = sql.template_get_all_by_guild_id(ctx.guild.id)

            if len(ts) < 1:
                ctx.command.parent.reset_cooldown(ctx)
                raise NoTemplatesError(False)

            msg = None
            ts = sorted(ts, key=lambda tx: tx.name)
            ts = sorted(ts, key=lambda tx: tx.canvas)
            for canvas, canvas_ts in itertools.groupby(ts,
                                                       lambda tx: tx.canvas):
                ct = list(canvas_ts)
                msg = await _check_canvas(ctx, ct, canvas, msg=msg)

            await msg.delete()
            await _build_template_report(ctx, ts)
 def __init__(self, gid, template_name):
     templates = sql.template_get_all_by_guild_id(gid)
     self.matches = [f"`{t.name}`" for t in templates if fuzz.partial_ratio(t.name, template_name) >= 70]
    async def template(self, ctx, *args):
        # Argument Parsing
        parser = GlimmerArgumentParser(ctx)
        parser.add_argument("-p", "--page", type=int, default=1)
        parser.add_argument("-f",
                            "--faction",
                            default=None,
                            action=FactionAction)
        try:
            args = vars(parser.parse_args(args))
        except TypeError:
            return

        page = args["page"]
        faction = args["faction"]

        gid = ctx.guild.id
        if faction != None:
            gid = faction.id

        templates = sql.template_get_all_by_guild_id(gid)
        if len(templates) < 1:
            raise NoTemplatesError()

        # Find number of pages given there are 25 templates per page.
        pages = int(math.ceil(len(templates) / 25))
        # Makes sure page is in the range (1 <= page <= pages).
        page = min(max(page, 0), pages)
        page_index = page - 1

        embed = Template.build_table(ctx, page_index, pages, templates)
        message = await ctx.send(embed=embed)
        await message.add_reaction('◀')
        await message.add_reaction('▶')

        def is_valid(reaction, user):
            return reaction.message.id == message.id and (
                reaction.emoji == '◀'
                or reaction.emoji == '▶') and user.id != discord.ClientUser.id

        _5_minutes_in_future = (datetime.datetime.today() +
                                datetime.timedelta(minutes=5.0))
        try:
            while _5_minutes_in_future > datetime.datetime.today():
                add_future = asyncio.ensure_future(
                    self.bot.wait_for("reaction_add",
                                      timeout=300.0,
                                      check=is_valid))
                remove_future = asyncio.ensure_future(
                    self.bot.wait_for("reaction_remove",
                                      timeout=300.0,
                                      check=is_valid))
                reaction, _user = None, None
                while True:
                    if remove_future.done() == True:
                        reaction, _user = remove_future.result()
                        break
                    if add_future.done() == True:
                        reaction, _user = add_future.result()
                        break
                    await asyncio.sleep(0.1)

                if reaction.emoji == '◀':
                    if page_index != 0:
                        #not on first page, scroll left
                        page_index -= 1
                        embed = Template.build_table(ctx, page_index, pages,
                                                     templates)
                        await message.edit(embed=embed)
                elif reaction.emoji == '▶':
                    if page_index != pages - 1:
                        #not on last page, scroll right
                        page_index += 1
                        embed = Template.build_table(ctx, page_index, pages,
                                                     templates)
                        await message.edit(embed=embed)
        except asyncio.TimeoutError:
            pass
        await message.edit(content=ctx.s("bot.timeout"), embed=embed)
示例#6
0
    async def check(self, ctx, *args):

        # Argument Parsing
        parser = GlimmerArgumentParser(ctx)
        parser.add_argument("-e", "--onlyErrors", action='store_true')
        parser.add_argument("-f",
                            "--faction",
                            default=None,
                            action=FactionAction)
        parser.add_argument("-s",
                            "--sort",
                            default="name_az",
                            choices=[
                                "name_az", "name_za", "errors_az", "errors_za",
                                "percent_az", "percent_za"
                            ])
        try:
            a = vars(parser.parse_args(args))
        except TypeError:
            return

        only_errors = a["onlyErrors"]
        faction = a["faction"]
        sort = a["sort"]

        if faction:
            templates = sql.template_get_all_by_guild_id(faction.id)
        else:
            templates = sql.template_get_all_by_guild_id(ctx.guild.id)

        if len(templates) < 1:
            ctx.command.parent.reset_cooldown(ctx)
            raise NoTemplatesError(False)

        msg = None

        # Calc info + send temp msg
        for canvas, canvas_ts in itertools.groupby(templates,
                                                   lambda tx: tx.canvas):
            ct = list(canvas_ts)
            msg = await check_canvas(ctx, ct, canvas, msg=msg)

        # Delete temp msg and send final report
        await msg.delete()

        ts = [t for t in templates
              if t.errors != 0] if only_errors else templates

        if sort == "name_az" or sort == "name_za":
            ts = sorted(ts, key=lambda t: t.name, reverse=(sort == "name_za"))
        elif sort == "errors_az" or sort == "errors_za":
            ts = sorted(ts,
                        key=lambda t: t.errors,
                        reverse=(sort == "errors_za"))
        elif sort == "percent_az" or sort == "percent_za":
            ts = sorted(ts,
                        key=lambda t: (t.size - t.errors) / t.size,
                        reverse=(sort == "percent_za"))

        ts = sorted(ts, key=lambda t: t.canvas)

        # Find number of pages given there are 25 templates per page.
        pages = int(math.ceil(len(ts) / 25))
        await build_template_report(ctx, ts, None, pages)