This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
Telegram/modules/commands/message.py

98 lines
3.6 KiB
Python
Raw Permalink Normal View History

2023-03-26 20:32:07 +03:00
from app import app, isAnAdmin
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-03-26 20:32:07 +03:00
from convopyro import listen_message
2023-01-06 16:49:51 +02:00
from classes.errors.holo_user import UserInvalidError
from classes.holo_user import HoloUser
2023-03-26 20:32:07 +03:00
from modules.utils import configGet, logWrite, locale, should_quote, find_user
2022-12-27 19:46:17 +02:00
from modules import custom_filters
2023-03-26 20:32:07 +03:00
from modules.database import col_messages
2022-12-05 19:49:51 +02:00
2023-03-09 17:25:06 +02:00
@app.on_message(
custom_filters.enabled_general
& ~filters.scheduled
& filters.command(["message"], prefixes=["/"])
2023-03-26 20:32:07 +03:00
# & custom_filters.admin
2023-03-09 17:25:06 +02:00
)
2022-12-27 14:36:54 +02:00
async def cmd_message(app: Client, msg: Message):
2022-12-27 19:46:17 +02:00
try:
2023-03-26 20:32:07 +03:00
if await isAnAdmin(msg.from_user.id):
try:
destination = HoloUser(int(msg.command[1]))
except (ValueError, UserInvalidError):
destination = HoloUser(await find_user(app, query=msg.command[1]))
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,
)
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,
)
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
else:
await msg.reply_text(
locale("message_enter", "message", locale=msg.from_user)
)
2023-04-08 02:17:49 +03:00
message = await listen_message(app, msg.chat.id)
if (
message is None
or message.text is not None
and message.text == "/cancel"
):
return
2023-03-26 20:32:07 +03:00
sent = await app.forward_messages(
configGet("admin", "groups"), msg.chat.id, message.id
)
col_messages.insert_one(
{
"origin": {"chat": message.chat.id, "id": message.id},
"destination": {"chat": sent.chat.id, "id": sent.id},
}
2023-03-09 17:25:06 +02:00
)
await message.reply_text(
locale("message_sent", "message", locale=message.from_user), quote=True
)
2023-03-09 17:25:06 +02:00
2022-12-27 19:46:17 +02:00
except IndexError:
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("message_invalid_syntax", "message", locale=msg.from_user),
quote=should_quote(msg),
)
2022-12-27 19:46:17 +02:00
logWrite(f"Admin {msg.from_user.id} tried to send message but 'IndexError'")
except ValueError:
2023-03-09 17:25:06 +02:00
await msg.reply_text(
locale("message_invalid_syntax", "message", locale=msg.from_user),
quote=should_quote(msg),
)
2022-12-27 19:46:17 +02:00
logWrite(f"Admin {msg.from_user.id} tried to send message but 'ValueError'")