async def finalize(client, message, **kwargs): """Finalize a tournament Tournament will be closed and no further modifications will be possible Be sure to upload attachements before finalizing This Channel will be locked for writing except for organizers No Arguments """ try: t = await kwargs.get('account').tournaments.finalize( kwargs.get('tournament_id')) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: # let's remove the role associated to this tournament. # only the Challonge role will be able to write in it await client.delete_role(message.server, kwargs.get('tournament_role')) await client.send_message(message.channel, '✅ Tournament has been finalized!') try: t = await kwargs.get('account').tournaments.show( kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel) await modules.on_state_change(message.server.id, TournamentState.complete, t_name=t['name'], me=message.server.me)
async def updatex(client, message, **kwargs): """Report a match score Required Arguments: p1 -- Player 1 name or nickname or mention (mention is safer) score -- [YourScore]-[OpponentScore] : 5-0. Can be comma separated: 5-0,4-5,5-3 p2 -- Player 2 name or nickname or mention (mention is safer) """ # Verify score format if not verify_score_format(kwargs.get('score')): await client.send_message(message.channel, '❌ Invalid score format. Please use the following 5-0,4-5,5-3') return # Verify first player: mention first, then name, then nick p1_as_member = get_member(kwargs.get('p1'), message.server) if not p1_as_member: await client.send_message(message.channel, '❌ I could not find player 1 on this server') return # Verify second player: mention first, then name, then nick p2_as_member = get_member(kwargs.get('p2'), message.server) if not p2_as_member: await client.send_message(message.channel, '❌ I could not find player 2 on this server') return p1_id, p2_id, exc = await get_players(kwargs.get('account'), kwargs.get('tournament_id'), p1_as_member.name, p2_as_member.name) if exc: await client.send_message(message.channel, exc) return elif not p1_id: await client.send_message(message.channel, '❌ I could not find player 1 in this tournament') return elif not p2_id: await client.send_message(message.channel, '❌ I could not find player 2 in this tournament') return match, is_reversed, exc = await get_match(kwargs.get('account'), kwargs.get('tournament_id'), p1_id, p2_id) if exc: await client.send_message(message.channel, exc) return elif not match: await client.send_message(message.channel, '❌ No open match found for these players') return winner_id = p1_id if author_is_winner(kwargs.get('score')) else p2_id score = kwargs.get('score') if not is_reversed else reverse_score(kwargs.get('score')) msg, exc = await update_score(kwargs.get('account'), kwargs.get('tournament_id'), match['id'], score, winner_id) if exc: await client.send_message(message.channel, exc) return else: await client.send_message(message.channel, msg) try: t = await kwargs.get('account').tournaments.show(kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel) await modules.on_event(message.server.id, Events.on_update_score, p1_name=p1_as_member.name, score=kwargs.get('score'), p2_name=p2_as_member.name, me=message.server.me)
async def checkin_abort(client, message, **kwargs): """Stop or reset the check-in process No arguments """ try: await kwargs.get('account').tournaments.abort_check_in(kwargs.get('tournament_id')) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: await client.send_message(message.channel, '✅ Check-ins have been aborted') try: t = await kwargs.get('account').tournaments.show(kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel)
async def checkin_validate(client, message, **kwargs): """Finalize the check-in process once check-in time is done Participants that didn't check-in will be moved to bottom seeds No arguments """ try: await kwargs.get('account').tournaments.process_check_ins(kwargs.get('tournament_id')) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: await client.send_message(message.channel, '✅ Check-ins have been processed') try: t = await kwargs.get('account').tournaments.show(kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel)
async def checkin_setup(client, message, **kwargs): """Setup the checkin process for participants Required Arguments: date -- date of the tournament: YYYY/MM/DD time -- time of the tournament: HH:MM (24h format) duration -- length of the participant check-in window in minutes. """ # verify date date = get_date(kwargs.get('date')) if not date: await client.send_message(message.channel, '❌ Wrong date format. Must be `YYYY/MM/DD`.') return # verify time time = get_time(kwargs.get('time')) if not time: await client.send_message(message.channel, '❌ Wrong time format. Must be `HH:MM` (24h format).') return # verify duration try: duration = int(kwargs.get('duration')) except ValueError: await client.send_message(message.channel, '❌ Duration must be an integer') return else: if duration <= 0: await client.send_message(message.channel, '❌ Duration must be a positive integer') return # combime date & time full_date_time = datetime.strptime(kwargs.get('date') + ' ' + kwargs.get('time'), '%Y/%m/%d %H:%M') try: await kwargs.get('account').tournaments.update(kwargs.get('tournament_id'), start_at=full_date_time, check_in_duration=duration) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: await client.send_message(message.channel, '✅ Start date and check-in duration have been processed') try: t = await kwargs.get('account').tournaments.show(kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel)
async def finalize(client, message, **kwargs): """Finalize a tournament Tournament will be closed and no further modifications will be possible Be sure to upload attachements before finalizing This Channel will be locked for writing except for organizers No Arguments """ try: t = await kwargs.get('account').tournaments.finalize(kwargs.get('tournament_id')) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: # let's remove the role associated to this tournament. # only the Challonge role will be able to write in it await client.delete_role(message.server, kwargs.get('tournament_role')) await client.send_message(message.channel, '✅ Tournament has been finalized!') try: t = await kwargs.get('account').tournaments.show(kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel) await modules.on_state_change(message.server.id, TournamentState.complete, t_name=t['name'], me=message.server.me)
async def checkin_abort(client, message, **kwargs): """Stop or reset the check-in process No arguments """ try: await kwargs.get('account').tournaments.abort_check_in( kwargs.get('tournament_id')) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: await client.send_message(message.channel, '✅ Check-ins have been aborted') try: t = await kwargs.get('account').tournaments.show( kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel)
async def checkin_validate(client, message, **kwargs): """Finalize the check-in process once check-in time is done Participants that didn't check-in will be moved to bottom seeds No arguments """ try: await kwargs.get('account').tournaments.process_check_ins( kwargs.get('tournament_id')) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: await client.send_message(message.channel, '✅ Check-ins have been processed') try: t = await kwargs.get('account').tournaments.show( kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel)
async def update(client, message, **kwargs): """Report your score against another participant Required Arguments: score -- [YourScore]-[OpponentScore] : 5-0. Can be comma separated: 5-0,4-5,5-3 opponent -- Your opponnent name or nickname or mention (mention is safer) """ account = kwargs.get('account') t_id = kwargs.get('tournament_id') score = kwargs.get('score') # Verify score format if not verify_score_format(score): await client.send_message(message.channel, '❌ Invalid score format. Please use the following 5-0,4-5,5-3') return # Verify other member: mention first, then name, then nick opponent_as_member = get_member(kwargs.get('opponent'), message.server) if not opponent_as_member: await client.send_message(message.channel, '❌ I could not find your opponent on this server') return p1_id, p2_id, exc = await get_players(account, t_id, message.author.name, opponent_as_member.name) if exc: await client.send_message(message.channel, exc) return elif not p1_id: await client.send_message(message.channel, '❌ I could not find you in this tournament') return elif not p2_id: await client.send_message(message.channel, '❌ I could not find your opponent in this tournament') return match, is_reversed, exc = await get_match(account, t_id, p1_id, p2_id) if exc: await client.send_message(message.channel, exc) return elif not match: await client.send_message(message.channel, '❌ Your current opponent is not ' + opponent_as_member.name) return winner_id = p1_id if author_is_winner(score) else p2_id if is_reversed: score = reverse_score(score) msg, exc = await update_score(account, t_id, match['id'], score, winner_id) if exc: await client.send_message(message.channel, exc) else: next_for_p1, exc1 = await get_next_match(account, t_id, message.author.name) next_for_p2, exc2 = await get_next_match(account, t_id, opponent_as_member.name) if exc1 or exc2: # something went wrong with the next games, don't bother the author and send the result msg await client.send_message(message.channel, msg) log_commands_def.error(exc1, exc2) else: if next_for_p1: msg = msg + '\n' + next_for_p1 if next_for_p2: msg = msg + '\n' + next_for_p2 await client.send_message(message.channel, msg) try: t = await account.tournaments.show(t_id, include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(account, t, client, message.channel) await modules.on_event(message.server.id, Events.on_update_score, p1_name=message.author.name, score=kwargs.get('score'), p2_name=opponent_as_member.name, me=message.server.me)
async def update(client, message, **kwargs): """Report your score against another participant Required Arguments: score -- [YourScore]-[OpponentScore] : 5-0. Can be comma separated: 5-0,4-5,5-3 opponent -- Your opponnent name or nickname or mention (mention is safer) """ account = kwargs.get('account') t_id = kwargs.get('tournament_id') score = kwargs.get('score') # Verify score format if not verify_score_format(score): await client.send_message( message.channel, '❌ Invalid score format. Please use the following 5-0,4-5,5-3') return # Verify other member: mention first, then name, then nick opponent_as_member = get_member(kwargs.get('opponent'), message.server) if not opponent_as_member: await client.send_message( message.channel, '❌ I could not find your opponent on this server') return p1_id, p2_id, exc = await get_players(account, t_id, message.author.name, opponent_as_member.name) if exc: await client.send_message(message.channel, exc) return elif not p1_id: await client.send_message(message.channel, '❌ I could not find you in this tournament') return elif not p2_id: await client.send_message( message.channel, '❌ I could not find your opponent in this tournament') return match, is_reversed, exc = await get_match(account, t_id, p1_id, p2_id) if exc: await client.send_message(message.channel, exc) return elif not match: await client.send_message( message.channel, '❌ Your current opponent is not ' + opponent_as_member.name) return winner_id = p1_id if author_is_winner(score) else p2_id if is_reversed: score = reverse_score(score) msg, exc = await update_score(account, t_id, match['id'], score, winner_id) if exc: await client.send_message(message.channel, exc) else: next_for_p1, exc1 = await get_next_match(account, t_id, message.author.name) next_for_p2, exc2 = await get_next_match(account, t_id, opponent_as_member.name) if exc1 or exc2: # something went wrong with the next games, don't bother the author and send the result msg await client.send_message(message.channel, msg) log_commands_def.error(exc1, exc2) else: if next_for_p1: msg = msg + '\n' + next_for_p1 if next_for_p2: msg = msg + '\n' + next_for_p2 await client.send_message(message.channel, msg) try: t = await account.tournaments.show(t_id, include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(account, t, client, message.channel) await modules.on_event(message.server.id, Events.on_update_score, p1_name=message.author.name, score=kwargs.get('score'), p2_name=opponent_as_member.name, me=message.server.me)
async def updatex(client, message, **kwargs): """Report a match score Required Arguments: p1 -- Player 1 name or nickname or mention (mention is safer) score -- [YourScore]-[OpponentScore] : 5-0. Can be comma separated: 5-0,4-5,5-3 p2 -- Player 2 name or nickname or mention (mention is safer) """ # Verify score format if not verify_score_format(kwargs.get('score')): await client.send_message( message.channel, '❌ Invalid score format. Please use the following 5-0,4-5,5-3') return # Verify first player: mention first, then name, then nick p1_as_member = get_member(kwargs.get('p1'), message.server) if not p1_as_member: await client.send_message( message.channel, '❌ I could not find player 1 on this server') return # Verify second player: mention first, then name, then nick p2_as_member = get_member(kwargs.get('p2'), message.server) if not p2_as_member: await client.send_message( message.channel, '❌ I could not find player 2 on this server') return p1_id, p2_id, exc = await get_players(kwargs.get('account'), kwargs.get('tournament_id'), p1_as_member.name, p2_as_member.name) if exc: await client.send_message(message.channel, exc) return elif not p1_id: await client.send_message( message.channel, '❌ I could not find player 1 in this tournament') return elif not p2_id: await client.send_message( message.channel, '❌ I could not find player 2 in this tournament') return match, is_reversed, exc = await get_match(kwargs.get('account'), kwargs.get('tournament_id'), p1_id, p2_id) if exc: await client.send_message(message.channel, exc) return elif not match: await client.send_message(message.channel, '❌ No open match found for these players') return winner_id = p1_id if author_is_winner(kwargs.get('score')) else p2_id score = kwargs.get('score') if not is_reversed else reverse_score( kwargs.get('score')) msg, exc = await update_score(kwargs.get('account'), kwargs.get('tournament_id'), match['id'], score, winner_id) if exc: await client.send_message(message.channel, exc) return else: await client.send_message(message.channel, msg) try: t = await kwargs.get('account').tournaments.show( kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel) await modules.on_event(message.server.id, Events.on_update_score, p1_name=p1_as_member.name, score=kwargs.get('score'), p2_name=p2_as_member.name, me=message.server.me)
async def checkin_setup(client, message, **kwargs): """Setup the checkin process for participants Required Arguments: date -- date of the tournament: YYYY/MM/DD time -- time of the tournament: HH:MM (24h format) duration -- length of the participant check-in window in minutes. """ # verify date date = get_date(kwargs.get('date')) if not date: await client.send_message( message.channel, '❌ Wrong date format. Must be `YYYY/MM/DD`.') return # verify time time = get_time(kwargs.get('time')) if not time: await client.send_message( message.channel, '❌ Wrong time format. Must be `HH:MM` (24h format).') return # verify duration try: duration = int(kwargs.get('duration')) except ValueError: await client.send_message(message.channel, '❌ Duration must be an integer') return else: if duration <= 0: await client.send_message(message.channel, '❌ Duration must be a positive integer') return # combime date & time full_date_time = datetime.strptime( kwargs.get('date') + ' ' + kwargs.get('time'), '%Y/%m/%d %H:%M') try: await kwargs.get('account').tournaments.update( kwargs.get('tournament_id'), start_at=full_date_time, check_in_duration=duration) except ChallongeException as e: await client.send_message(message.author, T_OnChallongeException.format(e)) else: await client.send_message( message.channel, '✅ Start date and check-in duration have been processed') try: t = await kwargs.get('account').tournaments.show( kwargs.get('tournament_id'), include_participants=1, include_matches=1) except ChallongeException: log_commands_def.exception('') else: await update_channel_topic(kwargs.get('account'), t, client, message.channel)