2022-12-07 15:17:27 +02:00
|
|
|
from os import sep
|
2022-12-05 19:49:51 +02:00
|
|
|
from app import app, isAnAdmin
|
|
|
|
from pyrogram import filters
|
|
|
|
from pyrogram.errors import bad_request_400
|
2022-12-07 15:17:27 +02:00
|
|
|
from modules.utils import jsonLoad, jsonSave, logWrite, locale, configGet, should_quote
|
2022-12-11 19:50:50 +02:00
|
|
|
from modules.database import col_messages
|
2022-12-05 19:49:51 +02:00
|
|
|
|
|
|
|
# Message command ==============================================================================================================
|
|
|
|
@app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"]))
|
|
|
|
async def cmd_message(app, msg):
|
|
|
|
|
|
|
|
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
|
|
|
|
|
|
|
|
try:
|
2022-12-06 12:10:44 +02:00
|
|
|
try:
|
|
|
|
destination = await app.get_users(int(msg.command[1]))
|
|
|
|
if destination == [] or destination == None:
|
|
|
|
raise TypeError
|
|
|
|
except TypeError:
|
|
|
|
try:
|
|
|
|
destination = await app.get_users(msg.command[1])
|
|
|
|
except bad_request_400.UsernameNotOccupied:
|
|
|
|
await msg.reply_text(locale("message_no_user", "message"), quote=should_quote(msg))
|
|
|
|
logWrite(f"Admin {msg.from_user.id} tried to send message '{' '.join(msg.command[2:])}' to '{msg.command[1]}' but 'UsernameNotOccupied'")
|
|
|
|
return
|
|
|
|
except ValueError:
|
|
|
|
try:
|
|
|
|
destination = await app.get_users(msg.command[1])
|
|
|
|
except bad_request_400.UsernameNotOccupied:
|
|
|
|
await msg.reply_text(locale("message_no_user", "message"), quote=should_quote(msg))
|
|
|
|
logWrite(f"Admin {msg.from_user.id} tried to send message '{' '.join(msg.command[2:])}' to '{msg.command[1]}' but 'UsernameNotOccupied'")
|
|
|
|
return
|
2022-12-05 19:49:51 +02:00
|
|
|
void = msg.command[2]
|
|
|
|
message = " ".join(msg.command[2:])
|
|
|
|
try:
|
2022-12-07 15:17:27 +02:00
|
|
|
new_message = await app.send_message(destination.id, message+locale("message_reply_notice", "message"))
|
2022-12-05 19:49:51 +02:00
|
|
|
await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
|
2022-12-06 12:10:44 +02:00
|
|
|
logWrite(f"Admin {msg.from_user.id} sent message '{' '.join(msg.command[2:])}' to {destination.id}")
|
2022-12-11 19:50:50 +02:00
|
|
|
col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
|
2022-12-05 19:49:51 +02:00
|
|
|
except bad_request_400.PeerIdInvalid:
|
|
|
|
await msg.reply_text(locale("message_no_user", "message"), quote=should_quote(msg))
|
2022-12-06 12:10:44 +02:00
|
|
|
logWrite(f"Admin {msg.from_user.id} tried to send message '{' '.join(msg.command[2:])}' to {destination.id} but 'PeerIdInvalid'")
|
2022-12-05 19:49:51 +02:00
|
|
|
except IndexError:
|
|
|
|
await msg.reply_text(locale("message_invalid_syntax", "message"), 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"), quote=should_quote(msg))
|
|
|
|
logWrite(f"Admin {msg.from_user.id} tried to send message but 'ValueError'")
|
|
|
|
# ==============================================================================================================================
|