Example #1
0
def matchup(context: Context):
    args = context.command_arguments().split()
    if len(args) < 2:
        return

    players = [context.session.query(Player).filter(Player.name == name).first().id for name in args]
    ttsm = _create_tsmm(context)
    matchups = ttsm.matchups(players)

    def names_list(ttsm: TrueSkillMatchmaker, ids):
        return ', '.join([ttsm.players[player_id].name for player_id in ids])

    def quality_name(quality: float):
        if quality >= 0.55:
            return 'Good'
        elif quality >= 0.45:
            return 'Unstable'
        else:
            return 'Poor'

    desc_list = []
    for matchup in matchups[:6]:
        desc_list.append('{} option (score: {})\n{} vs {}\n{}% vs {}%\n'.format(
            quality_name(matchup.quality), round(matchup.quality, 2),
            names_list(ttsm, matchup.team1_ids), names_list(ttsm, matchup.team2_ids),
            round(matchup.team1_win_chance * 100.0, 1), round(matchup.team2_win_chance * 100.0, 1)))
    context.send_response_message('\n'.join(desc_list))
Example #2
0
def drop_player(context: Context):
    player_name = context.command_arguments()
    if not player_name:
        return

    player = context.session.query(Player).filter(Player.name == player_name).first()
    if not player:
        return

    context.session.delete(player)
    context.send_response_message('deleted {}'.format(player_name))
Example #3
0
def on_all_request(context: Context):
    users_list = [user for user in context.group.users if user != context.sender]
    if not users_list:
        context.send_response_message(_('no_users_for_broadcast_message'))
        return
    user_message = context.command_arguments()
    if user_message:
        message = user_message + '\n' + _('all_with_text_from_{user}').format(user=context.sender.name)
    else:
        message = _('all_from_{user}').format(user=context.sender.name)
    message += '\n\n' + ', '.join([user.mention_name() for user in users_list])
    context.send_response_message(message)
Example #4
0
def add_player(context: Context):
    player_name = context.command_arguments()
    if not player_name:
        return

    player = context.session.query(Player).filter(Player.name == player_name).first()
    if player:
        context.send_response_message('exists')
        return

    player = Player(name=player_name, mu=_true_skill.mu, sigma=_true_skill.sigma)
    context.session.add(player)
    context.send_response_message('created {}'.format(player.name))
Example #5
0
def on_recall_request(context: Context):
    available_users = [user for user in context.group.users if user != context.sender]
    if not available_users:
        context.send_response_message(_('no_users_for_broadcast_message'))
        return
    user_message = context.command_arguments()
    if user_message:
        title = user_message + '\n' + _('recall_with_text_from_{user}').format(user=context.sender.name)
    else:
        title = _('recall_from_{user}').format(user=context.sender.name)
    request = Request(message_id=_MESSAGE_UNDEFINED,
                      chat_id=context.update.effective_chat.id,
                      author=context.sender,
                      title=title)
    context.session.add(request)
    request_message = context.send_response_message(_message_for_recall(context, request),
                                                    reply_markup=_markup_for_call())
    request.message_id = request_message.message_id
Example #6
0
def add_game(context: Context):
    args = context.command_arguments().split()
    if len(args) < 2:
        return

    tsmm = _create_tsmm(context)
    winner_team_size = int(args[0])
    winners = [context.session.query(Player).filter(Player.name == name).first().id for name in
               args[1:1 + winner_team_size]]
    losers = [context.session.query(Player).filter(Player.name == name).first().id for name in
              args[1 + winner_team_size:]]
    tsmm.update(winners, losers)

    all_players = context.session.query(Player).all()
    for player in all_players:
        player.mu = tsmm.players[player.id].rating.mu
        player.sigma = tsmm.players[player.id].rating.sigma

    list_players(context)