async def btm(query: types.CallbackQuery): answer_data = query.data if answer_data == "back_to_main": query.answer("....") await query.message.edit_text("Welcome", reply_markup=main_markup()) else: query.answer("oops Error :(")
async def calendar_notification_watch_handler(query: CallbackQuery, callback_data: dict): user_id = query.from_user.id episode_id = callback_data['id'] prev_watched = callback_data.get('watched') == '1' store = Storage.get_current() sess, user_pref = await asyncio.gather(trakt_session(user_id), store.get_pref(user=user_id)) on_watch = user_pref.get('on_watch', 'hide') watched = await sess.watched(episode_id) # if message was created more than 48 hours ago then it cannot be deleted now = datetime.now() delta = now - query.message.date if on_watch == 'delete' and delta >= timedelta(hours=48): warn = await query.message.reply( "quick note: bot cannot delete messages older then 48 hours", disable_notification=True) asyncio.create_task(postponed_delete(warn, delay=5)) on_watch = 'hide' # delete message if it is marked as watched if on_watch == 'delete': watched = await toggle_watched_status(sess, episode_id, watched) if watched: logger.debug("episode is watched and on_watch=delete") await asyncio.gather( store.update_data(user=user_id, data={'deleted_episode': episode_id}), query.message.delete(), query.answer("added to history"), ) return # sync with current watch status else: if watched is prev_watched: watched = await toggle_watched_status(sess, episode_id, watched) else: msg = 'watched' if watched else 'unwatched' logger.debug(f"user already marked this as {msg}") se = await sess.search_by_episode_id(episode_id, extended=True) logger.debug(se) # update keyboard hide = on_watch == 'hide' markup = await CalendarNotification.markup(se, watched, hide=hide) await asyncio.gather( query.message.edit_text(query.message.html_text, reply_markup=markup, disable_web_page_preview=hide and watched), query.answer( "added to history" if watched else "removed from history"), )
async def show_watch_btn(c: CallbackQuery): kp_id: int = int(c.data.split('|')[1]) film = await hdvb.find_by_kp_id(kp_id) if film.kinopoisk_id: views_counter.increment_day_views() await c.bot.edit_message_reply_markup( chat_id=c.from_user.id, message_id=c.message.message_id, reply_markup=templates.btn_search_film(film.iframe_url, film.kinopoisk_id, more_btn=False)) await hdvb.up_film_rating(film) else: c.answer('Ошибка')
async def modify_message(query: CallbackQuery): """ That's how `Markup` and `Markdown` buttons work Basically it edits message just changing its parse_mode """ message = query.message if query.data == SHOW_FORMATTED: bot.parse_mode = detect_message_text_formatting(message) markup = SHOW_RAW_MARKUP new_text = message.text else: markup = SHOW_FORMATTED_MARKUP to_html = query.data == SHOW_RAW_HTML with dont_change_plain_urls: bot.parse_mode = 'html' if to_html else 'markdown' # https://github.com/aiogram/aiogram/pull/205/ new_text = message.html_text if to_html else message.md_text bot.parse_mode = None answer_callback = asyncio.create_task( query.answer()) # remove 'Loading...' on user side quickly try: await message.edit_text(new_text, disable_web_page_preview=True, reply_markup=markup) except CantParseEntities as e: answer_callback.cancel() await query.answer(str(e), show_alert=True) except MessageNotModified: answer_callback.cancel() await query.answer('Message has no formatting') else: await answer_callback
async def update_boolean(query: types.CallbackQuery, callback_data: Dict[str, str], state: FSMContext): poi = (await state.get_data())['poi'] attr = callback_data['attr'] svalue = callback_data['value'] if svalue == 'null': value = None else: value = svalue == 'true' if attr == 'wifi': poi.has_wifi = value elif attr == 'cards': poi.accepts_cards = value else: query.answer(f'Unknown field {attr}') await delete_msg(query) await state.set_data({'poi': poi}) await EditState.confirm.set() await print_edit_options(query.from_user, state)
async def help_(query: types.CallbackQuery): answer_data = query.data query.answer("welcome ...") if answer_data == "help_cb": await bot.send_message(query.from_user.id, """ well hi {} iam TyNy bot Im here to manage your groups \n\n Notice : DO NOT FORGET TO MAKE ME ADMIN My Commands = /ban => use this to kick someone from your group /mute [time] => use this to mute someone pin => use this to pin a message unpin => use this to unpin your group message unban => use this to unban a banned member :| dice => Fun command group info => shows your group info admins => shows admin groups :/ lock on => it will lock your group ( No one can send message until you unlock it) lock off => it will unlock your group lock content => it will lock the media messages :/ unlock content => it will unlock your contents Link => it will show you your group link world info => shows some information about corona virus and BTC Price and ..... HOPE YOU ENJOY =) """.format(query.from_user.first_name), reply_markup=back_to_first()) elif answer_data == "ad_cb": await bot.send_message(query.from_user.id, """ Developed by iPzX @iPzXx source = https://github.com/ipzx/TyNy-bot """, reply_markup=back_to_first())
def callback(call: CallbackQuery): """Callback's handler.""" call.answer(cache_time=6) callback_data = call.data logging.info(f'{callback_data=}') return callback_data