From 9aa3668df027ee476d4b234dddbaa80311db7c4e Mon Sep 17 00:00:00 2001 From: Antigravity Bot Date: Sun, 30 Aug 2026 17:27:19 +0330 Subject: [PATCH] =?UTF-8?q?AI=20Update:=20=D8=A7=D8=B5=D9=84=D8=A7=D8=AD?= =?UTF-8?q?=D8=A7=D8=AA=20=D8=B1=D8=A7=20=D8=B1=D9=88=DB=8C=20=DA=A9=D8=AF?= =?UTF-8?q?=D9=87=D8=A7=20=D9=88=20=D8=B3=D8=B1=D9=88=DB=8C=D8=B3=E2=80=8C?= =?UTF-8?q?=D9=87=D8=A7=20=D8=A7=D8=B9=D9=85=D8=A7=D9=84=20=DA=A9=D9=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- services/admin_bot.py | 4 ++-- tests/test_name_formatting.py | 36 +++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/services/admin_bot.py b/services/admin_bot.py index ecf2213..7bb639b 100644 --- a/services/admin_bot.py +++ b/services/admin_bot.py @@ -654,7 +654,7 @@ class AdminBotService: tag_line = f"🏷 موضوع: #{post.subject}\n\n" if getattr(post, "subject", None) else "" - if post.source_channel_id <= -900000000: + if -999999999 <= post.source_channel_id <= -900000000: site_id = abs(post.source_channel_id + 900000000) site = await self.repo.get_source_website_by_id(site_id) if site and site.name: @@ -685,7 +685,7 @@ class AdminBotService: async def get_effective_review_channel_id(self, post: Post) -> Optional[int]: """Determine which Admin Review Channel this post should be sent to.""" - if post.source_channel_id <= -900000000: + if -999999999 <= post.source_channel_id <= -900000000: site_id = abs(post.source_channel_id + 900000000) site = await self.repo.get_source_website_by_id(site_id) if site and site.admin_channel_id: diff --git a/tests/test_name_formatting.py b/tests/test_name_formatting.py index 5fa5dc4..30fbcaa 100644 --- a/tests/test_name_formatting.py +++ b/tests/test_name_formatting.py @@ -43,3 +43,39 @@ async def test_admin_bot_format_raw_post_caption_website(): assert "دیجیاتو" in caption assert "وبسایت" in caption + + +@pytest.mark.asyncio +async def test_admin_bot_format_raw_post_caption_real_telegram_supergroup_id(): + repo = MagicMock() + real_tg_id = -1009199982627 + repo.get_source_by_channel_id = AsyncMock(return_value=SourceChannel( + id=1, channel_id=real_tg_id, username="mychannel", title="کانال تست" + )) + repo.get_source_website_by_id = AsyncMock() + bot = AdminBotService(repo=repo, ai_processor=MagicMock(), queue=MagicMock()) + + post = Post(id=3, source_channel_id=real_tg_id, source_message_id=100, raw_text="متن خبر کانال") + caption = await bot._format_raw_post_caption(post) + + assert "کانال تست" in caption + # Verify get_source_website_by_id was NEVER called for telegram channel + repo.get_source_website_by_id.assert_not_called() + repo.get_source_by_channel_id.assert_called_once_with(real_tg_id) + + +@pytest.mark.asyncio +async def test_admin_bot_get_effective_review_channel_id(): + repo = MagicMock() + real_tg_id = -1009199982627 + repo.get_source_by_channel_id = AsyncMock(return_value=SourceChannel( + id=1, channel_id=real_tg_id, username="mychannel", title="کانال تست", admin_channel_id=-100111222333 + )) + repo.get_source_website_by_id = AsyncMock() + bot = AdminBotService(repo=repo, ai_processor=MagicMock(), queue=MagicMock()) + + post = Post(id=3, source_channel_id=real_tg_id, source_message_id=100, raw_text="متن خبر") + rev_id = await bot.get_effective_review_channel_id(post) + assert rev_id == -100111222333 + repo.get_source_website_by_id.assert_not_called() +