Exemplo n.º 1
0
async def display_diff(db: DatabaseManager, id_discord_server: int, username1: str, username2: str) \
        -> List[Dict[str, Optional[str]]]:
    if not await db.user_exists(id_discord_server, username1):
        tosend = f'User {username1} is not in team.'
        tosend_list = [{'user': username1, 'msg': tosend}]
        return tosend_list
    if not await db.user_exists(id_discord_server, username2):
        tosend = f'User {username2} is not in team.'
        tosend_list = [{'user': username2, 'msg': tosend}]
        return tosend_list

    database_users = await db.select_users(id_discord_server)
    user1 = db.find_user(database_users, id_discord_server, username1)
    user2 = db.find_user(database_users, id_discord_server, username2)
    solved_user1 = await get_solved_challenges(user1['rootme_user_id'])
    solved_user1 = sorted(solved_user1, key=lambda x: x['date'])  # sort challenge solved by date
    solved_user2 = await get_solved_challenges(user2['rootme_user_id'])
    solved_user2 = sorted(solved_user2, key=lambda x: x['date'])  # sort challenge solved by date

    user1_diff, user2_diff = get_diff(solved_user1, solved_user2)
    tosend_list = []

    tosend = await display_diff_one_side(user1_diff)
    tosend_list.append({'user': username1, 'msg': tosend})
    tosend = await display_diff_one_side(user2_diff)
    tosend_list.append({'user': username2, 'msg': tosend})
    return tosend_list
Exemplo n.º 2
0
async def display_diff_with(db: DatabaseManager, id_discord_server: int, bot: Bot, selected_username: str):
    if not await db.user_exists(id_discord_server, selected_username):
        tosend = f'User {selected_username} is not in team.'
        tosend_list = [{'user': selected_username, 'msg': tosend}]
        return tosend_list

    tosend_list = []
    users = await db.select_users(id_discord_server)
    selected_user = db.find_user(users, id_discord_server, selected_username)
    solved_user_select = await get_solved_challenges(selected_user['rootme_user_id'])

    for user in users:
        solved_user = await get_solved_challenges(user['rootme_user_id'])
        user_diff, user_diff_select = get_diff(solved_user, solved_user_select)
        if user_diff:
            tosend = await display_diff_one_side(user_diff)
            tosend_list.append({'user': user["rootme_username"], 'msg': tosend})
    return tosend_list
Exemplo n.º 3
0
async def display_diff_with(db: DatabaseManager, id_discord_server: int,
                            bot: Bot, selected_user: str):
    if not await db.user_exists(id_discord_server, selected_user):
        tosend = f'User {selected_user} is not in team.'
        tosend_list = [{'user': selected_user, 'msg': tosend}]
        return tosend_list

    tosend_list = []
    lang = await db.get_server_language(id_discord_server)
    users = await db.select_users(id_discord_server)
    users = [user['rootme_username'] for user in users]
    solved_user_select = await get_solved_challenges(selected_user, lang)
    for user in users:
        solved_user = await get_solved_challenges(user, lang)
        user_diff, user_diff_select = get_diff(solved_user, solved_user_select)
        if user_diff:
            tosend = display_diff_one_side(db, lang, user_diff)
            tosend_list.append({'user': user, 'msg': tosend})
    return tosend_list
Exemplo n.º 4
0
async def display_diff(db: DatabaseManager, id_discord_server: int, bot: Bot, user1: str, user2: str) \
        -> List[Dict[str, Optional[str]]]:
    if not await db.user_exists(id_discord_server, user1):
        tosend = f'User {user1} is not in team.'
        tosend_list = [{'user': user1, 'msg': tosend}]
        return tosend_list
    if not await db.user_exists(id_discord_server, user2):
        tosend = f'User {user2} is not in team.'
        tosend_list = [{'user': user2, 'msg': tosend}]
        return tosend_list

    lang = await db.get_server_language(id_discord_server)
    solved_user1 = await get_solved_challenges(user1, lang)
    solved_user2 = await get_solved_challenges(user2, lang)

    user1_diff, user2_diff = get_diff(solved_user1, solved_user2)
    tosend_list = []

    tosend = display_diff_one_side(db, lang, user1_diff)
    tosend_list.append({'user': user1, 'msg': tosend})
    tosend = display_diff_one_side(db, lang, user2_diff)
    tosend_list.append({'user': user2, 'msg': tosend})

    return tosend_list