示例#1
0
async def status(client, message, **kwargs):
    """Get the tournament status
    No Arguments
    """
    account = kwargs.get('account')
    try:
        t = await account.tournaments.show(kwargs.get('tournament_id'), include_participants=1, include_matches=1)
    except ChallongeException as e:
        await client.send_message(message.author, T_OnChallongeException.format(e))
    else:
        if t['state'] == 'underway':
            matchesRepr, exc = await get_current_matches_repr(account, t)
            if exc:
                await client.send_message(message.channel, exc)
            else:
                await client.send_message(message.channel, '✅ Open matches for tournament `{0}` ({1})\n{2}'.format(t['name'], t['full-challonge-url'], matchesRepr))

        elif t['state'] == 'pending':
            info = []
            info.append('✅ Tournament: {0} ({1}) is pending.'.format(t['name'], t['full-challonge-url']))
            info.append('%d participants have registered right now. More can still join until tournament is started' % t['participants-count'])
            await client.send_message(message.channel, '\n'.join(info))

        elif t['state'] == 'awaiting_review':
            await client.send_message(message.channel, '✅ Tournament: {0} ({1}) has been completed and is waiting for final review (finalize)'.format(t['name'], t['full-challonge-url']))

        elif t['state'] == 'complete':
            rankingRepr, exc = get_final_ranking_repr(account, t)
            if exc:
                await client.send_message(message.channel, exc)
            else:
                await client.send_message(message.channel, '✅ Tournament: {0} ({1}) has been completed\n{2}'.format(t['name'], t['full-challonge-url'], rankingRepr))

        else:
            log_commands_def.error('[status] Unknown state: ' + t['state'])
示例#2
0
async def reset(client, message, **kwargs):
    """Reset a tournament
    All scores and attachments will be cleared. You will be able to edit participants then start again
    No Arguments
    """
    try:
        await kwargs.get('account').tournaments.reset(
            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,
                                  '✅ Tournament has been reset!')
        try:
            t = await kwargs.get('account').tournaments.show(
                kwargs.get('tournament_id'))
        except ChallongeException as e:
            log_commands_def.error('reset exc=: %s' % e)
        else:
            await update_channel_topic(kwargs.get('account'), t, client,
                                       message.channel)
            await modules.on_state_change(message.server.id,
                                          TournamentState.pending,
                                          t_name=t['name'],
                                          me=message.server.me)
示例#3
0
async def status(client, message, **kwargs):
    """Get the tournament status
    No Arguments
    """
    account = kwargs.get('account')
    try:
        t = await account.tournaments.show(kwargs.get('tournament_id'),
                                           include_participants=1,
                                           include_matches=1)
    except ChallongeException as e:
        await client.send_message(message.author,
                                  T_OnChallongeException.format(e))
    else:
        if t['state'] == 'underway':
            matchesRepr, exc = await get_current_matches_repr(account, t)
            if exc:
                await client.send_message(message.channel, exc)
            else:
                await client.send_message(
                    message.channel,
                    '✅ Open matches for tournament `{0}` ({1})\n{2}'.format(
                        t['name'], t['full-challonge-url'], matchesRepr))

        elif t['state'] == 'pending':
            info = []
            info.append('✅ Tournament: {0} ({1}) is pending.'.format(
                t['name'], t['full-challonge-url']))
            info.append(
                '%d participants have registered right now. More can still join until tournament is started'
                % t['participants-count'])
            await client.send_message(message.channel, '\n'.join(info))

        elif t['state'] == 'awaiting_review':
            await client.send_message(
                message.channel,
                '✅ Tournament: {0} ({1}) has been completed and is waiting for final review (finalize)'
                .format(t['name'], t['full-challonge-url']))

        elif t['state'] == 'complete':
            rankingRepr, exc = get_final_ranking_repr(account, t)
            if exc:
                await client.send_message(message.channel, exc)
            else:
                await client.send_message(
                    message.channel,
                    '✅ Tournament: {0} ({1}) has been completed\n{2}'.format(
                        t['name'], t['full-challonge-url'], rankingRepr))

        else:
            log_commands_def.error('[status] Unknown state: ' + t['state'])
示例#4
0
async def reset(client, message, **kwargs):
    """Reset a tournament
    All scores and attachments will be cleared. You will be able to edit participants then start again
    No Arguments
    """
    try:
        await kwargs.get('account').tournaments.reset(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, '✅ Tournament has been reset!')
        try:
            t = await kwargs.get('account').tournaments.show(kwargs.get('tournament_id'))
        except ChallongeException as e:
            log_commands_def.error('reset exc=: %s' % e)
        else:
            await update_channel_topic(kwargs.get('account'), t, client, message.channel)
            await modules.on_state_change(message.server.id, TournamentState.pending, t_name=t['name'], me=message.server.me)
示例#5
0
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)
示例#6
0
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)