Ejemplo n.º 1
0
def buy_status(bot, update):
    mes = update.message
    status_id = re.search("_(\\d+)", mes.text)
    if status_id is None:
        bot.send_message(chat_id=mes.chat_id, text="Статус не найден")
        return
    status_id = int(status_id.group(1))
    player = Player.get_player(mes.from_user.id)
    player_statuses = player.tea_party_info.get("statuses")
    if player_statuses is None:
        player_statuses = []
        player.tea_party_info.update({"statuses": player_statuses})
    if status_id in player_statuses:
        bot.send_message(chat_id=mes.chat_id, text="Статус уже куплен")
        return
    status = statuses_const.get(status_id)
    price, name = status.get("price"), status.get("name")
    if price is None:
        bot.send_message(chat_id=mes.chat_id,
                         text="Этот статус невозможно купить.")
        return
    if player.reputation < price:
        bot.send_message(chat_id=mes.chat_id, text="Недостаточно 🔘")
        return
    player.reputation -= price
    player_statuses.append(status_id)
    player.update()
    bot.send_message(chat_id=mes.chat_id,
                     text="Статус <b>{}</b> успешно куплен!\nАктивируйте его! "
                     "Просмотреть доступные статусы: /statuses".format(name),
                     parse_mode='HTML')
Ejemplo n.º 2
0
def get_status_text_by_id(status_id: int, player_id=None) -> str:
    if status_id == OWN_STATUS_ID:
        player = Player.get_player(player_id, notify_on_error=False)
        if player is None:
            raise RuntimeError
        return player.tea_party_info.get("own_status")
    status = statuses_const.get(status_id)
    if status is not None:
        name = status["name"]
        if status.get("unique"):
            name += " 🎗"
        return name
    return None
Ejemplo n.º 3
0
def statuses(bot, update):
    mes = update.message
    player = Player.get_player(mes.from_user.id)
    player_statuses = player.tea_party_info.get("statuses")
    if player_statuses is None:
        bot.send_message(
            chat_id=mes.chat_id,
            text=
            "Нет купленных статусов. Статусы можно купить в магазине (Чайная лига)"
        )
        return
    response = "Текущий статус: <b>{}</b>\n\n".format(get_status_text_by_id(player.status, player.id)) if \
        player.status is not None else ""
    response += "Доступные статусы:\n"
    for status_id in player_statuses:
        if status_id == OWN_STATUS_ID:
            name = player.tea_party_info.get("own_status")
        else:
            status = statuses_const.get(status_id)
            name = status.get("name")
        response += "<b>{}</b>\n/status_on_{}\n\n".format(name, status_id)
    bot.send_message(chat_id=player.id, text=response, parse_mode='HTML')