def alch_possible_craft(bot, update): mes = update.message alch = {} for string in mes.text.splitlines()[1:]: parse = re.search("/aa_(\\d+) .* x (\\d+)", string) if parse is None: continue code = parse.group(1) count = int(parse.group(2)) res = resources_reverted.get(code) alch.update({res.lower(): count}) response = "Зелья и травы, которые можно скрафтить:\n" for name, potion in list(alch_recipes.items()): code = potion.get("code") recipe = potion.get("recipe") craft_count = 999999999 for item, count in list(recipe.items()): has = alch.get(item) or 0 can_craft = has // int(count) if can_craft < craft_count: craft_count = can_craft if craft_count > 0: response += "<a href=\"https://t.me/share/url?url={}\">{} ({})</a>" \ "\n".format("/brew_{} {}".format(code, craft_count), name, craft_count) response += "\n<em>Нажмите на название, чтобы переслать в бота.</em>" bot.send_message(chat_id=mes.chat_id, text=response, parse_mode='HTML')
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 set_withdraw_res(bot, update, user_data, args): mes = update.message found = [] not_found = False response = "Список для выдачи ресурсов обновлён. Текущий список:\n" response_end = "\nНе найдены ресурсы с кодом:\n" for res_code in args: res_name = resources_reverted.get(res_code) if res_name is None: not_found = True response_end += "<b>{}</b>\n".format(res_code) else: if res_code in found: continue found.append(res_code) response += "<b>{}</b>\n".format(res_name) user_data.update({"withdraw_res": found}) if not_found: response += response_end bot.send_message(chat_id=mes.chat_id, text=response, parse_mode='HTML')
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': 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 filter(self, message): return message.forward_from and filter_is_chat_wars_forward(message) and \ filter_is_pm(message) and message.text.find("Guild Warehouse:") == 0 and \ resources_reverted.get(message.text.splitlines()[1].split(" ")[0]) is not None