2023-08-27 23:43:16 +03:00
|
|
|
import logging
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from convopyro import listen_message
|
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.types import ForceReply, Message, ReplyKeyboardRemove
|
|
|
|
|
|
|
|
from classes.pyroclient import PyroClient
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
|
|
|
|
|
|
@PyroClient.on_message(
|
|
|
|
~filters.scheduled & filters.private & filters.command(["set_time"], prefixes=["/"]) # type: ignore
|
|
|
|
)
|
|
|
|
async def command_set_time(app: PyroClient, message: Message):
|
|
|
|
user = await app.find_user(message.from_user)
|
|
|
|
|
|
|
|
await message.reply_text(
|
2023-08-30 12:01:59 +03:00
|
|
|
app._("set_time", "messages", locale=user.locale),
|
|
|
|
reply_markup=ForceReply(
|
|
|
|
placeholder=app._("set_time", "force_replies", locale=user.locale)
|
|
|
|
),
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
while True:
|
|
|
|
answer = await listen_message(app, message.chat.id, 300)
|
|
|
|
|
|
|
|
if answer is None or answer.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-27 23:43:16 +03:00
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
datetime.strptime(answer.text, "%H:%M")
|
|
|
|
except ValueError:
|
|
|
|
await answer.reply_text(
|
2023-08-30 12:01:59 +03:00
|
|
|
app._("set_time_invalid", "messages", locale=user.locale).format(
|
|
|
|
cancel_notice=app._("cancel", "messages", locale=user.locale)
|
|
|
|
)
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
continue
|
|
|
|
|
|
|
|
break
|
|
|
|
|
|
|
|
user_time = datetime.strptime(answer.text, "%H:%M")
|
|
|
|
|
|
|
|
await user.update_time(hour=user_time.hour, minute=user_time.minute)
|
|
|
|
|
|
|
|
logger.info(
|
|
|
|
"User %s has selected notification time of %s",
|
|
|
|
user.id,
|
|
|
|
user_time.strftime("%H:%M"),
|
|
|
|
)
|
|
|
|
|
|
|
|
garbage_time = user_time.strftime(app._("time", "formats"))
|
|
|
|
|
|
|
|
await answer.reply_text(
|
2023-08-30 12:01:59 +03:00
|
|
|
app._("set_time_finished", "messages", locale=user.locale).format(
|
|
|
|
offset=user.offset,
|
|
|
|
time=garbage_time,
|
|
|
|
toggle_notice=""
|
|
|
|
if user.enabled
|
|
|
|
else app._("toggle", "messages", locale=user.locale),
|
|
|
|
),
|
2023-08-27 23:43:16 +03:00
|
|
|
reply_markup=ReplyKeyboardRemove(),
|
|
|
|
)
|