Ejemplo n.º 1
0
def ga(bot, update):
    alliances = Alliance.get_all_alliances()
    res = "🎪Альянс:\n  |—🗺Локация | битв удерживается\n⚠ - Локация могла истечь\n" \
          "----------------------------------------\n\n"
    res_end = ""
    player = Player.get_player(update.message.from_user.id)
    alliance = Alliance.get_player_alliance(player)
    for cur_alliance in alliances:
        locations = cur_alliance.get_alliance_locations()
        if locations:
            res += cur_alliance.format()
            for location in locations:
                res += "  |—{} | {}\n".format(location.format_link_view(alliance, new_line=False),
                                              location.turns_owned)
            res += "\n"
        else:
            res_end += cur_alliance.format()
    res += res_end
    bot.send_message(chat_id=update.message.chat_id, text=alliance.add_flag_to_name(res), parse_mode='HTML')
Ejemplo n.º 2
0
def add_alliance_location(bot, update):
    mes = update.message
    player, guild, alliance = get_player_and_guild_and_alliance(mes.from_user.id)
    try:
        parse = re.search("simple combination: (\\w+)", mes.text)
        link = parse.group(1)

        parse = re.search("You found hidden (location (.+) lvl.(\\d+)|headquarter (.+))", mes.text)
        if parse.group(4) is not None:
            return add_alliance_link(parse.group(4), link)
        name, lvl = parse.group(2), int(parse.group(3))

    except Exception:
        logging.error(traceback.format_exc())
        if filter_is_pm(mes):
            bot.send_message(chat_id=mes.chat_id, text="Произошла ошибка")
        return
    request = "select id from alliance_locations where link = %s and expired is false"
    cursor.execute(request, (link,))
    row = cursor.fetchone()
    if row is not None:
        return
    request = "select id from alliance_locations where name = %s and lvl = %s and link is null " \
              "and expired is false limit 1"
    cursor.execute(request, (name, lvl))
    row = cursor.fetchone()
    if row is not None:
        location = AllianceLocation.get_location(row[0])
        location.link = link
        location.update()
    else:
        location = AllianceLocation(None, link, name, None, lvl, None, 0, False, False)
        location.figure_type()
        location.insert_to_database()
    for alli in Alliance.get_all_alliances():
        if alli.hq_chat_id is not None:
            bot.send_message(chat_id=alli.hq_chat_id, parse_mode='HTML',
                             text="Новая локация: <b>{} Lvl.{}</b>\n{}".format(name, lvl, link))
    bot.send_message(chat_id=mes.chat_id, text="Спасибо! Новая локация!", reply_to_message_id=mes.message_id)