예제 #1
0
파일: tasks.py 프로젝트: CaptainSora/phobot
async def get_dashboard(ctx, user, colors):
    tasks = sorted(
        database.get_tasks(),
        key=lambda t: datetime.strptime(t['due_date'], "%b %d, %H:%M")
    )
    embed=Embed(
        title='Task Dashboard',
        color=0x95a5a6 # default
    )
    embed.set_author(
        name=user.nick,
        icon_url=user.avatar_url
    )
    if colors:
        embed.description = colors[0][0]
        embed.color = colors[0][1]
    for t in tasks:
        assigned_to_list = t['assigned_to'].split(',')
        if f"<@{user.id}>" not in assigned_to_list:
            continue
        # Emoji formatting
        cur_time = datetime.now()
        due_time = datetime.strptime(t['due_date'], "%b %d, %H:%M")
        due_time = due_time.replace(year=cur_time.year)
        check = ' :white_check_mark:' if t['complete_date'] is not None else ''
        alert = ' :warning:' if not check and cur_time > due_time else ''
        # Embed
        embed.add_field(
            name=f"{t['task_name']} - ID:{t['task_id']}",
            value=(
                f"Due NLT {t['due_date']}{check}{alert}"
            ),
            inline=False
        )
    await ctx.send(embed=embed)
예제 #2
0
파일: tasks.py 프로젝트: CaptainSora/phobot
async def remove_task(ctx, args):
    embed=Embed(
        title='Remove Task',
        color=RED
    )
    if len(args) < 1 or not args[0].isdecimal():
        embed.description = (
            "Function usage:\n"
            "!remtask [id]\n"
            "id: the task id"
        )
        await ctx.send(embed=embed)
        return
    task_id = int(args[0])
    tasks = database.get_tasks(ext=f"WHERE task_id = {task_id}")
    if not tasks:
        embed.description = (
            f"Task id {task_id} not found."
        )
        await ctx.send(embed=embed)
        return
    database.remove_task(task_id)
    embed.color = GREEN
    embed.description = (
        f"Successfully removed task id {task_id}."
    )
    await ctx.send(embed=embed)
예제 #3
0
파일: tasks.py 프로젝트: CaptainSora/phobot
async def complete_task(ctx, args):
    user_id = ctx.author.id
    embed=Embed(
        title='Complete Task',
        color=RED
    )
    if len(args) < 1 or not args[0].isdecimal():
        embed.description = (
            "Function usage:\n"
            "!complete [id]\n"
            "id: the task id"
        )
        await ctx.send(embed=embed)
        return
    task_id = int(args[0])
    tasks = database.get_tasks(ext=f"WHERE task_id = {task_id}")
    if not tasks:
        embed.description = (
            f"Task with ID:{task_id} not found."
        )
        await ctx.send(embed=embed)
        return
    assigned_to = [int(i[2:-1]) for i in tasks[0]['assigned_to'].split(',')]
    if user_id not in assigned_to:
        embed.description = (
            f"Task with ID:{task_id} not assigned to <@{user_id}>."
        )
        await ctx.send(embed=embed)
        return
    database.complete_task(task_id)
    embed.color = GREEN
    embed.description = (
        f"Task with ID:{task_id} marked as complete."
    )
    await ctx.send(embed=embed)
예제 #4
0
파일: tasks.py 프로젝트: CaptainSora/phobot
async def get_report(ctx, user, colors):
    tasks = sorted(
        database.get_tasks(),
        key=lambda t: datetime.strptime(t['due_date'], "%b %d, %H:%M")
    )
    embed=Embed(
        title='Task Report',
        color=0x95a5a6 # default
    )
    embed.set_author(
        name=user.nick,
        icon_url=user.avatar_url
    )
    if colors:
        if colors[0][1] is None:
            embed.description = (
                f"'{colors[0][0]}' is not a valid team name.\n"
                f"Please choose one of {({', '.join(ROLES.keys())})}."
            )
            await ctx.send(embed=embed)
            return
        embed.description = colors[0][0]
        embed.color = colors[0][1]
    numfields = 0
    page = 1
    for t in tasks:
        assigned_to_list = t['assigned_to'].split(',')
        if colors[0][0] != t['task_team']:
            continue
        # Emoji formatting
        cur_time = datetime.now()
        due_time = datetime.strptime(t['due_date'], "%b %d, %H:%M")
        due_time = due_time.replace(year=cur_time.year)
        check = ' :white_check_mark:' if t['complete_date'] is not None else ''
        alert = ' :warning:' if not check and cur_time > due_time else ''
        # Embed
        embed.add_field(
            name=f"{t['task_name']} - ID:{t['task_id']}",
            value=(
                f"Assigned to {', '.join(assigned_to_list)}\n"
                f"Due NLT {t['due_date']}{check}{alert}"
            ),
            inline=False
        )
        numfields += 1
        if numfields >= 24:
            embed.set_footer(text=f"Page {page}")
            await ctx.send(embed=embed)
            embed.clear_fields()
            page += 1
            numfields = 0
    if numfields > 0:
        if page > 1:
            embed.set_footer(text=f"Page {page}")
        await ctx.send(embed=embed)
예제 #5
0
 def get(self, offset=0, count=10):
     if not session.has_key('userName') or len(session['userName']) == 0:
         resp = make_response("require login", 403)
         return resp
     data = database.get_tasks(session['userName'], offset, count)
     for item in data:
         nodes = database.get_nodes(item['keyword'])
         for node in nodes:
             node['choose'] = node['magnet'] == item['magnet']
         item['nodes'] = nodes
     return data
예제 #6
0
def create_task():
    if not request.json or 'title' not in request.json:
        abort(400)
    task = {
        'id': max([int(task.get('id')) for task in
                   database.get_tasks(CONNECTION)]) + 1,
        'title': request.json['title'],
        'description': request.json.get('description', ""),
        'status': request.json.get('status', 'False')
    }
    database.create_task(CONNECTION, task)
    return jsonify({'task': make_public_task(task)}), 201
예제 #7
0
def select_option_li(connection, existing_users):

    current_user = users.logged_in_user(connection)

    # Print the currently logged in username
    print('You are currently logged in as {}'.format(current_user))

    # Asking user for an option
    print('Select any of the following options:')
    option = input('1) {}\n2) {}\n3) {}\n'.format('Continue', 'SignOut', 'quit'))

    if option == '1':
        # Passing current user and user's tasks as arguments
        gui.display(connection, current_user, database.get_tasks(connection, current_user))
    elif option == '2':
        users.sign_out(connection, existing_users)
    elif option == '3':
        return
    else:
        print('Invalid option chosen! Please retry!\n')
        select_option_li(connection, existing_users)
예제 #8
0
파일: tasks.py 프로젝트: CaptainSora/phobot
async def change_task_due(ctx, args):
    embed=Embed(
        title='Change Task Due Date',
        color=RED
    )
    if len(args) < 2 or not args[0].isdecimal():
        embed.description = (
            "Function usage:\n"
            "!changedue [id] [due date]\n"
            "id: the task id\n"
            "due date: date + time in the format 'Jan 1, 23:30'"
        )
        await ctx.send(embed=embed)
        return
    # Param 1
    task_id = int(args[0])
    tasks = database.get_tasks(ext=f"WHERE task_id = {task_id}")
    if not tasks:
        embed.description = (
            f"Task with ID:{task_id} not found."
        )
        await ctx.send(embed=embed)
        return
    # Param 2
    due_str = ' '.join(args[1:])
    try:
        due_date = datetime.strptime(due_str, "%b %d, %H:%M")
    except ValueError:
        embed.description = (
            "Parameter 2: 'due date' must be a date and time in the format "
            "'Jan 1, 23:30'."
        )
        await ctx.send(embed=embed)
        return
    database.task_change_due(task_id, due_str)
    embed.color = GREEN
    embed.description = (
        f"Task with ID:{task_id} changed due date to {due_str}."
    )
    await ctx.send(embed=embed)
예제 #9
0
def get_tasks():
    return jsonify({'tasks': list(map(make_public_task,
                                      database.get_tasks(CONNECTION)))})