add fix for sender success
This commit is contained in:
parent
65d527b9d2
commit
696cce8bdf
@ -1,7 +1,9 @@
|
|||||||
|
from telethon.errors.rpcerrorlist import MessageIdInvalidError
|
||||||
|
|
||||||
from src.core.database import TgMessage, TgChat, User
|
from src.core.database import TgMessage, TgChat, User
|
||||||
from src.core.settings.base import settings
|
from src.core.settings.base import settings
|
||||||
from src.core.tg_service.notify_sender import send_to_tg_from_bot
|
from src.core.tg_service.notify_sender import send_to_tg_from_bot
|
||||||
from src.core.tg_service.utils import create_and_format_message
|
from src.core.tg_service.utils import create_and_format_message, create_text_for_error_message_success
|
||||||
|
|
||||||
from src.telethon_client import telethon_client
|
from src.telethon_client import telethon_client
|
||||||
|
|
||||||
@ -24,8 +26,19 @@ async def notify_for_success(
|
|||||||
text=message
|
text=message
|
||||||
)
|
)
|
||||||
|
|
||||||
|
for message in messages:
|
||||||
|
try:
|
||||||
await telethon_client.forward_messages(
|
await telethon_client.forward_messages(
|
||||||
entity=settings.NOTIFY.CHAT_ID,
|
entity=settings.NOTIFY.CHAT_ID,
|
||||||
messages=[message.id for message in messages],
|
messages=message.id,
|
||||||
from_peer=source_chat,
|
from_peer=source_chat,
|
||||||
)
|
)
|
||||||
|
except MessageIdInvalidError:
|
||||||
|
await send_to_tg_from_bot(
|
||||||
|
text=create_text_for_error_message_success(
|
||||||
|
"🔒 Удаленное сообщение\n\n"
|
||||||
|
"⚠️ Сообщение удалено или недоступно\n\n"
|
||||||
|
f"📝 Текст:`{message.text}`"
|
||||||
|
f"👤 ID_USER:`{message.user_id}`"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
@ -37,13 +37,6 @@ def check_message_condition(
|
|||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def create_and_format_message(
|
|
||||||
reason: str,
|
|
||||||
chat: TgChat,
|
|
||||||
user_model: User | Channel,
|
|
||||||
) -> str:
|
|
||||||
def escape_markdown_v2(text: str) -> str:
|
def escape_markdown_v2(text: str) -> str:
|
||||||
if not text:
|
if not text:
|
||||||
return ""
|
return ""
|
||||||
@ -59,6 +52,12 @@ def create_and_format_message(
|
|||||||
text = text.replace('`', 'ʻ') # Replace with similar-looking character
|
text = text.replace('`', 'ʻ') # Replace with similar-looking character
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
|
||||||
|
def create_and_format_message(
|
||||||
|
reason: str,
|
||||||
|
chat: TgChat,
|
||||||
|
user_model: User | Channel,
|
||||||
|
) -> str:
|
||||||
# User info
|
# User info
|
||||||
username = escape_markdown_v2(user_model.username) if user_model.username else f"ID: {user_model.id}"
|
username = escape_markdown_v2(user_model.username) if user_model.username else f"ID: {user_model.id}"
|
||||||
user_link = f"[{username}](tg://user?id={user_model.id})" if user_model.username else f"ID: {user_model.id}"
|
user_link = f"[{username}](tg://user?id={user_model.id})" if user_model.username else f"ID: {user_model.id}"
|
||||||
@ -116,3 +115,10 @@ def handle_chat_type(
|
|||||||
raise ValueError(f"Invalid chat type check it!{chat}")
|
raise ValueError(f"Invalid chat type check it!{chat}")
|
||||||
|
|
||||||
return chat_type, chat_username
|
return chat_type, chat_username
|
||||||
|
|
||||||
|
|
||||||
|
def create_text_for_error_message_success(
|
||||||
|
text: str
|
||||||
|
) -> str:
|
||||||
|
text = escape_markdown_v2(text)
|
||||||
|
return validate_markdown(text)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user