Send replies to messages sent with /message

This commit is contained in:
2022-12-07 14:17:27 +01:00
parent 1f7890dc53
commit d117146d96
4 changed files with 45 additions and 5 deletions

View File

@@ -1,7 +1,8 @@
from os import sep
from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.errors import bad_request_400
from modules.utils import logWrite, locale, configGet, should_quote
from modules.utils import jsonLoad, jsonSave, logWrite, locale, configGet, should_quote
# Message command ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"]))
@@ -31,9 +32,12 @@ async def cmd_message(app, msg):
void = msg.command[2]
message = " ".join(msg.command[2:])
try:
await app.send_message(destination.id, message)
new_message = await app.send_message(destination.id, message+locale("message_reply_notice", "message"))
await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
logWrite(f"Admin {msg.from_user.id} sent message '{' '.join(msg.command[2:])}' to {destination.id}")
messages = jsonLoad(f"{configGet('data', 'locations')}{sep}messages.json")
messages.append({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
jsonSave(messages, f"{configGet('data', 'locations')}{sep}messages.json")
except bad_request_400.PeerIdInvalid:
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 {destination.id} but 'PeerIdInvalid'")