Now using HoloUser messaging

This commit is contained in:
Profitroll 2022-12-11 23:32:20 +01:00
parent c5f9e96414
commit 0e06c2a7a5

View File

@ -2,6 +2,7 @@ from os import sep
from app import app, isAnAdmin from app import app, isAnAdmin
from pyrogram import filters from pyrogram import filters
from pyrogram.errors import bad_request_400 from pyrogram.errors import bad_request_400
from classes.holo_user import HoloUser
from modules.utils import jsonLoad, jsonSave, logWrite, locale, configGet, should_quote from modules.utils import jsonLoad, jsonSave, logWrite, locale, configGet, should_quote
from modules.database import col_messages from modules.database import col_messages
@ -12,34 +13,25 @@ async def cmd_message(app, msg):
if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id): if msg.chat.id == configGet("admin_group") or await isAnAdmin(msg.from_user.id):
try: try:
try: try:
destination = await app.get_users(int(msg.command[1])) destination = HoloUser(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: except ValueError:
try: destination = HoloUser(msg.command[1])
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
void = msg.command[2] void = msg.command[2]
message = " ".join(msg.command[2:]) message = " ".join(msg.command[2:])
try:
new_message = await app.send_message(destination.id, message+locale("message_reply_notice", "message")) await destination.message(msg, msg.command[2:])
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}") # try:
col_messages.insert_one({"origin": {"chat": msg.chat.id, "id": msg.id}, "destination": {"chat": new_message.chat.id, "id": new_message.id}}) # new_message = await app.send_message(destination.id, message+locale("message_reply_notice", "message"))
except bad_request_400.PeerIdInvalid: # await msg.reply_text(locale("message_sent", "message"), quote=should_quote(msg))
await msg.reply_text(locale("message_no_user", "message"), quote=should_quote(msg)) # logWrite(f"Admin {msg.from_user.id} sent message '{' '.join(msg.command[2:])}' to {destination.id}")
logWrite(f"Admin {msg.from_user.id} tried to send message '{' '.join(msg.command[2:])}' to {destination.id} but 'PeerIdInvalid'") # 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'")
except IndexError: except IndexError:
await msg.reply_text(locale("message_invalid_syntax", "message"), quote=should_quote(msg)) 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'") logWrite(f"Admin {msg.from_user.id} tried to send message but 'IndexError'")