Messages command updated

This commit is contained in:
Profitroll 2022-12-11 18:50:50 +01:00
parent 091c0abace
commit 03ebeafdd4
2 changed files with 13 additions and 16 deletions

View File

@ -3,6 +3,7 @@ from app import app, isAnAdmin
from pyrogram import filters
from pyrogram.errors import bad_request_400
from modules.utils import jsonLoad, jsonSave, logWrite, locale, configGet, should_quote
from modules.database import col_messages
# Message command ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.command(["message"], prefixes=["/"]))
@ -35,9 +36,7 @@ async def cmd_message(app, msg):
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")
col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
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

@ -5,19 +5,19 @@ import asyncio
from pyrogram import filters
from pyrogram.types import ForceReply, ReplyKeyboardMarkup, Message
from modules.utils import configGet, configSet, jsonLoad, jsonSave, locale, logWrite, should_quote
from modules.database import col_messages
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):
async def message_involved(msg: Message) -> bool:
message = col_messages.find_one({"destination.id": msg.reply_to_message.id, "destination.chat": msg.reply_to_message.chat.id})
if message is not None:
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):
async def message_context(msg: Message) -> tuple:
message = col_messages.find_one({"destination.id": msg.reply_to_message.id, "destination.chat": msg.reply_to_message.chat.id})
if message is not None:
return message["origin"]["chat"], message["origin"]["id"]
return 0, 0
# Any other input ==============================================================================================================
@app.on_message(~ filters.scheduled & filters.private)
@ -32,9 +32,7 @@ async def any_stage(app, msg):
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")
col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}})
return
user_stage = configGet("stage", file=str(msg.from_user.id))