예제 #1
0
def battle_equip(bot, update):
    mes = update.message
    if mes.from_user.id != SUPER_ADMIN_ID:
        return
    battle_id = re.search("\\d+", mes.text)
    if battle_id is None:
        battle_id = count_battle_id(mes)
    else:
        battle_id = int(battle_id.group(0))
    full = 'full' in mes.text
    request = "select player_id, equip from reports where battle_id = %s and equip is not null " \
              "order by equip ->> 'status'"
    cursor.execute(request, (battle_id, ))
    rows = cursor.fetchall()
    response = "Дроп с битвы {} - {} :\n".format(
        battle_id,
        count_battle_time(battle_id).strftime("%d/%m/%y %H:%M:%S"))
    for row in rows:
        name, found_from = row[1].get("name"), row[1].get("from")
        player = Player.get_player(row[0])
        response += "{}<b>{}</b> {}\n".format(
            "{} ".format((player.castle + player.nickname) if full else ""),
            name,
            "(От {})".format(found_from) if found_from is not None else "")
    bot.send_message(chat_id=mes.chat_id, text=response, parse_mode='HTML')
예제 #2
0
def fill_triggers_ignore():
    ignore_global_triggers.clear()
    request = "select date, additional_info from castle_logs where action ilike " \
              "'reward_castle_disable_global_triggers%' order by date"
    cursor.execute(request)
    for row in cursor.fetchall():
        chat_id = row[1].get("chat_id")
        end_time = row[0] + datetime.timedelta(hours=row[1].get("period"))
        if end_time < datetime.datetime.now():
            continue
        ignore_global_triggers.update({int(chat_id): end_time})
    print(ignore_global_triggers)
예제 #3
0
def get_triggers_list(trigger_chat_id):
    returned = ''
    cursor.execute(
        "select text_in, creator, date_created from triggers where chat_id = %s",
        (trigger_chat_id, ))
    rows = cursor.fetchall()
    if rows:
        for row in rows:
            returned += f'<code>{row[0]}</code> — создал <code>{row[1]}</code> {row[2].strftime("%d/%m/%y %H:%M:%S")}\n'
    else:
        pass
    return returned
예제 #4
0
def battle_drop(bot, update):
    mes = update.message
    request = "select battle_id, equip from reports where player_id = %s and equip is not null " \
              "order by battle_id desc limit 20"
    cursor.execute(request, (mes.from_user.id, ))
    rows = cursor.fetchall()
    response = "Последние изменения в экипировке по репортам:\n"
    for row in rows:
        found_from = row[1].get("from")
        response += "{} - <code>{}</code>: <b>{}</b> {}" \
                    "\n".format(count_battle_time(row[0]), row[1].get("status"), row[1].get("name"),
                                "(От {})".format(found_from) if found_from is not None else "")
    bot.send_message(chat_id=mes.chat_id, text=response, parse_mode='HTML')
예제 #5
0
def count_reports_combo(player_id: int, battle_id: int) -> int:
    """
    Функция подсчитывает, комбо сданных репортов (сколько репортов сдано подряд).
    :param player_id: int - Player id
    :param battle_id: int - Battle id of new reports
    :return: int - reputation that should be added to player`s balance as a reward
    """
    request = "select battle_id from reports where player_id = %s and battle_id < %s order by battle_id desc limit %s"
    cursor.execute(request, (player_id, battle_id, MAX_REPORTS_COMBO - 1))
    rows = cursor.fetchall()
    combo = 1
    for (new_battle_id, *skip) in rows:
        if battle_id - new_battle_id > 1:
            break
        battle_id = new_battle_id
        combo += 1
    return combo
예제 #6
0
def remember_exp(bot, job):
    cursor = conn.cursor()
    request = "select id, exp, exp_info from players"
    cursor.execute(request)
    rows = cursor.fetchall()
    battle_id = count_battle_id(None)
    for row in rows:
        player_id, exp, exp_info = row
        player = Player.get_player(player_id)
        if exp_info is None:
            exp_info = {}
        exp_info.update({str(battle_id): exp})
        exp_info = {
            k: v
            for k, v in sorted(list(exp_info.items()), key=lambda x: int(x[0]))
        }
        player.exp_info = exp_info
        player.update()
        # request = "update players set exp_info = %s where id = %s"
        # cursor.execute(request, (json.dumps(exp_info, ensure_ascii=False), player_id))
    plan_remember_exp()
예제 #7
0
 def get_all_alliances() -> ['Alliance']:
     request = "select id from alliances order by id asc"
     cursor.execute(request)
     return list(
         map(lambda alliance_id: Alliance.get_alliance(alliance_id[0]),
             cursor.fetchall()))
예제 #8
0
 def get_alliance_locations(self) -> ['AllianceLocation']:
     request = "select id from alliance_locations where owner_id = %s and expired is false"
     cursor.execute(request, (self.id, ))
     return list(
         map(lambda loc_id: AllianceLocation.get_location(loc_id[0]),
             cursor.fetchall()))
예제 #9
0
 def get_alliance_guilds(self):
     request = "select guild_id from guilds where alliance_id = %s"
     cursor.execute(request, (self.id, ))
     return list(
         map(lambda guild_id: Guild.get_guild(guild_id[0]),
             cursor.fetchall()))
예제 #10
0
 def get_active_locations() -> ['AllianceLocation']:
     request = "select id from alliance_locations where expired is false"
     cursor.execute(request)
     rows = cursor.fetchall()
     return list(
         map(lambda loc_id: AllianceLocation.get_location(loc_id[0]), rows))