This repository has been archived on 2024-10-10. You can view files and clone it, but cannot push or open issues or pull requests.
TelegramBot/plugins/commands/toggle.py
2023-08-29 16:32:37 +02:00

41 lines
1.1 KiB
Python

from datetime import datetime
from pyrogram import filters
from pyrogram.types import Message
from classes.pyroclient import PyroClient
@PyroClient.on_message(
~filters.scheduled & filters.private & filters.command(["toggle"], prefixes=["/"]) # type: ignore
)
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:
await message.reply_text(
app._("toggle_disabled", "messages", locale=user.locale)
)
return
user_time = datetime(1970, 1, 1, user.time_hour, user.time_minute).strftime("%H:%M")
if user.location is None:
await message.reply_text(
app._("toggle_enabled", "messages", locale=user.locale).format(
offset=user.offset,
time=user_time,
),
)
return
await message.reply_text(
app._("toggle_enabled_location", "messages", locale=user.locale).format(
offset=user.offset,
time=user_time,
name=user.location.name,
)
)