Пример #1
0
async def display_cron(
        id_discord_server: int,
        db: DatabaseManager) -> Tuple[Optional[str], Optional[str]]:
    lang = await db.get_server_language(id_discord_server)
    users = await db.select_users(id_discord_server)
    for user in users:
        last = user['last_challenge_solve']
        solved_user = await get_solved_challenges(user['rootme_username'],
                                                  lang)
        if not solved_user or solved_user[-1]['name'] == last:
            continue
        blue(solved_user[-1]['name'] + "  |  " + last + "\n")
        next_chall = next_challenge_solved(solved_user, last)
        if next_chall is None:
            red(f'Error with {user} --> last chall: {solved_user[-1]["name"]}\n'
                )
            continue
        name = f'New challenge solved by {user["rootme_username"]}'
        c = find_challenge(db, lang, next_chall['name'])
        green(f'{user} --> {c["name"]}')
        tosend = f' • {c["name"]} ({c["value"]} points)'
        tosend += f'\n • Difficulty: {c["difficulty"]}'
        tosend += f'\n • Date: {next_chall["date"]}'
        tosend += f'\n • New score: {next_chall["score_at_date"]}'
        await db.update_user_last_challenge(id_discord_server,
                                            user['rootme_username'], c['name'])
        return name, tosend
    return None, None
Пример #2
0
async def display_cron(id_discord_server: int, db: DatabaseManager) -> Tuple[Optional[str], Optional[str]]:
    # check updates about challenges data
    global all_challenges
    if id_discord_server not in list(all_challenges.keys()):
        list_all_challenges = await get_all_challenges()
        all_challenges[id_discord_server] = list_all_challenges

    list_all_challenges = all_challenges[id_discord_server]
    new_list_all_challenges = await get_all_challenges()

    if len(new_list_all_challenges) > len(list_all_challenges):
        challenges = [chall for chall in new_list_all_challenges if chall not in list_all_challenges]
        message_title = f'NEW CHALLENGE !!!'
        tosend = f''
        for challenge in challenges:
            print(challenge)
            tosend += f' • {unescape(challenge["titre"])}'
            """
            challenge_info = await Parser.extract_challenge_info(challenge['id_challenge'])
            tosend += f' • {challenge_info["titre"]} ({challenge_info["score"]} points)'
            tosend += f'\n --> Category: {challenge_info["rubrique"]}'
            #  tosend += f'\n • URL: {challenge_info["url_challenge"]}'
            tosend += f'\n --> Difficulty: {challenge_info["difficulte"]}\n'
            """
        # update challenges list
        all_challenges[id_discord_server] = new_list_all_challenges
        return message_title, tosend
    # check updates about user data
    users = await db.select_users(id_discord_server)
    for user in users:
        time.sleep(1)
        print(user)
        number_challenge_solved, score = user['number_challenge_solved'], user['score']
        user_data = await Parser.extract_rootme_profile_complete(user['rootme_user_id'])
        if user_data is None:  #  User {user["rootme_username"]} score is equal to zero
            continue
        if len(user_data['validations']) == number_challenge_solved:
            continue

        if number_challenge_solved > 0:
            new_challenges_solved = user_data['validations'][:-number_challenge_solved][::-1]  # last solved + reverse order
        else:
            new_challenges_solved = user_data['validations'][::-1]  # all solves because there was no solve before + reverse
        new_challenge = new_challenges_solved[0]

        challenge_info = await Parser.extract_challenge_info(new_challenge['id_challenge'])
        score += int(challenge_info['score'])

        green(f'{user["rootme_username"]} --> {unescape(challenge_info["titre"])}')
        message_title = f'New challenge solved by {user["rootme_username"]}'
        tosend = f' • {unescape(challenge_info["titre"])} ({challenge_info["score"]} points)'
        tosend += f'\n • Category: {challenge_info["rubrique"]}'
        #  tosend += f'\n • URL: {challenge_info["url_challenge"]}'
        tosend += f'\n • Difficulty: {challenge_info["difficulte"]}'
        tosend += f'\n • Date: {new_challenge["date"]}'
        tosend += f'\n • New score: {score}'
        await db.update_user_info(id_discord_server, user['rootme_username'], score, number_challenge_solved + 1)
        return message_title, tosend
    return None, None
Пример #3
0
async def check_new_server(channel: TextChannel, server: Guild, db: DatabaseManager, command_prefix: str) -> None:
    if await db.is_server_registered(server.id):
        return
    green(f'RootMeBot is coming on {server.name} discord server !')
    await db.register_server(server.id)
    tosend = f"Hello, it seems that it's the first time you are using my services.\nYou might use " \
        f"`{command_prefix}help` to know more about my features."
    embed_color, embed_name = 0x000000, "RootMe Bot"
    await interrupt(channel, tosend, embed_color=embed_color, embed_name=embed_name)
Пример #4
0
async def extract_json(url: str) -> response_content_type:
    data = await request_to(url)
    if data is None:
        red(url)
    else:
        green(url)
        if 'body' in data.keys():
            data = data['body']
    return data
Пример #5
0
 async def on_ready():
     green('RootMeBot is starting !')
Пример #6
0
 async def on_ready():
     for server in self.bot.guilds:
         green(
             f'RootMeBot is starting on the following server: "{server.name}" !'
         )