Telegram/modules/commands/message.py

34 lines
2.2 KiB
Python
Raw Normal View History

2022-12-27 19:46:17 +02:00
from app import app
2022-12-05 19:49:51 +02:00
from pyrogram import filters
2022-12-27 14:36:54 +02:00
from pyrogram.types import Message
from pyrogram.client import Client
2023-01-06 16:49:51 +02:00
from classes.errors.holo_user import UserInvalidError
from classes.holo_user import HoloUser
2023-01-05 21:47:02 +02:00
from modules.utils import logWrite, locale, should_quote, find_user
2022-12-27 19:46:17 +02:00
from modules import custom_filters
2022-12-05 19:49:51 +02:00
# Message command ==============================================================================================================
2023-01-03 22:46:16 +02:00
@app.on_message(custom_filters.enabled_general & ~filters.scheduled & filters.command(["message"], prefixes=["/"]) & custom_filters.admin)
2022-12-27 14:36:54 +02:00
async def cmd_message(app: Client, msg: Message):
2022-12-05 19:49:51 +02:00
2022-12-27 19:46:17 +02:00
try:
2022-12-05 19:49:51 +02:00
try:
2022-12-27 19:46:17 +02:00
destination = HoloUser(int(msg.command[1]))
2023-01-05 21:47:02 +02:00
except (ValueError, UserInvalidError):
destination = HoloUser(await find_user(app, query=msg.command[1]))
2022-12-27 19:46:17 +02:00
if ((msg.text is not None) and (len(str(msg.text).split()) > 2)):
await destination.message(context=msg, text=" ".join(str(msg.text).split()[2:]), caption=msg.caption, photo=msg.photo, video=msg.video, file=msg.document, voice=msg.voice, animation=msg.animation, adm_context=True)
2022-12-27 19:46:17 +02:00
elif ((msg.caption is not None) and (len(msg.caption.split()) > 2)):
await destination.message(context=msg, text=str(msg.text), caption=" ".join(msg.caption.split()[2:]), photo=msg.photo, video=msg.video, file=msg.document, voice=msg.voice, animation=msg.animation, adm_context=True)
2022-12-27 19:46:17 +02:00
else:
await destination.message(context=msg, text=None, caption=None, photo=msg.photo, video=msg.video, file=msg.document, voice=msg.voice, animation=msg.animation, adm_context=True)
2022-12-27 19:46:17 +02:00
except IndexError:
await msg.reply_text(locale("message_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
logWrite(f"Admin {msg.from_user.id} tried to send message but 'IndexError'")
except ValueError:
await msg.reply_text(locale("message_invalid_syntax", "message", locale=msg.from_user), quote=should_quote(msg))
logWrite(f"Admin {msg.from_user.id} tried to send message but 'ValueError'")
2022-12-05 19:49:51 +02:00
# ==============================================================================================================================