Send replies to messages sent with /message

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

View File

@ -58,6 +58,8 @@
"message_sent": "Повідомлення надіслано",
"message_no_user": "⚠️ **Помилка надсилання**\nВказано невірний ID користувача, тому не вдалось надіслати йому повідомлення. Перевірте чи в якості ID надано те число, яке було показане в анкеті.",
"message_invalid_syntax": "Неправильний синтаксис!\nТреба: `/message ID ПОВІДОМЛЕННЯ`",
"message_from": "Повідомлення від **{0}** (`{1}`):\n\n",
"message_reply_notice": "\n\n**Щоб надіслати відповідь на це повідомлення, тегніть його.**",
"question_titles": {
"question1": "Ім'я/звертання:",
"question2": "День народження:",

View File

@ -22,6 +22,14 @@ for entry in [f"{configGet('data', 'locations')}{sep}applications.json", f"{conf
except:
pass
for entry in [f"{configGet('data', 'locations')}{sep}messages.json"]:
mode = 'r' if path.exists(entry) else 'w'
with open(entry, mode) as f:
try:
f.write("[]")
except:
pass
# Importing
from modules.commands.application import *
from modules.commands.applications import *

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'")

View File

@ -1,9 +1,23 @@
from datetime import datetime
from app import app
from os import sep
from app import app, isAnAdmin
import asyncio
from pyrogram import filters
from pyrogram.types import ForceReply, ReplyKeyboardMarkup
from modules.utils import configGet, configSet, locale, logWrite
from pyrogram.types import ForceReply, ReplyKeyboardMarkup, Message
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite, should_quote
async def message_involved(msg: Message):
messages = jsonLoad(f"{configGet('data', 'locations')}{sep}messages.json")
for message in messages:
if (message["destination"]["id"] == msg.reply_to_message.id) and (message["destination"]["chat"] == msg.reply_to_message.chat.id):
return True
return False
async def message_context(msg: Message):
messages = jsonLoad(f"{configGet('data', 'locations')}{sep}messages.json")
for message in messages:
if (message["destination"]["id"] == msg.reply_to_message.id) and (message["destination"]["chat"] == msg.reply_to_message.chat.id):
return message["origin"]["chat"], message["origin"]["id"]
# Any other input ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.private)
@ -11,6 +25,18 @@ async def any_stage(app, msg):
if msg.via_bot is None:
if (msg.reply_to_message != None) and (await message_involved(msg)):
context = await message_context(msg)
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
new_message = await (await app.get_messages(context[0], context[1])).reply_text(msg.text+locale("message_reply_notice", "message"), quote=True)
else:
new_message = await (await app.get_messages(context[0], context[1])).reply_text(locale("message_from", "message").format(msg.from_user.first_name, msg.from_user.id)+msg.text+locale("message_reply_notice", "message"), quote=True)
await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
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")
return
user_stage = configGet("stage", file=str(msg.from_user.id))
if user_stage == 1: