def show_worldtop(bot, update, args):
    battle_id = None
    if args:
        try:
            battle_id = int(args[0])
            if battle_id < 0:
                battle_id = count_battle_id() + battle_id
        except ValueError:
            pass
    worldtop = load_worldtop(battle_id=battle_id)
    if worldtop is None and battle_id is None:
        battle_id = count_battle_id()
        for i in range(6):
            worldtop = load_worldtop(battle_id - i)
            if worldtop is not None:
                break
    response = "Worldtop: {}\n".format("битва {}\n({}):".format(
        battle_id,
        count_battle_time(battle_id).strftime("%d/%m/%y %H:%M:%S")
    ) if battle_id is not None else "")
    i = 1
    for k, v in list(worldtop.items()):
        response += "# {} {}: <code>{:>5}</code> 🏆 очков\n".format(i, k, v)
        i += 1
    bot.send_message(chat_id=update.message.chat_id,
                     text=response,
                     parse_mode='HTML')
Exemplo n.º 2
0
def profile_exp(bot, update):
    data = update.callback_query.data
    mes = update.callback_query.message
    player_id = re.search("_(\\d+)", data)
    if player_id is None:
        bot.answerCallbackQuery(
            callback_query_id=update.callback_query.id,
            text="Произошла ошибка. Попробуйте открыть все меню сначала.")
        return
    player_id = int(player_id.group(1))
    player = Player.get_player(player_id)
    if player is None:
        return
    response = "Изменения в опыте <b>{}</b>:\n".format(player.nickname)
    previous_exp = None
    print(player.exp_info)
    if not player.exp_info:
        response += "<em>Пусто</em>"
    else:
        for battle_id, exp in list(player.exp_info.items())[-14:]:
            battle_id = int(battle_id)
            if previous_exp is not None:
                response += "{}: +🔥<code>{}</code>\n".format(
                    count_battle_time(battle_id).strftime("%d/%m/%y"),
                    exp - previous_exp)
            previous_exp = exp
        response += "{}: +🔥<code>{}</code>" \
                    "\n".format(datetime.datetime.now(tz=moscow_tz).replace(tzinfo=None).strftime("%d/%m/%y"),
                                player.exp - previous_exp)
    bot.send_message(chat_id=update.callback_query.from_user.id,
                     text=response,
                     parse_mode='HTML')
    bot.answerCallbackQuery(callback_query_id=update.callback_query.id)
Exemplo n.º 3
0
def profile_exp(bot, update):
    data = update.callback_query.data
    mes = update.callback_query.message
    player_id = re.search("_(\\d+)", data)
    if player_id is None:
        bot.answerCallbackQuery(
            callback_query_id=update.callback_query.id,
            text="Произошла ошибка. Попробуйте открыть все меню сначала.")
        return
    player_id = int(player_id.group(1))
    player = Player.get_player(player_id)
    if player is None:
        return
    response = "Изменения в опыте <b>{}</b>:\n".format(player.nickname)
    previous_exp = None
    # print(player.exp_info)
    if not player.exp_info:
        response += "<em>Пусто</em>"
    else:
        for battle_id, exp in list(player.exp_info.items())[-14:]:
            battle_id = int(battle_id)
            if previous_exp is not None:
                response += "{}: +🔥<code>{}</code>\n".format(
                    count_battle_time(battle_id).strftime("%d/%m/%y"),
                    exp - previous_exp)
            previous_exp = exp
        response += "{}: +🔥<code>{}</code>" \
                    "\n".format(datetime.datetime.now(tz=moscow_tz).replace(tzinfo=None).strftime("%d/%m/%y"),
                                player.exp - previous_exp)
        prediction_data = list(player.exp_info.values())[-4:]
        prediction_data = [
            prediction_data[i] - prediction_data[i - 1]
            for i in range(1, len(prediction_data))
        ]
        if prediction_data:
            avg_exp = sum(prediction_data) / len(prediction_data)
            need_reach = levels.get(player.lvl + 1, {}).get("exp")
            if need_reach is not None:
                remain = need_reach - player.exp
                if remain < 0:
                    logging.error(
                        "Wrong info about level exp: {} {} {}".format(
                            player.nickname, player.lvl, player.exp))
                else:
                    response += "\nВ среднем <code>{}</code>🔥 в день.\n" \
                                "До следующего уровня приблизительно <b>{}</b> дней.".format(
                                    int(avg_exp),
                                    int(remain // avg_exp) + (1 if remain % avg_exp else 0) if avg_exp > 0 else "❔"
                        )

    bot.send_message(chat_id=update.callback_query.from_user.id,
                     text=response,
                     parse_mode='HTML')
    bot.answerCallbackQuery(callback_query_id=update.callback_query.id)
Exemplo n.º 4
0
def send_potion_stats(bot, job):
    """
    Отправка статистики покупки банок по замкам в чат МИДа
    """
    clear = job.context[0]
    potions = cwapi.api_info.get("potions_info")
    if potions is None:
        bot.send_message(chat_id=SUPER_ADMIN_ID,
                         text="Ошибка. Информация по банкам отсутствует.")
        return
    battle_id = count_battle_id(None) + 1
    response = "Закупки замков по банкам к битве № <code>{}</code> ({}):\n\n<em>total | vial / potion / bottle</em>" \
               "\n\n".format(battle_id, count_battle_time(battle_id).strftime("%d/%m/%y %H:%M:%S"))
    for category, pot in list(potions.items()):
        total_potions = {}
        response += "<b>{}:</b>\n".format(category)
        types = ["vial", "potion", "bottle"]
        for type in types:
            potion = pot.get(type)
            if potion is None:
                potion = {k: 0 for k in castles}
            for castle in castles:
                count = potion.get(castle) or 0
                pt = total_potions.get(castle)
                if pt is None:
                    pt = [0, ""]
                    total_potions.update({castle: pt})
                # count, res = pt
                pt[1] += "<code>{:>2}</code> / ".format(count)
                pt[0] += count
        total_potions = {
            k: v
            for k, v in sorted(list(total_potions.items()),
                               key=lambda x: x[1][0],
                               reverse=True)
        }
        for castle, pot in list(total_potions.items()):
            if pot[0] == 0:
                continue
            response += "{}: <code>{:>2}</code> | {}\n".format(
                castle, pot[0], pot[1][:-1])
    bot.send_message(chat_id=MID_CHAT_ID, text=response, parse_mode='HTML')
    if clear:
        cwapi.api_info.update({"potions_info": {}})
Exemplo n.º 5
0
def reports_history(bot, update):
    data = update.callback_query.data
    mes = update.callback_query.message
    player = Player.get_player(player_id=update.callback_query.from_user.id)
    if player is None:
        return

    requested_player_id = re.search("_(\\d+)", data)
    if requested_player_id is None:
        bot.send_message(
            chat_id=mes.chat_id,
            text="Произошла ошибка. Попробуйте вызвать сообщение заного.")
        return
    requested_player_id = int(requested_player_id.group(1))

    requested_player = Player.get_player(requested_player_id,
                                         notify_on_error=False)
    if requested_player is None:
        bot.send_message(chat_id=mes.chat_id, text="Игрок не найден.")
        return
    if player.id != requested_player.id and not check_whois_access(
            player.id) and (requested_player.guild is None
                            or requested_player.guild != player.guild):
        bot.answerCallbackQuery(callback_query_id=update.callback_query.id)
        bot.send_message(chat_id=mes.chat_id, text="Доступ запрещён.")
        return
    response = "Отчёты по последним битвам <b>{}</b>:\n".format(
        requested_player.nickname)
    request = "select battle_id, attack, defense, exp, gold, stock from reports where player_id = %s order by " \
              "battle_id desc limit 30"
    cursor.execute(request, (requested_player.id, ))
    row = cursor.fetchone()
    while row is not None:
        response += "🕒{} ⚔️:<code>{:<3},🛡:{:<3},🔥:{:<4},💰:{:<3},📦:{:<3}</code>" \
                    "\n".format(count_battle_time(row[0]).strftime("%H:%M %d/%m"), row[1], row[2], row[3], row[4],
                                row[5])
        row = cursor.fetchone()
    bot.send_message(chat_id=mes.chat_id, text=response, parse_mode='HTML')
    bot.answerCallbackQuery(callback_query_id=update.callback_query.id)