Exemplo n.º 1
0
def list_players(context: Context):
    players_list = _create_tsmm(context).players_list()
    desc_list = []
    for player in players_list:
        desc_list.append('{}: {} ({}:{})'.format(player.name, round(player.pure_rating, 1),
                                                 round(player.rating.mu, 2), round(player.rating.sigma, 2)))
    context.send_response_message('\n'.join(desc_list))
Exemplo n.º 2
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))
Exemplo n.º 3
0
def _maybe_greet_user(context: Context, user: User):
    if context.group not in user.groups:
        user.groups.append(context.group)
        message_template = _('greet_known_{user}') if user.is_known else _(
            'greet_new_{user}')
        user.is_known = True
        context.send_response_message(message_template.format(user=user.name))
Exemplo n.º 4
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))
Exemplo n.º 5
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)
Exemplo n.º 6
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))
Exemplo n.º 7
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
Exemplo n.º 8
0
def on_help_or_start(context: Context):
    # RELEASE-UPDATE
    message_template = _('{project}_help_for_group') if context.group else _(
        '{project}_help_for_private')
    context.send_response_message(
        message_template.format(project=PROJECT_FULL_NAME))
Exemplo n.º 9
0
def on_user_report_received(context: Context):
    ReportsSender.forward_user_message(context)
    context.send_response_message(
        _('{user}_report_sent').format(user=context.sender.name))
Exemplo n.º 10
0
def on_user_report_request(context: Context):
    on_reset_action(context, new_action=Pending.REPORT)
    context.send_response_message(
        _('waiting_for_{user}_report').format(user=context.sender.name))
Exemplo n.º 11
0
def on_reset_action(context: Context, new_action=None):
    action_string = context.sender.reset_pending_action(
        new_action, context.update.effective_chat.id)
    if action_string:
        context.send_response_message(_('pending_action_cancelled'))
Exemplo n.º 12
0
def on_click_here(context: Context):
    context.send_response_message(_('rdr2_easter_egg'))
Exemplo n.º 13
0
def on_help_or_start(context: Context):
    message_template = 'Hello world!\n{project}'
    context.send_response_message(
        message_template.format(project=PROJECT_FULL_NAME))
Exemplo n.º 14
0
def _try_update_message(context: Context, request: Request):
    try:
        context.update.callback_query.edit_message_text(text=_message_for_recall(context, request),
                                                        reply_markup=_markup_for_call())
    except TelegramError:
        context.send_response_message(_('invalid_request_{user}').format(user=context.sender.name))
Exemplo n.º 15
0
def _maybe_farewell_user(context: Context, user: User):
    if context.group in user.groups:
        user.groups.remove(context.group)
        context.send_response_message(
            _('farewell_{user}').format(user=user.mention_name()))
Exemplo n.º 16
0
def on_help_or_start(context: Context):
    context.send_response_message(
        _('{project}_help').format(project=PROJECT_FULL_NAME))