Example #1
0
async def autoscan(ctx):
    if ctx.guild and not sql.guild_is_autoscan(ctx.guild.id):
        return

    canvas = sql.guild_get_canvas_by_id(
        ctx.guild.id) if ctx.guild else "pixelcanvas"

    cmd = None
    view = ""
    m_pc = re.search('pixelcanvas\.io/@(-?\d+),(-?\d+)(?:(?: |#| #)(-?\d+))?',
                     ctx.message.content)
    m_pzi = re.search('pixelz\.io/@(-?\d+),(-?\d+)(?:(?: |#| #)(-?\d+))?',
                      ctx.message.content)
    m_pz = re.search(
        'pixelzone\.io/\?p=(-?\d+),(-?\d+)(?:,(\d+))?(?:(?: |#| #)(-?\d+))?',
        ctx.message.content)
    m_ps = re.search(
        'pxls\.space/#x=(\d+)&y=(\d+)(?:&scale=(\d+))?(?:(?: |#| #)(-?\d+))?',
        ctx.message.content)
    m_pre_def = re.search('@(-?\d+)(?: |,|, )(-?\d+)(?:(?: |#| #)(-?\d+))?',
                          ctx.message.content)
    m_dif_def = re.search(
        '(?:(-l) )?(-?\d+)(?: |,|, )(-?\d+)(?:(?: |#| #)(-?\d+))?',
        ctx.message.content)
    if m_pc:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands,
                   name='pixelcanvas')
        view = ' '.join(m_pc.groups(default='1'))
    elif m_pzi:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands,
                   name='pixelzio')
        view = ' '.join(m_pzi.groups(default='1'))
    elif m_pz:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands,
                   name='pixelzone')
        view = '{} {} {}'.format(m_pz.group(1), m_pz.group(2),
                                 m_pz.group(4) or m_pz.group(3) or '1')
    elif m_ps:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands,
                   name='pxlsspace')
        view = '{} {} {}'.format(m_ps.group(1), m_ps.group(2),
                                 m_ps.group(4) or m_ps.group(3) or '1')
    elif m_pre_def:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands,
                   name=canvas)
        view = ' '.join(m_pre_def.groups(default='1'))
    elif m_dif_def and len(
            ctx.message.attachments
    ) > 0 and ctx.message.attachments[0].filename[-4:].lower() == ".png":
        cmd = dget(dget(ctx.bot.commands, name='diff').commands, name=canvas)
        view = '{} {} {} {}'.format(
            m_dif_def.group(1) or "", m_dif_def.group(2), m_dif_def.group(3),
            m_dif_def.group(4) or 1)

    if cmd:
        ctx.command = cmd
        ctx.view = StringView(view)
        ctx.is_autoscan = True
        await ctx.bot.invoke(ctx)
        return True
async def autoscan(ctx):
    if ctx.guild and not sql.guild_is_autoscan(ctx.guild.id):
        return

    canvas = sql.guild_get_canvas_by_id(ctx.guild.id) if ctx.guild else "pixelcanvas"

    cmd = None
    g = None
    m_pc = re.search('pixelcanvas\.io/@(-?\d+),(-?\d+)(?:(?: |#| #)(-?\d+))?', ctx.message.content)
    m_pz = re.search('pixelzone\.io/\?p=(-?\d+),(-?\d+)(?:,(\d+))?(?:(?: |#| #)(-?\d+))?', ctx.message.content)
    m_ps = re.search('pxls\.space/#x=(\d+)&y=(\d+)(?:&scale=(\d+))?(?:(?: |#| #)(-?\d+))?', ctx.message.content)
    m_pre_def = re.search('@(-?\d+)(?: |,|, )(-?\d+)(?:(?: |#| #)(-?\d+))?', ctx.message.content)
    m_dif_def = re.search('(-?\d+)(?: |,|, )(-?\d+)(?:(?: |#| #)(-?\d+))?', ctx.message.content)
    if m_pc:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands, name='pixelcanvas')
        g = m_pc.groups()
    elif m_pz:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands, name='pixelzone')
        g = m_pz.groups()
    elif m_ps:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands, name='pxlsspace')
        g = m_ps.groups()
    elif m_pre_def:
        cmd = dget(dget(ctx.bot.commands, name='preview').commands, name=canvas)
        g = m_pre_def.groups()
    elif m_dif_def and len(ctx.message.attachments) > 0 and ctx.message.attachments[0].filename[-4:].lower() == ".png":
        cmd = dget(dget(ctx.bot.commands, name='diff').commands, name=canvas)
        g = m_dif_def.groups()

    if cmd:
        view = f"{g[0]} {g[1]} -z {g[2] if g[2] != None else 1}"
        ctx.command = cmd
        ctx.view = StringView(view)
        ctx.is_autoscan = True
        await ctx.bot.invoke(ctx)
        return True
Example #3
0
 def canvas(self):
     return sql.guild_get_canvas_by_id(self.guild.id)