from datetime import datetime from convopyro import listen_message from pyrogram import filters from pyrogram.types import ( KeyboardButton, Message, ReplyKeyboardMarkup, ReplyKeyboardRemove, ) from classes.pyroclient import PyroClient @PyroClient.on_message( ~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) # type: ignore ) async def command_start(app: PyroClient, message: Message): user = await app.find_user(message.from_user) await message.reply_text(app._("start", "messages", locale=user.locale)) join_code = None if len(message.command) == 1 else message.command[1] if join_code is not None: try: location = await app.get_location(int(join_code)) except ValueError: await message.reply_text( "đŸšĢ You have provided the location but it does not seem to be a valid one. Please, use the command /setup to manually configure the location." ) return keyboard = ReplyKeyboardMarkup( [ [KeyboardButton("Yes, I want to use it")], [KeyboardButton("No, I don't want to use it")], ], resize_keyboard=True, one_time_keyboard=True, ) await message.reply_text( f"ℹī¸ You have started the bot by the link containing a location **{location.name}**.\n\nPlease, confirm whether you want to use it as your location.", reply_markup=keyboard, ) while True: answer = await listen_message(app, message.chat.id, 300) if answer is None or answer.text == "/cancel": await message.reply_text( "Cancelled.", reply_markup=ReplyKeyboardRemove() ) return if answer.text not in [ "Yes, I want to use it", "No, I don't want to use it", ]: await answer.reply_text( "Please, select a valid location using keyboard provided. Use /cancel if you want to cancel this operation." ) continue if answer.text in [ "No, I don't want to use it", ]: await answer.reply_text( "Alright, you're on your own now. Please, use the command /setup to configure your location and start receiving reminders.", reply_markup=ReplyKeyboardRemove(), ) return break await user.update_location(location.id) user_time = datetime(1970, 1, 1, user.time_hour, user.time_minute).strftime( app._("time", "formats", locale=user.locale) ) await answer.reply_text( f"✅ Finished! Your location is now **{location.name}**. You will receive reminders about garbage collection {user.offset} d. in advance at {user_time}.\n\nPlease, visit /help if you want to know how to change notifications time or disable them.", reply_markup=ReplyKeyboardRemove(), ) return if user.location is None: await message.reply_text( "📍 Let's configure your location. Press the button on pop-up keyboard to start the process.", reply_markup=ReplyKeyboardMarkup( [[KeyboardButton(app._("configure", "buttons", locale=user.locale))]], resize_keyboard=True, one_time_keyboard=True, ), )