2023-08-27 23:43:16 +03:00
|
|
|
import logging
|
2023-08-28 16:41:20 +03:00
|
|
|
from datetime import datetime
|
2023-08-27 23:43:16 +03:00
|
|
|
|
|
|
|
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
|
2023-08-30 15:41:34 +03:00
|
|
|
from modules import custom_filters
|
2023-08-28 16:41:20 +03:00
|
|
|
from modules.search_name import search_name
|
|
|
|
from modules.search_nearby import search_nearby
|
2023-09-25 00:47:09 +03:00
|
|
|
from modules.utils import from_utc
|
2023-08-27 23:43:16 +03:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@PyroClient.on_message(
|
2023-08-30 15:41:34 +03:00
|
|
|
~filters.scheduled & filters.private & filters.command(["setup"] + i18n.sync.in_all_locales("start_configure", "buttons"), prefixes=["/", ""]) & ~custom_filters.context # type: ignore
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
async def command_setup(app: PyroClient, message: Message):
|
|
|
|
user = await app.find_user(message.from_user)
|
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
keyboard_type = ReplyKeyboard(resize_keyboard=True, row_width=1)
|
|
|
|
keyboard_type.add(
|
2023-08-30 12:01:59 +03:00
|
|
|
ReplyButton(
|
|
|
|
app._("search_nearby", "buttons", locale=user.locale), request_location=True
|
|
|
|
),
|
|
|
|
ReplyButton(app._("search_name", "buttons", locale=user.locale)),
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
await message.reply_text(
|
2023-08-30 12:01:59 +03:00
|
|
|
app._("setup", "messages", locale=user.locale),
|
2023-08-28 16:41:20 +03:00
|
|
|
reply_markup=keyboard_type,
|
|
|
|
)
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
while True:
|
2023-08-30 15:41:34 +03:00
|
|
|
app.contexts.append(message.from_user.id)
|
2023-08-28 16:41:20 +03:00
|
|
|
answer_type = await listen_message(app, message.chat.id, 300)
|
2023-08-30 15:41:34 +03:00
|
|
|
app.contexts.remove(message.from_user.id)
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
if answer_type is None or answer_type.text == "/cancel":
|
2023-08-29 17:32:37 +03:00
|
|
|
await message.reply_text(
|
|
|
|
app._("cancelled", "messages", locale=user.locale),
|
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|
2023-08-28 16:41:20 +03:00
|
|
|
return
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-30 12:01:59 +03:00
|
|
|
if answer_type.location is None and answer_type.text not in app.in_all_locales(
|
|
|
|
"search_name", "buttons"
|
|
|
|
):
|
2023-08-28 16:41:20 +03:00
|
|
|
await answer_type.reply_text(
|
2023-08-29 17:32:37 +03:00
|
|
|
app._("selection_invalid", "messages", locale=user.locale).format(
|
|
|
|
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
|
|
|
)
|
2023-08-28 16:41:20 +03:00
|
|
|
)
|
|
|
|
continue
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
break
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
location = (
|
|
|
|
await search_name(app, answer_type)
|
|
|
|
if answer_type.location is None
|
|
|
|
else await search_nearby(app, answer_type)
|
|
|
|
)
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
if location is None:
|
|
|
|
await answer_type.reply_text(
|
2023-08-30 12:01:59 +03:00
|
|
|
app._("setup_retry", "messages", locale=user.locale),
|
2023-08-28 16:41:20 +03:00
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|
|
|
|
return
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
await user.update_location(location.id)
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-09-25 00:47:09 +03:00
|
|
|
user_time = from_utc(
|
|
|
|
datetime(1970, 1, 1, user.time_hour, user.time_minute),
|
|
|
|
None if user.location is None else user.location.timezone.zone,
|
|
|
|
).strftime(app._("time", "formats", locale=user.locale))
|
2023-08-27 23:43:16 +03:00
|
|
|
|
2023-08-28 16:41:20 +03:00
|
|
|
await message.reply_text(
|
2023-08-30 12:01:59 +03:00
|
|
|
app._("setup_finished", "messages", locale=user.locale).format(
|
|
|
|
name=location.name,
|
|
|
|
offset=user.offset,
|
|
|
|
time=user_time,
|
|
|
|
),
|
2023-08-28 16:41:20 +03:00
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|