Ejemplo n.º 1
0
def get_mobs_info_by_link(link):
    cursor = conn.cursor()
    request = "select mob_names, mob_lvls, date_created, helpers, buffs, minutes, created_player from mobs where link = %s"
    cursor.execute(request, (link,))
    row = cursor.fetchone()
    cursor.close()
    return row
def rangers_notify_start(bot, update):
    cursor = conn.cursor()
    time_to_battle = get_time_remaining_to_battle()
    print("time_to_battle", time_to_battle)
    try:
        callback_chat_id = update.message.chat_id
    except AttributeError:
        try:
            callback_chat_id = int(update)
        except TypeError:
            return
    count = 0
    request = "select id from players where class_skill_lvl is not NULL"
    cursor.execute(request)
    row = cursor.fetchone()
    while row is not None:
        player = Player.get_player(row[0])
        if player is None:
            row = cursor.fetchone()
            continue
        if player.settings is not None and player.settings.get(
                "rangers_notify") is False:
            row = cursor.fetchone()
            continue
        guild = Guild.get_guild(guild_id=player.guild)
        if guild is None:
            row = cursor.fetchone()
            continue
        telegram_username = player.username
        username = player.nickname
        class_skill_lvl = player.class_skill_lvl
        context = [telegram_username, username, guild.chat_id]
        print(class_skill_lvl)
        time_to_aim_mins = ranger_aiming_minutes[class_skill_lvl] if \
            class_skill_lvl < len(ranger_aiming_minutes) else 40

        time_to_aim = datetime.timedelta(minutes=time_to_aim_mins)
        print("time_to_aim", time_to_aim)
        time_to_notify = time_to_battle - time_to_aim - datetime.timedelta(
            minutes=1)
        print(time_to_notify)
        # time_to_notify = datetime.timedelta(minutes=1)    # TEST
        if time_to_notify >= datetime.timedelta(minutes=0):
            job.run_once(ranger_notify, time_to_notify, context=context)

        row = cursor.fetchone()
        count += 1
    cursor.close()
    bot.send_message(
        chat_id=callback_chat_id,
        text="Запланировано оповещение <b>{0}</b> бедных лучников".format(
            count),
        parse_mode='HTML')
Ejemplo n.º 3
0
def load_worldtop(battle_id: int = None) -> dict:
    """
    Загружает /worldtop после битвы с battle_id
    :return: { str: int }
    """
    if battle_id is None:
        battle_id = count_battle_id()
    cursor = conn.cursor()
    request = "select ferma, amber, oplot, rassvet, tortuga, night, skala from worldtop where battle_id = %s"
    cursor.execute(request, (battle_id, ))
    row = cursor.fetchone()
    if not row:
        return {}
    worldtop = {k: v for k, v in zip(castles, row)}
    sort_worldtop(worldtop)
    cursor.close()
    return worldtop
Ejemplo n.º 4
0
def save_worldtop(worldtop: dict, battle_id: int = None):
    cursor = conn.cursor()
    try:
        if battle_id is None:
            battle_id = count_battle_id()
        request = "insert into worldtop(battle_id, "
        args = [battle_id]
        for k, v in list(worldtop.items()):
            request += "{}, ".format(emodji_to_castle_names.get(k))
            args.append(v)
        request = request[:-2] + ')' + 'values(%s, %s, %s, %s, %s, %s, %s, %s)'
        cursor.execute(request, args)
    except psycopg2.IntegrityError:
        request = "update worldtop set "
        for k, v in list(worldtop.items()):
            request += "{} = {}, ".format(emodji_to_castle_names.get(k), v)
        request = request[:-2] + " where battle_id = {}".format(battle_id)
        cursor.execute(request)
    except Exception:
        logging.error(traceback.format_exc())
    cursor.close()