Example #1
0
async def confirm_player(request_id, server, user):
    # Transition user's request to accepted registration
    anytime_data = persistence.submit(request_id)

    if anytime_data is None:
        await user.send(
            'I\'m sorry, there was a problem with your registration.'
            'Please try again by typing `!enterticket`')
        return

    # Retrieve anytime channel
    anytime_channel = server.get_channel(
        anytime_data['channel_id']) if 'channel_id' in anytime_data else None

    if anytime_channel is None:
        # First submitted player: create channel
        anytime_channel = await create_anytime_channel(server,
                                                       anytime_data.doc_id)
        await anytime_channel.send(
            f'Hi everyone! This is the channel we\'ll use for the '
            f'Anytime Tournament #{anytime_data.doc_id}')
        anytime_data = persistence.add_channel_id(anytime_channel.id,
                                                  anytime_data.doc_id)

    # Notify user in the anytime channel
    participant_role = await get_participant_role(server, anytime_data.doc_id)
    await user.add_roles(participant_role)
    await anytime_channel.send(f'{user.mention} joins the battle!')

    # Check that everyone still has a ticket, exit the ones that does not
    for player in anytime_data['players']:
        discord_player = server.get_member(player['user_id'])
        if not config.has_ticket(server.name, discord_player):
            await discord_player.remove_roles(participant_role)
            persistence.remove_player(anytime_data.doc_id, player['user_id'])
            await discord_player.send(
                f'Hey, you don\'t seem to have a ticket anymore, so you were removed from'
                f' the Anytime #{anytime_data.doc_id}. If you think this is an error,'
                f'please contact an Anytime Mod!')

    return anytime_data
Example #2
0
def test_remove_player_missing_player():
    request_id = persistence.add_to_waiting_list(
        TEST_SERVER_ID, MockUser(name=TEST_USER_NAME, id=TEST_USER_NAME),
        TEST_TOURNAMENT_SIZE)
    persistence.add_deck(request_id, TEST_DECK_DESCRIPTION, [TEST_DECK_URL])
    anytime = persistence.submit(request_id)

    anytime = persistence.remove_player(anytime.doc_id, TEST_USER_NAME + '2')

    assert len(anytime['players']) == 1
    player = anytime['players'][0]
    assert player['user_id'] == TEST_USER_NAME
Example #3
0
async def exit(context):
    anytime = await get_anytime(context)

    if anytime is None:
        # Handled by get_anytime
        return

    # Check player status
    anytime_player = next(
        (player for player in anytime['players'] if player['user_id'] == context.message.author.id),
        None
    )
    if anytime_player is None:
        await context.message.channel.send(f'You don\'t seem to be playing in this tournament!')
        return

    if anytime['status'] == AnytimeStatus.RECRUITING:
        persistence.remove_player(anytime.doc_id, context.message.author.id)
        participant_role = await utils.get_participant_role(context.message.guild, anytime.doc_id)
        await context.message.author.remove_roles(participant_role)
    else:
        await context.message.channel.send(f'It\'s too late to exit this tournament!')
Example #4
0
def test_remove_player_missing_anytime():
    anytime = persistence.remove_player('random-id', TEST_USER_NAME)
    assert anytime is None