class MainMenuDialog(BaseDialog): @message_handler(commands='start,lang', state='*') async def entry_point(self, message: Message): await self.deps.broadcaster.register_user(message.from_user.id) loc_man = self.deps.loc_man if message.get_command(pure=True) == 'lang' or await loc_man.get_lang( message.from_user.id, self.deps.db) is None: await SettingsDialog(self.loc, self.data, self.deps).ask_language(message) else: info = await ThorInfo.get_old_cap(self.deps.db) await message.answer(self.loc.welcome_message(info), reply_markup=self.loc.kbd_main_menu(), disable_notification=True) await MainStates.MAIN_MENU.set() @message_handler(commands='cap', state='*') async def cmd_cap(self, message: Message): await MetricsDialog(self.loc, self.data, self.deps).show_cap(message) @message_handler(commands='price', state='*') async def cmd_price(self, message: Message): await MetricsDialog(self.loc, self.data, self.deps).show_price_info(message) @message_handler(commands='help', state='*') async def cmd_help(self, message: Message): await message.answer(self.loc.help_message(), disable_web_page_preview=True, disable_notification=True) @message_handler(filters.RegexpCommandsFilter(regexp_commands=[r'/.*']), state='*') async def on_unknown_command(self, message: Message): await message.answer(self.loc.unknown_command(), disable_notification=True) @message_handler(state=MainStates.MAIN_MENU) async def on_main_menu(self, message: Message): if message.text == self.loc.BUTTON_MM_METRICS: message.text = '' await MetricsDialog(self.loc, self.data, self.deps).on_enter(message) elif message.text == self.loc.BUTTON_MM_MY_ADDRESS: message.text = '' await StakeDialog(self.loc, self.data, self.deps).on_enter(message) elif message.text == self.loc.BUTTON_MM_SETTINGS: message.text = '' await SettingsDialog(self.loc, self.data, self.deps).on_enter(message) elif message.text == self.loc.BUTTON_MM_MAKE_AVATAR: await AvatarDialog(self.loc, self.data, self.deps).on_enter(message) else: return False
def _construct(self, *args, **kwargs): super(TeleRemBot, self)._construct(*args, **kwargs) if self.params.auth_secret is None: raise AttributeError("AUTH_SECRET not specified") self.totp = pyotp.TOTP(self.params.auth_secret) self.user_whitelist = [self.params.username] self.user_id_whitelist = [self.params.user_id] self.chat_id_whitelist = [] # Initialize bot and dispatcher self.bot = Bot(token=self.params.api_token) self.dp = Dispatcher(self.bot) self.dp.register_message_handler( self.cmd_auth, filters.RegexpCommandsFilter(regexp_commands=[REX_AUTH])) self.dp.register_message_handler( self.cmd_do_execute, filters.RegexpCommandsFilter(regexp_commands=[REX_DO])) self.dp.register_message_handler(self.default_message_handler)
dp.register_message_handler( sections, lambda c: c.text == '🏛Штаб [AT]' and c.chat.type == 'private') # /hero dp.register_message_handler( hero_refresh, lambda c: "🎉Достижения: /ach" in c.text and c.forward_from.id == CW_BOT_ID) # Закрыть Инлайн Клавиатуру dp.register_callback_query_handler(callback_cancel, text='cancel') # Shop trigger dp.register_message_handler(open_shop, commands=['open_shop']) dp.register_message_handler(gold, commands=['gold']) dp.register_message_handler( change_cost, filters.RegexpCommandsFilter(regexp_commands=['cc_[0-9]+'])) # /top dp.register_message_handler(top, commands=['top']) '''------------------------------------------------------------------------------------------------------------------''' '''<<<----- 🗺LOCATION SECTION ----->>>''' # New Location Input dp.register_message_handler( new_loc, lambda c: "То remember the route you associated it with simple combination:" in c. text and c.forward_from.id == CW_BOT_ID) # Delete Location from Database dp.register_message_handler(loc_del, commands=['l_del']) # /l_list
@dp.message_handler(regexp='(news)') async def stat(message: types.Message): await types.ChatActions.typing() crawler = Crawler() response = crawler.get_response(NEWS) print(message.from_user.full_name) print(message.text) data = response.json()['items'] news_list = [] for news in data: await message.answer(text("[%s](%s)" % (news["title"], news["url"])), parse_mode=ParseMode.MARKDOWN) @dp.message_handler( filters.RegexpCommandsFilter( regexp_commands=['travel_alert_([a-zA-Z]{2,})'])) async def send_welcome(message: types.Message, regexp_command): country_id = f"{regexp_command.group(1)}" if pycountry.countries.get(alpha_2=country_id.upper()): crawler = Crawler() response = crawler.get_response(TA) data = response.json() travel_alert = {} for country in data: if country['countryCode'] == country_id.upper(): travel_alert = country await message.answer( 'Here is the travel alert for %s crawled at : %s \n' '%s' % (travel_alert["countryName"], travel_alert["publishedDate"], travel_alert["alertMessage"].replace("|", ''))) else:
"/lives") else 'https://pancakeswap.info/pair/{}' msg = f"<b>Your live pairs on {chain.name} exchange:</b>\n\n" num = 1 async for gate in LiveGate.filter(chat_id=message.chat.id, alert_type=chain): msg += f"{num}) <a href='{link_tmp.format(gate.pair)}'>{gate.pair[:4]}...{gate.pair[-4:]}</a>\n" \ f"/stop_{gate.id} /start_{gate.id} /delete_{gate.id}\n" num += 1 await bot.send_message(message.chat.id, msg, parse_mode='html', disable_web_page_preview=True) @dp.message_handler( filters.RegexpCommandsFilter( regexp_commands=['stop_([0-9]*)', 'start_([0-9]*)', 'delete_([0-9]*)']) ) async def live_start_stop_delete(message: types.Message): cmd, g_id = message.text.split('_') gate = await LiveGate.get_or_none(id=int(g_id)) if not gate or gate.chat_id != message.chat.id: await bot.send_message(message.chat.id, Lang.gate_not_exist) elif cmd == "/stop": gate.active = False await gate.save() await bot.send_message(message.chat.id, Lang.live_stopped) elif cmd == "/start": gate.active = True await gate.save() await bot.send_message(message.chat.id, Lang.live_started) elif cmd == "/delete":
if other is not None: text.append(f'{row_number}. {choice}\n' f'количество: {amount}\n' f'подробности: {other}\n' f'удалить пожелание - /del{row_number}') else: text.append(f'{row_number}. {choice}\n' f'количество: {amount}\n' f'удалить пожелание - /del{row_number}') res[text[-1][-5:]] = native_id await message.answer('Список твоих пожеланий:\n' + '\n'.join(text)) await state.update_data(res=res) # step 2 @dp.message_handler(filters.RegexpCommandsFilter(regexp_commands=[r'del(\d)+']) ) async def delete_item(message: types.Message, state: FSMContext): check_if_user_exists(message) user_data = await state.get_data() try: session.query(Alcohol).filter( Alcohol.user_id == message.from_user.id, Alcohol.id == user_data['res'][message.text]).one() session.query(Alcohol).filter( Alcohol.id == user_data['res'][message.text]).delete() except NoResultFound: session.query(Food).filter( Food.id == user_data['res'][message.text]).delete() session.commit() await message.answer('Пожелание удалено.')