85 lines
2.6 KiB
Python
85 lines
2.6 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(
|
|
app._("search_nearby", "buttons", locale=user.locale), request_location=True
|
|
),
|
|
ReplyButton(app._("search_name", "buttons", locale=user.locale)),
|
|
)
|
|
|
|
await message.reply_text(
|
|
app._("setup", "messages", locale=user.locale),
|
|
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 app.in_all_locales(
|
|
"search_name", "buttons"
|
|
):
|
|
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(
|
|
app._("setup_retry", "messages", locale=user.locale),
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|
|
return
|
|
|
|
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 message.reply_text(
|
|
app._("setup_finished", "messages", locale=user.locale).format(
|
|
name=location.name,
|
|
offset=user.offset,
|
|
time=user_time,
|
|
),
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|