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,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: