123 lines
4.0 KiB
Python
123 lines
4.0 KiB
Python
from convopyro import listen_message
|
|
from pyrogram import filters
|
|
from pyrogram.types import (
|
|
KeyboardButton,
|
|
Message,
|
|
ReplyKeyboardMarkup,
|
|
ReplyKeyboardRemove,
|
|
)
|
|
|
|
from classes.pyroclient import PyroClient
|
|
from modules import custom_filters
|
|
|
|
|
|
@PyroClient.on_message(
|
|
~filters.scheduled & filters.private & filters.command(["start"], prefixes=["/"]) & ~custom_filters.context # 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).format(
|
|
terms_of_service="https://garbagebot.eu/community/public/terms-of-service",
|
|
privacy_policy="https://garbagebot.eu/community/public/privacy-policy",
|
|
)
|
|
)
|
|
|
|
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(
|
|
app._("start_code_invalid", "messages", locale=user.locale)
|
|
)
|
|
return
|
|
|
|
keyboard = ReplyKeyboardMarkup(
|
|
[
|
|
[
|
|
KeyboardButton(
|
|
app._("start_code_yes", "buttons", locale=user.locale)
|
|
)
|
|
],
|
|
[KeyboardButton(app._("start_code_no", "buttons", locale=user.locale))],
|
|
],
|
|
resize_keyboard=True,
|
|
one_time_keyboard=True,
|
|
)
|
|
|
|
await message.reply_text(
|
|
app._("start_code", "messages", locale=user.locale).format(
|
|
name=location.name
|
|
),
|
|
reply_markup=keyboard,
|
|
)
|
|
|
|
while True:
|
|
app.contexts.append(message.from_user.id)
|
|
answer = await listen_message(app, message.chat.id, 300)
|
|
app.contexts.remove(message.from_user.id)
|
|
|
|
if answer is None or answer.text == "/cancel":
|
|
await message.reply_text(
|
|
app._("cancelled", "messages", locale=user.locale),
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|
|
return
|
|
|
|
if answer.text not in app.in_all_locales(
|
|
"start_code_yes", "buttons"
|
|
) + app.in_all_locales("start_code_no", "buttons"):
|
|
await answer.reply_text(
|
|
app._("selection_invalid", "messages", locale=user.locale).format(
|
|
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
|
)
|
|
)
|
|
continue
|
|
|
|
if answer.text in app.in_all_locales("start_code_no", "buttons"):
|
|
await answer.reply_text(
|
|
app._("start_selection_no", "messages", locale=user.locale),
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|
|
return
|
|
|
|
break
|
|
|
|
await user.update_location(location.id)
|
|
|
|
try:
|
|
user_time = user.get_reminder_time().strftime(
|
|
app._("time", "formats", locale=user.locale)
|
|
)
|
|
except AttributeError:
|
|
user_time = "N/A"
|
|
|
|
await answer.reply_text(
|
|
app._("start_selection_yes", "messages", locale=user.locale).format(
|
|
name=location.name,
|
|
offset=user.offset,
|
|
time=user_time,
|
|
),
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
)
|
|
return
|
|
|
|
if user.location is None:
|
|
await message.reply_text(
|
|
app._("start_configure", "messages", locale=user.locale),
|
|
reply_markup=ReplyKeyboardMarkup(
|
|
[
|
|
[
|
|
KeyboardButton(
|
|
app._("start_configure", "buttons", locale=user.locale)
|
|
)
|
|
]
|
|
],
|
|
resize_keyboard=True,
|
|
one_time_keyboard=True,
|
|
),
|
|
)
|