diff --git a/telegram-application/src/core/settings/account.py b/telegram-application/src/core/settings/account.py index 22a5c1f..be4eea8 100644 --- a/telegram-application/src/core/settings/account.py +++ b/telegram-application/src/core/settings/account.py @@ -4,4 +4,5 @@ from pydantic import BaseModel class AccountSettings(BaseModel): API_ID: int API_HASH: str - NAME: str = "tg_account" \ No newline at end of file + NAME: str = "tg_account" + SESSION: str \ No newline at end of file diff --git a/telegram-application/src/core/tg_service/messages_handler.py b/telegram-application/src/core/tg_service/messages_handler.py index 055c273..3c253b3 100644 --- a/telegram-application/src/core/tg_service/messages_handler.py +++ b/telegram-application/src/core/tg_service/messages_handler.py @@ -12,11 +12,13 @@ from telethon.types import Message, User, Chat, Channel DATA: dict[int, list[MessageFromChatSchema]] = dict() + lock = asyncio.Lock() @telethon_client.on(event=NewMessage) async def message_listener(event: NewMessage.Event) -> None: + print("received new message") message: Message = event.message sender: User = await event.get_sender() chat: TELETHON_CHAT_TYPES = await event.get_chat() diff --git a/telegram-application/src/core/tg_service/utils.py b/telegram-application/src/core/tg_service/utils.py index 2c42376..610ddcd 100644 --- a/telegram-application/src/core/tg_service/utils.py +++ b/telegram-application/src/core/tg_service/utils.py @@ -15,6 +15,9 @@ def check_message_condition( sender: User, chat_type: CustomChatTypes, ) -> bool: + if isinstance(sender, Channel): + return False + if chat_type == CustomChatTypes.PRIVATE_GROUP: return False @@ -36,7 +39,7 @@ def check_message_condition( def create_and_format_message( reason: str, chat: TgChat, - user_model: User, + user_model: User | Channel, ) -> str: def escape_markdown_v2(text: str) -> str: if not text: diff --git a/telegram-application/src/telethon_client.py b/telegram-application/src/telethon_client.py index e8a8b62..a6e2664 100644 --- a/telegram-application/src/telethon_client.py +++ b/telegram-application/src/telethon_client.py @@ -1,13 +1,14 @@ import asyncio from telethon import TelegramClient +from telethon.sessions import StringSession from src.core.settings.base import settings loop = asyncio.get_event_loop() telethon_client = TelegramClient( - settings.ACCOUNT.NAME, + session=StringSession(settings.ACCOUNT.SESSION), api_id=settings.ACCOUNT.API_ID, api_hash=settings.ACCOUNT.API_HASH, loop=loop,