77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
import logging
|
|
from datetime import datetime
|
|
|
|
from convopyro import listen_message
|
|
from libbot import i18n
|
|
from pykeyboard import ReplyButton, ReplyKeyboard
|
|
from pyrogram import filters
|
|
from pyrogram.types import Message, ReplyKeyboardRemove
|
|
|
|
from classes.pyroclient import PyroClient
|
|
from modules.search_name import search_name
|
|
from modules.search_nearby import search_nearby
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@PyroClient.on_message(
|
|
~filters.scheduled & filters.private & filters.command(["setup"] + i18n.sync.in_all_locales("configure", "buttons"), prefixes=["/", ""]) # type: ignore
|
|
)
|
|
async def command_setup(app: PyroClient, message: Message):
|
|
user = await app.find_user(message.from_user)
|
|
|
|
keyboard_type = ReplyKeyboard(resize_keyboard=True, row_width=1)
|
|
keyboard_type.add(
|
|
ReplyButton("Search nearby locations", request_location=True),
|
|
ReplyButton("Search by location name"),
|
|
)
|
|
|
|
await message.reply_text(
|
|
"Let's begin configuration with the search for your location.\n\nPlease, select whether you want to search among the locations near you or go straight to the search by location name.\n\nNote that the location you send will **NOT** be saved anywhere and is only used for location lookup in the database.",
|
|
reply_markup=keyboard_type,
|
|
)
|
|
|
|
while True:
|
|
answer_type = await listen_message(app, message.chat.id, 300)
|
|
|
|
if answer_type is None or answer_type.text == "/cancel":
|
|
await message.reply_text(
|
|
app._("cancelled", "messages", locale=user.locale),
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|
|
return
|
|
|
|
if answer_type.location is None and answer_type.text not in [
|
|
"Search by location name",
|
|
]:
|
|
await answer_type.reply_text(
|
|
app._("selection_invalid", "messages", locale=user.locale).format(
|
|
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
|
)
|
|
)
|
|
continue
|
|
|
|
break
|
|
|
|
location = (
|
|
await search_name(app, answer_type)
|
|
if answer_type.location is None
|
|
else await search_nearby(app, answer_type)
|
|
)
|
|
|
|
if location is None:
|
|
await answer_type.reply_text(
|
|
"If you want try selecting the location again, use the /setup command.",
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|
|
return
|
|
|
|
await user.update_location(location.id)
|
|
|
|
user_time = datetime(1970, 1, 1, user.time_hour, user.time_minute)
|
|
|
|
await message.reply_text(
|
|
f"✅ Finished! Your location is now **{location.name}**. You will receive the notifications about garbage collection {user.offset} d. in advance at {user_time.strftime(app._('time', 'formats', locale=user.locale))}.",
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|