def go_to_previous_step(client: TopUpGifter, query: CallbackQuery): user_id = str(query.from_user.id) user_info = dict(client.users.find_one(id=user_id)) user = User(user_info) query_data = query.data.split(',') user.state = State.get_previous_state(user.state) user.last_interaction = datetime.now() client.users.update(user.to_dict(), ['id']) client.db.commit() query.continue_propagation()
async def notify_callback(bot: Amime, callback: CallbackQuery): content_type = callback.matches[0]["c_type"] content_id = int(callback.matches[0]["c_id"]) recipient_type = callback.matches[0]["r_type"] recipient_id = int(callback.matches[0]["r_id"]) message = callback.message chat = message.chat user = callback.from_user lang = callback._lang if recipient_type == "group": if not await filters.administrator(bot, callback): return elif content_type == "episodes": callback.continue_propagation() notify = await Notify.get_or_none( recipient=recipient_id, recipient_type=recipient_type, item=content_id, type=content_type, ) if notify is None: await Notify.create( recipient=recipient_id, recipient_type=recipient_type, item=content_id, type=content_type, ) await callback.answer(lang.notifications_linked_alert, show_alert=True) else: await notify.delete() await callback.answer(lang.notifications_turned_off_alert, show_alert=True) keyboard = bki(message.reply_markup) for line, column in enumerate(keyboard): for index, button in enumerate(column): if button[1].startswith("notify"): keyboard[line][index] = await get_notify_button( lang, user if recipient_type == "user" else chat, content_type, content_id, ) await callback.edit_message_reply_markup(ikb(keyboard))