Пример #1
0
    async def swap(self, ctx: Context, *args: str):
        todo_id, section_id, args = await parse_section_args(ctx, args)

        if not (todo_id and section_id):
            return

        if not args:
            return await ctx.send('Specify second section id')

        try:
            section_id_2 = int(args[0])

            with Session() as session:
                sections = get_todo_sects(session, ctx.guild.id, todo_id)
                if 1 <= section_id_2 <= len(sections):
                    section = sections[section_id - 1]
                    section_2 = sections[section_id_2 - 1]

                    section.timestamp, section_2.timestamp = section_2.timestamp, section.timestamp
                    session.commit()

                    return await update_list(ctx, todo_id)
        except ValueError:
            pass

        await ctx.send('Please input valid second section id')
Пример #2
0
    async def move(self, ctx: Context, *args: str):
        todo_id, section_id, args = await parse_section_args(ctx, args)

        if not (todo_id and section_id):
            return

        if not args:
            return await ctx.send('Specify second list id')

        todo_id_2 = args[0]

        with Session() as session:
            todo_list_2 = get_todo_list(session, ctx.guild.id, todo_id_2)
            if not todo_list_2:
                return await ctx.send('Invalid second list id')

            sections = get_todo_sects(session, ctx.guild.id, todo_id)
            section = sections[section_id - 1]

            section.todo_id = todo_id_2
            section.timestamp = func.now()

            session.commit()

        await update_list(ctx, todo_id)
        await update_list(ctx, todo_id_2)
Пример #3
0
    async def done(self, ctx: Context, *args: str):
        todo_id, section_id, args = await parse_section_args(ctx, args)

        if not (todo_id and section_id):
            return

        with Session() as session:
            sections = get_todo_sects(session, ctx.guild.id, todo_id)
            section = sections[section_id - 1]

            section.done = not section.done
            session.commit()

        await update_list(ctx, todo_id)
Пример #4
0
async def update_list(ctx: Context, todo_id: str) -> None:
    with Session() as session:
        todo_list = get_todo_list(session, ctx.guild.id, todo_id)
        sections = get_todo_sects(session, ctx.guild.id, todo_id)

    if not todo_list:
        return

    msg = await fetch_message(ctx, todo_list.msg_id)

    if not msg:
        return

    embed = create_todo_embed(todo_list, sections)
    await msg.edit(embed=embed)
Пример #5
0
    async def content(self, ctx: Context, *args: str):
        todo_id, section_id, args = await parse_section_args(ctx, args)

        if not (todo_id and section_id):
            return

        value = ' '.join(args).replace('\\n', '\n')
        if value == '':
            value = 'Title'

        with Session() as session:
            sections = get_todo_sects(session, ctx.guild.id, todo_id)
            section = sections[section_id - 1]

            section.content = value
            session.commit()

        await update_list(ctx, todo_id)
Пример #6
0
    async def title(self, ctx: Context, *args: str):
        todo_id, section_id, args = await parse_section_args(ctx, args)

        if not (todo_id and section_id):
            return

        title = ' '.join(args)
        if title == '':
            title = 'Title'

        with Session() as session:
            sections = get_todo_sects(session, ctx.guild.id, todo_id)
            section = sections[section_id - 1]

            section.title = title

            session.commit()

        await update_list(ctx, todo_id)
Пример #7
0
    async def recreate(self, ctx: Context, *args: str):
        todo_id, sink = await parse_todo_args(ctx, args)

        if not todo_id:
            return

        with Session() as session:
            res = get_todo_list(session, ctx.guild.id, todo_id)

            msg = await fetch_message(ctx, res.msg_id)
            if msg:
                await msg.delete()

            sections = get_todo_sects(session, ctx.guild.id, todo_id)

            embed = create_todo_embed(res, sections)
            new_msg = await ctx.send(embed=embed)

            res.msg_id = new_msg.id
            session.commit()