add fix for checker condidtinos

This commit is contained in:
harold 2025-06-14 00:14:26 +05:00
parent 231d449203
commit 7e1889ef6d
4 changed files with 10 additions and 3 deletions

View File

@ -4,4 +4,5 @@ from pydantic import BaseModel
class AccountSettings(BaseModel): class AccountSettings(BaseModel):
API_ID: int API_ID: int
API_HASH: str API_HASH: str
NAME: str = "tg_account" NAME: str = "tg_account"
SESSION: str

View File

@ -12,11 +12,13 @@ from telethon.types import Message, User, Chat, Channel
DATA: dict[int, list[MessageFromChatSchema]] = dict() DATA: dict[int, list[MessageFromChatSchema]] = dict()
lock = asyncio.Lock() lock = asyncio.Lock()
@telethon_client.on(event=NewMessage) @telethon_client.on(event=NewMessage)
async def message_listener(event: NewMessage.Event) -> None: async def message_listener(event: NewMessage.Event) -> None:
print("received new message")
message: Message = event.message message: Message = event.message
sender: User = await event.get_sender() sender: User = await event.get_sender()
chat: TELETHON_CHAT_TYPES = await event.get_chat() chat: TELETHON_CHAT_TYPES = await event.get_chat()

View File

@ -15,6 +15,9 @@ def check_message_condition(
sender: User, sender: User,
chat_type: CustomChatTypes, chat_type: CustomChatTypes,
) -> bool: ) -> bool:
if isinstance(sender, Channel):
return False
if chat_type == CustomChatTypes.PRIVATE_GROUP: if chat_type == CustomChatTypes.PRIVATE_GROUP:
return False return False
@ -36,7 +39,7 @@ def check_message_condition(
def create_and_format_message( def create_and_format_message(
reason: str, reason: str,
chat: TgChat, chat: TgChat,
user_model: User, user_model: User | Channel,
) -> str: ) -> str:
def escape_markdown_v2(text: str) -> str: def escape_markdown_v2(text: str) -> str:
if not text: if not text:

View File

@ -1,13 +1,14 @@
import asyncio import asyncio
from telethon import TelegramClient from telethon import TelegramClient
from telethon.sessions import StringSession
from src.core.settings.base import settings from src.core.settings.base import settings
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
telethon_client = TelegramClient( telethon_client = TelegramClient(
settings.ACCOUNT.NAME, session=StringSession(settings.ACCOUNT.SESSION),
api_id=settings.ACCOUNT.API_ID, api_id=settings.ACCOUNT.API_ID,
api_hash=settings.ACCOUNT.API_HASH, api_hash=settings.ACCOUNT.API_HASH,
loop=loop, loop=loop,