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:
|
2023-03-26 20:38:59 +03:00
|
|
|
await msg.reply_text(
|
|
|
|
locale("message_enter", "message", locale=msg.from_user)
|
|
|
|
)
|
2023-03-26 20:32:07 +03:00
|
|
|
message = await listen_message(app, msg.chat.id, timeout=None)
|
2023-03-26 20:50:10 +03:00
|
|
|
if 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
|
|
|
)
|
2023-03-26 20:38:59 +03: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'")
|