<commit_before>from botstory.middlewares import option, text
import emoji
import logging
import re

from todo import orm
from todo.tasks import task_story_helper

logger = logging.getLogger(__name__)


def singular_vs_plural(singular):
    return ' was' if singular else 's were'


def setup(story):
    async def open_one_task(ctx, task):
        if task.state == 'open':
            await story.ask(
                'Task `{}` is already opened'.format(task.description),
                quick_replies=[{
                    'title': 'start',
                    'payload': 'START_TASK_{}'.format(task._id),
                }, {
                    'title': 'details',
                    'payload': 'TASK_DETAILS_{}'.format(task._id),
                }, {
                    'title': 'list tasks',
                    'payload': 'LIST_TASKS_NEW_FIRST',
                }, ],
                user=ctx['user'])
            return
        task.state = 'open'
        await task.save()
        await story.ask(
            emoji.emojize(':ok: Task `{}` was opened', use_aliases=True).format(task.description),
            quick_replies=[{
                'title': 'start',
                'payload': 'START_TASK_{}'.format(task._id),
            }, {
                'title': 'details',
                'payload': 'TASK_DETAILS_{}'.format(task._id),
            }, {
                'title': 'list tasks',
                'payload': 'LIST_TASKS_NEW_FIRST',
            }, ],
            user=ctx['user'])

    async def open_many_task(ctx, tasks):
        modified_descriptions = []
        for task in tasks:
            if task.state == 'done':
                task.state = 'open'
                await task.save()
                modified_descriptions.append(task.description)

        if len(modified_descriptions) == 0:
            await story.ask('There is no task to open',
                            quick_replies=[{
                                'title': 'add new task',
                                'payload': 'ADD_NEW_TASK',
                            }, {
                                'title': 'list tasks',
                                'payload': 'LIST_TASKS_NEW_FIRST',
                            },
                            ],
                            user=ctx['user'])
            return

        modified_descriptions_list = '\n'.join(
            [emoji.emojize(':white_check_mark: {}', use_aliases=True).format(t) for t in modified_descriptions])

        await story.ask(
            emoji.emojize(':ok: Task{} opened:\n{}', use_aliases=True).format(
                singular_vs_plural(len(modified_descriptions) == 1),
                modified_descriptions_list),
            quick_replies=[{
                'title': 'start all',
                'payload': 'START_ALL_TASKS',
            }, {
                'title': 'list tasks',
                'payload': 'LIST_TASKS_NEW_FIRST',
            },
            ],
            user=ctx['user'])

    async def start_one_task(ctx, task):
        if task.state == 'in progress':
            await story.ask(
                'Task `{}` is already in progress'.format(task.description),
                quick_replies=[{
                    'title': 'stop',
                    'payload': 'DONE_TASK_{}'.format(task._id),
                }, {
                    'title': 'done',
                    'payload': 'DONE_TASK_{}'.format(task._id),
                }, {
                    'title': 'details',<commit_msg>remove duplicate quick replay<commit_after>from botstory.middlewares import option, text
import emoji
import logging
import re

from todo import orm
from todo.tasks import task_story_helper

logger = logging.getLogger(__name__)


def singular_vs_plural(singular):
    return ' was' if singular else 's were'


def setup(story):
    async def open_one_task(ctx, task):
        if task.state == 'open':
            await story.ask(
                'Task `{}` is already opened'.format(task.description),
                quick_replies=[{
                    'title': 'start',
                    'payload': 'START_TASK_{}'.format(task._id),
                }, {
                    'title': 'details',
                    'payload': 'TASK_DETAILS_{}'.format(task._id),
                }, {
                    'title': 'list tasks',
                    'payload': 'LIST_TASKS_NEW_FIRST',
                }, ],
                user=ctx['user'])
            return
        task.state = 'open'
        await task.save()
        await story.ask(
            emoji.emojize(':ok: Task `{}` was opened', use_aliases=True).format(task.description),
            quick_replies=[{
                'title': 'start',
                'payload': 'START_TASK_{}'.format(task._id),
            }, {
                'title': 'details',
                'payload': 'TASK_DETAILS_{}'.format(task._id),
            }, {
                'title': 'list tasks',
                'payload': 'LIST_TASKS_NEW_FIRST',
            }, ],
            user=ctx['user'])

    async def open_many_task(ctx, tasks):
        modified_descriptions = []
        for task in tasks:
            if task.state == 'done':
                task.state = 'open'
                await task.save()
                modified_descriptions.append(task.description)

        if len(modified_descriptions) == 0:
            await story.ask('There is no task to open',
                            quick_replies=[{
                                'title': 'add new task',
                                'payload': 'ADD_NEW_TASK',
                            }, {
                                'title': 'list tasks',
                                'payload': 'LIST_TASKS_NEW_FIRST',
                            },
                            ],
                            user=ctx['user'])
            return

        modified_descriptions_list = '\n'.join(
            [emoji.emojize(':white_check_mark: {}', use_aliases=True).format(t) for t in modified_descriptions])

        await story.ask(
            emoji.emojize(':ok: Task{} opened:\n{}', use_aliases=True).format(
                singular_vs_plural(len(modified_descriptions) == 1),
                modified_descriptions_list),
            quick_replies=[{
                'title': 'start all',
                'payload': 'START_ALL_TASKS',
            }, {
                'title': 'list tasks',
                'payload': 'LIST_TASKS_NEW_FIRST',
            },
            ],
            user=ctx['user'])

    async def start_one_task(ctx, task):
        if task.state == 'in progress':
            await story.ask(
                'Task `{}` is already in progress'.format(task.description),
                quick_replies=[{
                    'title': 'done',
                    'payload': 'DONE_TASK_{}'.format(task._id),
                }, {
                    'title': 'details',
{'fraction_non_alphanumeric': 0.12572505800464037, 'fraction_numerical': 0.000580046403712297, 'mean_word_length': 1.3652263374485596, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7567575', 'n_tokens_mistral': 1910, 'n_tokens_neox': 1825, 'n_words': 364}