async def gold(mes: Message): #journal_log(mes) if not uc.select(**{'id': mes.from_user.id, 'guild_tag': 'AT'}): await mes.answer('Доступ запрещён.') return load = await mes.answer('Запрашиваю, подожди./⏳') await load.edit_text('Запрашиваю, подожди../⌛') await load.edit_text('Запрашиваю, подожди.../⏳') await main_client.connect() conv_answer_list = {} async with main_client.conversation(CW_BOT_ID) as conv: for i, req in enumerate(['/ws_MYdnt', '/ws_MYdnt_stand']): time.sleep(float(str(random.uniform(1, 3))[0:4])) await conv.send_message(req) conv_answer_list[str(i)] = await conv.get_response() await main_client.disconnect() mana = re.search(r'\w*/\w+', conv_answer_list.get('0').message).group(0) cost = re.search(r'Steel mold, 15💧 (\d+)', conv_answer_list.get('1').message).group(1) rand_price = str(random.randint(1, 999)) open = 'Открыто✅' if 'Studio is открыто.' in conv_answer_list.get( '0').message else 'Закрыто🚫' await load.edit_text(GOLD_TEXT.format(cost, rand_price, open, mana))
async def change_cost(mes: Message): #journal_log(mes) if not uc.select(**{'id': mes.from_user.id, 'guild_tag': 'AT'}): await mes.answer('Доступ запрещён.') return load = await mes.answer('Меняю цену, подожди./⏳') await load.edit_text('Меняю цену, подожди../⌛') await load.edit_text('Меняю цену, подожди.../⏳') cc = re.search(r'(\d+)', mes.text[4:]).group(1) if not 1 < int(cc) < 1000: await load.edit_text('Недоступная цена.') return await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: time.sleep(float(str(random.uniform(1, 3))[0:4])) await conv.send_message('/s_695_add 27 ' + cc) cc_report = await conv.get_response() await main_client.disconnect() if 'Steel mold, 15💧 {}💰'.format(cc) in cc_report.message: txt = 'Меняю цену, подожди.../⌛\nУспех! Установленная цена {}💰!'.format( cc) else: txt = 'Меняю цену, подожди.../⌛\nПровал! Что-то не так.' await load.edit_text(txt)
async def guild_stock_refresh(mes: Message): #journal_log(mes) if mes.chat.type != 'private': return load = await mes.answer('Запрашиваю, подожди./⏳') await load.edit_text('Запрашиваю, подожди../⌛') await load.edit_text('Запрашиваю, подожди.../⏳') stock_result = [] await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: for x in ['/g_stock_res', '/g_stock_parts', '/g_stock_rec']: await conv.send_message(x) y = await conv.get_response() stock_result.append(y.message) time.sleep(1) await main_client.disconnect() guild_stock.pools_input(stock_result) guild_res_pool = guild_stock.guild_res_pool text = '<b>Сток гильдии обновлён!</b>' for key in guild_res_pool: text += f'\n<code>{key}</code> {guild_res_pool[key][0]} x {guild_res_pool[key][1]}' await load.edit_text(text, reply_markup=stock_keyboard)
async def g_receive_and_deposit(mes: Message): if mes.chat.type != 'private': return await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: await conv.send_message(mes.text) answer = await conv.get_response() await mes.answer('<b>CW:</b>\n' + answer.message) await main_client.disconnect()
async def irren_interface(mes: Message): if mes.chat.type != 'private': return await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: await conv.send_message('🏅Герой') answer = await conv.get_response() await main_client.disconnect() await mes.answer(f'<b>CW:</b>\n{answer.message}', reply_markup=interface_menu) await craft_states.Q2.set()
async def crafting(mes: Message): if mes.chat.type != 'private': return try: await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: await conv.send_message(mes.text) answer = await conv.get_response() await main_client.disconnect() if 'Не хватает материалов для крафта' in answer.message: f_list = {} for string in answer.message.splitlines(): parse = re.search(r'(\d+) x ([^\n$]+)', string) if parse is None: continue count = int(parse.group(1)) name = parse.group(2) f_list[name] = count res = "select * from craft where Name in ('{}')" res_q = res.format("', '".join(f_list.keys())) res_r = mes.db.checkall(res_q, []) r_text = '<b>Запрос:</b>\n' s_text = '/g_withdraw' guild_pool = guild_stock.guild_pool guild_res_pool = guild_stock.guild_res_pool for item in res_r: try: if int(f_list.get(item[1])) <= int( guild_pool.get(item[0])[1]): r_text += f'✅ <code>{item[0]}</code> {item[1]} x {f_list.get(item[1])}\n' else: r_text += f'❌ <code>{item[0]}</code> {item[1]} x {guild_res_pool.get(item[0])[1]}/{f_list.get(item[1])}\n' except: r_text += f'❌ <code>{item[0]}</code> {item[1]} x 0/{f_list.get(item[1])}\n' s_text += f' {item[0]} {f_list.get(item[1])}' mes.db.query( 'UPDATE settings SET info = ? WHERE name = "last_craft"', [r_text]) mes.db.query( 'UPDATE settings SET info = ? WHERE name = "last_craft_url"', [s_text]) await mes.answer(f'<b>CW:</b>\n{answer.message}\n\n{r_text}', reply_markup=crafting_keyboard(s_text)) else: await mes.answer(f'<b>CW:</b>\n{answer.message}') except: await mes.answer('<b>Обновите сток гильдии, пожалуйста!</b>\n')
async def irren_interface_adv(mes: Message): if mes.chat.type != 'private': return move_keyboard_dict = { '🏅Герой': interface_menu, '🏰Замок': interface_castle_menu, '🛎Аукцион': interface_castle_menu, '⚖️Биржа': interface_castle_menu, '/inv': interface_inv_menu } keyboard = move_keyboard_dict.get(mes.text, int_menu) await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: await conv.send_message(mes.text) answer = await conv.get_response() await main_client.disconnect() await mes.answer('<b>CW:</b>\n' + answer.message, reply_markup=keyboard)
async def open_shop(mes: Message): #journal_log(mes) if not uc.select(**{'id': mes.from_user.id, 'guild_tag': 'AT'}): await mes.answer('Доступ запрещён.') return load = await mes.answer('Попробую открыть, подожди./⏳') await load.edit_text('Попробую открыть, подожди../⌛') await load.edit_text('Попробую открыть, подожди.../⏳') await main_client.connect() async with main_client.conversation(CW_BOT_ID) as conv: time.sleep(float(str(random.uniform(1, 3))[0:4])) await conv.send_message('/myshop_open') answer = await conv.get_response() await main_client.disconnect() if "It's OPEN now." in answer.message: txt = 'Попробую открыть, подожди.../⏳\nУспех! Заходи!' else: txt = 'Попробую открыть, подожди.../⏳\nПровал! Подожди около 5 минут...' await load.edit_text(txt)
async def trade(mes: Message): #journal_log(mes) if mes.chat.type != 'private': return if not uc.select(**{'id': mes.from_user.id, 'guild_tag': 'AT'}): await mes.answer('Доступ запрещён.') return load = await mes.answer('Запрашиваю, подожди./⏳') await load.edit_text('Запрашиваю, подожди../⌛') await load.edit_text('Запрашиваю, подожди.../⏳') res = uc.select_id(mes.from_user.id).get('trade') if not res: await load.edit_text(TRADE_ANSWER_TEXT.format('Пусто')) return herb_text = '' herb_list = res.split(' ') await main_client.connect() for el in herb_list: async with main_client.conversation(CW_BOT_ID) as conv: time.sleep(float(str(random.uniform(1, 2))[0:4])) await conv.send_message('/t_' + str(el)) answer = await conv.get_response() try: cost = re.search(r'шт. по (\d+)', answer.message).group(1) name = re.search(r'Предложения (\D+) сейчас:', answer.message).group(1) except: x = 'В правилах введён недоступный ресурс.\nПожалуйста поменяйте правило через /gs id, либо обратитесь к @Irrenriel.' await load.edit_text(x) return herb_text += f'<code>{el}</code> | {name} | <a href="https://t.me/share/url?url=/wtb_{el}">{cost}💰</a>\n' await main_client.disconnect() await load.edit_text(TRADE_ANSWER_TEXT.format(herb_text))
async def loc_check_f(mes: Message): #journal_log(mes) if not uc.check_perm_role(mes.from_user.id, [2, 3, 4]): await mes.answer('Доступ запрещён.') return if mes.from_user.id != ADMIN: now = datetime.datetime.now() now_str = now.strftime('%Y-%m-%d-%H-%M-%S') last_update = mes.db.check( 'SELECT info FROM settings WHERE name = "last_l_check_datetime"') if last_update and last_update[0]: lu = last_update[0].split('-') td = datetime.timedelta(hours=7, minutes=59) lu_date = datetime.datetime(year=int(lu[0]), month=int(lu[1]), day=int(lu[2]), hour=int(lu[3]), minute=int(lu[4]), second=int(lu[5])) if now - lu_date < td: l = await mes.answer( f'Не доступно! Запрещено до {lu_date + td}.\nДля экстренной проверки обратитесь к @Irrenriel.' ) await asyncio.sleep(2) await mes.delete() await asyncio.sleep(3) await l.delete() return else: mes.db.query( 'UPDATE settings SET info = ? WHERE name = "last_l_check_datetime"', [now_str]) else: mes.db.query( 'UPDATE settings SET info = ? WHERE name = "last_l_check_datetime"', [now_str]) await mes.answer('Выполняется, жди...') err = "Strange fog is so dense that you can't reach this place." text = 'Истёкшие локации!\n\n' req = 'SELECT code FROM loc WHERE lvl != 99' if mes.text.startswith( '/l_chk') else 'SELECT code FROM loc' locs = mes.db.checkall(req) result = [] await main_client.connect() for loc in locs: if loc[0].startswith('NoneCode'): continue async with main_client.conversation(CW_BOT_ID) as conv: time.sleep(float(str(random.uniform(1, 3))[0:4])) await conv.send_message('/ga_atk_' + loc[0]) ga_atk_answer = await conv.get_response() if ga_atk_answer.message == 'Ты сейчас занят другим приключением. Попробуй позже.' or 'Ветер завывает по окрестным лугам, замки как будто вымерли. Это воины зашивают раны и латают доспехи после тяжелой битвы. Ближайшие несколько минут все учреждения и ворота замка закрыты. Жди сводки с полей в @ChatWarsDigest.': await mes.answer( 'Мы сейчас заняты другим приключением. Попробуйте позже.') return if ga_atk_answer.message == err: time.sleep(float(str(random.uniform(1, 3))[0:4])) await conv.send_message('/ga_def_' + loc[0]) ga_def_answer = await conv.get_response() if ga_atk_answer.message == err and ga_def_answer.message == err: req = mes.db.check( 'SELECT name, lvl, code FROM loc WHERE code = ?', [loc[0]]) answer = LOC_TYPES.get(req[0].split(' ')[-1], '🎪 ') + req[0] + ( "" if req[1] == 99 else " lvl. " + str(req[1])) result.append('<b>{}</b>\n └ <code>{}</code>'.format( answer, req[2])) mes.db.query('DELETE FROM loc WHERE code = ?', [loc[0]]) mes.db.query('DELETE FROM loc_buff_info WHERE code = ?', [loc[0]]) if not mes.text.startswith('/l_chk'): mes.db.query('DELETE FROM al_guild_info WHERE code = ?', [loc[0]]) chats = mes.db.checkall('SELECT id FROM chats WHERE delete_loc_ntf = 1', []) if not chats and not result: await mes.answer('Done!') return for chat in chats: try: await bot.send_message(chat[0], text + '\n\n'.join(result)) except: pass await asyncio.sleep(0.3) await mes.answer('Done!') mes.db.query('UPDATE settings SET info = ? WHERE name = "last_l_check"', [str(datetime.datetime.today().strftime('%d.%m.%Y %H:%M'))]) async with main_client.conversation(CW_BOT_ID) as conv: time.sleep(float(str(random.uniform(1, 3))[0:4])) await conv.send_message('/myshop_open') await main_client.disconnect()