2023-08-27 23:43:16 +03:00
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.types import Message
|
|
|
|
|
|
|
|
from classes.pyroclient import PyroClient
|
2023-08-30 15:41:34 +03:00
|
|
|
from modules import custom_filters
|
2023-08-27 23:43:16 +03:00
|
|
|
|
|
|
|
|
|
|
|
@PyroClient.on_message(
|
2023-08-30 15:41:34 +03:00
|
|
|
~filters.scheduled & filters.private & filters.command(["toggle"], prefixes=["/"]) & ~custom_filters.context # type: ignore
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
async def command_toggle(app: PyroClient, message: Message):
|
|
|
|
user = await app.find_user(message.from_user)
|
|
|
|
|
|
|
|
await user.update_state(not user.enabled)
|
|
|
|
|
|
|
|
if user.enabled:
|
2023-08-29 17:32:37 +03:00
|
|
|
await message.reply_text(
|
|
|
|
app._("toggle_disabled", "messages", locale=user.locale)
|
|
|
|
)
|
2023-08-27 23:43:16 +03:00
|
|
|
return
|
|
|
|
|
2023-08-29 17:32:37 +03:00
|
|
|
user_time = datetime(1970, 1, 1, user.time_hour, user.time_minute).strftime("%H:%M")
|
|
|
|
|
2023-08-27 23:43:16 +03:00
|
|
|
if user.location is None:
|
|
|
|
await message.reply_text(
|
2023-08-29 17:32:37 +03:00
|
|
|
app._("toggle_enabled", "messages", locale=user.locale).format(
|
|
|
|
offset=user.offset,
|
|
|
|
time=user_time,
|
|
|
|
),
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|
|
|
|
return
|
|
|
|
|
|
|
|
await message.reply_text(
|
2023-08-29 17:32:37 +03:00
|
|
|
app._("toggle_enabled_location", "messages", locale=user.locale).format(
|
|
|
|
offset=user.offset,
|
|
|
|
time=user_time,
|
|
|
|
name=user.location.name,
|
|
|
|
)
|
2023-08-27 23:43:16 +03:00
|
|
|
)
|