Beispiel #1
0
def get_item_code_by_name(name):
    name = name.lower()
    max_len = len(list(items.values())[-1])
    for num, elem in list(items.items()):
        if elem[1].lower() in name:
            code = "k" + num
            if len(elem) == max_len:
                code = "k" + elem[-1]
            return code
        elif elem[0].lower() in name and "recipe" in name:
            code = "r" + num
            if len(elem) == max_len:
                code = "r" + elem[-2]
            return code
        else:
            continue
    item = get_equipment_by_name(name)
    if item is not None:
        return item.type + item.code
    item = alch_recipes.get(name.lower())
    if item is not None:
        return item.get("code")
    item = get_resource_code_by_name(name)
    # print(name, item)
    return item
Beispiel #2
0
def get_item_name_by_code(code):
    try:
        item = get_equipment_by_code(code)
        if item is not None:
            return item.name
        item = resources_reverted.get(code)
        if item is not None:
            return item
        if code[0] in {"k", "r"}:
            item = items.get(code[1:])
            if code[0] == 'k':
                return item[1]
            if code[0] == 'r':
                max_len = len(list(items.values())[-1])
                if len(item) < max_len:
                    return item[0] + " recipe"
                for item_code, item in list(items.items()):
                    if len(item) < max_len:
                        if item_code == code[1:]:
                            return item[0] + " recipe"
                    else:
                        if item[-2] == code[1:]:
                            return item[0] + " recipe"
        if code[0] == "p":
            for name, potion in list(alch_recipes.items()):
                if potion.get("code") == code:
                    return name
        return code
    except Exception:
        logging.error(traceback.format_exc())
        return code
def get_possible_text(stock, tier: int = None) -> str:
    can_craft, possible_craft = [], []
    for short_code, item in list(items.items()):
        eq = get_equipment_by_name(item[0])
        if eq is None:
            continue
        parts_count = stock.get("k" + short_code, 0)
        recipes_count = stock.get("r" + short_code, 0)
        need_parts = max(0, item[2] - parts_count) + 1 - min(1, recipes_count)
        craft_count = min(recipes_count, parts_count // item[2])
        if eq is None:
            logging.warning("Equipment is None for {}".format(item[0]))
            continue
        if tier is not None and eq.tier != tier:
            continue
        if need_parts == 0:
            can_craft.append([need_parts, eq, craft_count])
        else:
            possible_craft.append(
                [need_parts, eq, recipes_count, parts_count, item[2]])
    can_craft.sort(key=lambda x: (-x[1].tier, x[1].name))
    possible_craft.sort(key=lambda x: (x[0], (-x[1].tier, x[1].name)))
    res = "Экипировка, которую можно скрафтить:\n"
    for item in can_craft:
        res += "{}{} x {}: /craft_{}\n".format(item[1].get_tier_emoji(),
                                               item[1].name, item[2],
                                               item[1].format_code())
    res += "\nНемного не хватает:\n"
    for item in possible_craft[:POSSIBLE_LIMIT]:
        res += "{}{} - {}📄 {}/{}🔩\n".format(item[1].get_tier_emoji(),
                                            item[1].name, item[2], item[3],
                                            item[4])
    return res
 def get_item(self):
     lower_name = self.name.lower()
     for short_code, item in items.items():
         if lower_name == item[0].lower():
             self.recipe_code = "r" + (short_code if len(item) < len(
                 list(items.values())[-1]) else item[-2])
             self.part_code = "k" + (short_code if len(item) < len(
                 list(items.values())[-1]) else item[-1])
             return item
     return None
def deposit(bot, update):
    mes = update.message
    if mes.text == "/deposit":
        if mes.reply_to_message is None:
            return
        mes = mes.reply_to_message
    response = "<b>Ресурсы на складе:</b>\n<em>Нажмите на ресурс, чтобы внести в гильдию</em>\n\n"
    num = 0
    for string in mes.text.splitlines():
        # parse = re.search("/aa_(\\d+)", string)
        parse = re.search("/lot_(\\S+) (.*) \\((\\d+)\\)", string)
        if parse is not None:
            # Кинут аукцион
            code = parse.group(1)
            res_name = parse.group(2)
            count = int(parse.group(3))
        else:
            parse = re.search("(.*) \\((\\d+)\\) /(use|view)_(.+)", string)
            if parse is not None:
                # Кинут misc
                code = parse.group(4)
                if code[-1] == ' ':
                    # Обрезаем последний пробел, найс чв вообще прогали, тупо пробел в конце строки
                    code = code[:-1]
                res_name = parse.group(1)
                count = int(parse.group(2))
            else:
                # Кинут сток
                parse = re.search("(/sg_\\d+ )?(.*) \\((\\d+)\\)", string)
                if parse is None:
                    continue
                res_name = parse.group(2)
                count = int(parse.group(3))
                code = resources.get(res_name)
        if code is None:
            for num, elem in list(items.items()):
                if res_name == elem[1]:
                    code = "k" + num
                elif elem[0] in res_name:
                    code = "r" + num
                else:
                    continue
        if code is None:
            continue
        response += "<a href=\"https://t.me/share/url?url=/g_deposit {} {}\">{} x {}</a>\n".format(
            code, count, res_name, count)
        num += 1
        if num % 5 == 0:
            response += "\n"
    bot.send_message(chat_id=mes.chat_id, text=response, parse_mode='HTML')
def get_gs_craft_text(guild, tier=None) -> str:
    response = "Крафт в стоках игроков {}:\n".format(guild.format())
    for short_code, item in list(items.items()):
        eq = get_equipment_by_name(item[0])
        if eq is None or (tier is not None and tier != eq.tier):
            continue
        part_code = eq.part_code
        recipe_code = eq.recipe_code
        part_count, recipe_count = 0, 0
        for player in guild.get_members():
            recipe_count += player.stock.get(recipe_code, 0)
            part_count += player.stock.get(part_code, 0)
        if part_count or recipe_count:
            response += "{}{} {}📄 {}🔩 /gs_ap{}\n".format(
                eq.get_tier_emoji(), eq.name, recipe_count, part_count,
                eq.format_code())
    return response
Beispiel #7
0
def get_item_code_by_name(name):
    name = name.lower()
    for num, elem in list(items.items()):
        if name == elem[1].lower():
            code = "k" + num
            return code
        elif elem[0].lower() in name and "recipe" in name:
            code = "r" + num
            return code
        else:
            continue
    item = get_equipment_by_name(name)
    if item is not None:
        return item.type + item.code
    item = alch_recipes.get(name.lower())
    if item is not None:
        return item.get("code")
    item = get_resource_code_by_name(name)
    # print(name, item)
    return item
def send_withdraw(bot, update, *args):
    manual = False
    if args and args[0] == "custom_request":
        manual = True
        give = args[1]
        chat_id = update
        player = Player.get_player(chat_id)
    else:
        chat_id = update.message.chat_id
        player = Player.get_player(update.message.from_user.id)
        give = {}
    mes = update.message if not isinstance(update, int) else None
    response, response_full = "/g_withdraw ", "/g_withdraw "
    res_count = 0
    if player is None:
        return
    guild_stock = None
    if player.guild is not None:
        guild = Guild.get_guild(guild_id=player.guild)
        if guild.settings is not None:
            if guild.settings.get("withdraw") is False:
                if guild.chat_id == mes.chat_id:
                    return
        guild_stock = guild.api_info.get("stock")
    if manual:
        pass
    elif "дай" in mes.text.lower():
        # Выдача ресурсов по Дай x y
        potions_dict = {
            "фр": ["p01", "p02", "p03"],
            "фд": ["p04", "p05", "p06"],
            "грид": ["p07", "p08", "p09"],
            "натуру": ["p10", "p11", "p12"],
            "ману": ["p13", "p14", "p15"],
            "твайлайт": ["p16", "p17", "p18"],
            "морф": ["p19", "p20", "p21"]
        }
        parse = mes.text.lower().split()[1:]
        mode = "name"
        names = []
        for string in parse:
            if mode == "quantity":
                mode = "name"
                try:
                    quantity = int(string)
                    if quantity > 0:
                        if not names:
                            continue
                        for name in names:
                            give.update({name: quantity})
                        continue
                except ValueError:
                    pass
            if mode == "name":
                mode = "quantity"
                potions = potions_dict.get(string)
                if potions is None:
                    if string not in list(resources) and string not in list(equipment_names) and string not in \
                            list(resources_reverted) and re.match("[rk]\\d\\d?", string) is None:
                        mode = "name"
                        continue
                    names = [
                        string
                    ]  # Список из имён, к которым далее следует количество для выдачи
                    give.update({string: 1})
                else:
                    names = []
                    for p in potions:
                        give.update({p: 1})
                        names.append(p)
    else:
        for string in update.message.text.splitlines():
            if "Нет нужных материалов" in mes.text:
                parse = re.search("([^\n$]+) x (\\d+)", string)
                if parse is None:
                    continue
                count = int(parse.group(2))
                name = parse.group(1)
                code = resources.get(name)
            else:
                parse = re.search("(\\d+) x ([^\n$]+)", string)
                if parse is None:
                    continue
                count = int(parse.group(1))
                name = parse.group(2)
                code = resources.get(name)
            if code is None:
                for num, elem in list(items.items()):
                    if name.lower() == elem[1].lower():
                        code = "k" + num
                    elif elem[0].lower() in name.lower():
                        code = "r" + num
                    else:
                        continue
            if code is None:
                continue
            give.update({code: count})
    not_enough = ""
    for code, count in list(give.items()):
        if guild_stock is not None:
            # Есть данные о стоке, проверка наличия ресурсов
            in_stock = guild_stock.get(code) or 0
            if in_stock > 0:
                response += "{} {} ".format(code, min(count, in_stock))
            if in_stock < count:
                not_enough += "{} x {}\n".format(get_item_name_by_code(code),
                                                 count - in_stock)
        response_full += "{} {} ".format(code, count)
        res_count += 1
        if res_count >= 8:
            response = format_all_withdraws(response, response_full,
                                            not_enough)
            bot.send_message(chat_id=chat_id, text=response, parse_mode='HTML')
            response, response_full, not_enough = "/g_withdraw ", "/g_withdraw ", ""
            res_count = 0
    if res_count > 0:
        response = format_all_withdraws(response, response_full, not_enough)
        bot.send_message(chat_id=chat_id, text=response, parse_mode='HTML')