async def add_player(client, user, server, size): # Register user and ask for decks request_id = persistence.add_to_waiting_list(server.id, user, size) await user.send( config.get_server_config(server.name, 'wait_for_decks_message')) def he_replied(message): return message.author == user and isinstance( message.channel, discord.abc.PrivateChannel) request = None while True: reply = await client.wait_for('message', check=he_replied) if not persistence.is_join_request_still_valid(request_id): # While waiting, the user performed the command again and subscribed to a new tournament format: # We'll let that coroutine to handle it, and this will terminate here print('submission invalidated: terminating') break if reply.content != '!submit': # Add deck urls = [attachment.url for attachment in reply.attachments] request = persistence.add_deck(request_id, reply.content, urls) elif request is None: # !submit used, but no decks submitted yet await user.send( 'At least one deck is needed to complete registration, please send at least one and try ' 'again with `!submit`') else: # He's finished print(f'Submitting player: {user.name}') return await confirm_player(request_id, server, user)
async def enterticket(context, size=4): # Read and delete message message = context.message await message.delete() # Extract user, server, create direct message channel with the user user = message.author server = message.channel.guild # Check user's ticker if not config.has_ticket(server.name, user): await user.send( config.get_server_config(server.name, 'role_missing_message')) elif not is_power_of_two(size): await user.send( f'I\'sorry, but the size "{size}"" is not a power of two! Try with one of these: 2, 4, 8, 16, 32,' f' 64, 128....') elif persistence.is_username_used(user.name, server.id, size): await user.send( f'I\'sorry, but the user name "{user.name}" is already being used in the currently open Anytime ' f'Tournament of size {size}. Change it and try again!') else: try: anytime_data = await add_player(context.bot, user, server, size) except Exception: await user.send( 'Sorry, something went wrong. Please try again and if it\'s not getting better, contact' ' a mod.') raise # Did the anytime just got full? if len(anytime_data['players']) == anytime_data['size']: try: await start_tournament(server, anytime_data) except Exception: anytime_channel = server.get_channel( anytime_data['channel_id']) await anytime_channel.send( 'Error: could not start the tournament. Please ask a mod to start it ' 'manually.') raise
def test_get_server_config_missing_server(): role = config.get_server_config(TEST_SERVER_MISSING, TEST_KEY) assert role == TEST_VALUE
def test_get_server_config_absent(): role = config.get_server_config(TEST_SERVER, TEST_KEY_MISSING) assert role is None
def test_get_server_config_present(): role = config.get_server_config(TEST_SERVER, TEST_KEY) assert role == TEST_VALUE