From a15b6a16753c989598668b08c11e7e501058a02f Mon Sep 17 00:00:00 2001 From: xtaodada Date: Thu, 14 Sep 2023 21:43:30 +0800 Subject: [PATCH] fix: dc error --- group_data.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/group_data.py b/group_data.py index 6a90ed1..74d3615 100644 --- a/group_data.py +++ b/group_data.py @@ -2,6 +2,7 @@ from typing import List, Dict from cashews import cache from telethon import TelegramClient +from telethon.errors import StatsMigrateError from telethon.tl.functions.stats import GetMegagroupStatsRequest from telethon.utils import get_input_channel from telethon.tl.types.stats import MegagroupStats @@ -12,8 +13,15 @@ cache.setup("mem://") @cache(ttl="1h", key="{cid}") async def get_group_data(cid: int, client: TelegramClient) -> List[Dict]: group = get_input_channel(await client.get_input_entity(cid)) - result: MegagroupStats = await client(GetMegagroupStatsRequest( - channel=group, - dark=True - )) + try: + result: MegagroupStats = await client(GetMegagroupStatsRequest( + channel=group, + dark=True + )) + except StatsMigrateError as e: + sender = await client._borrow_exported_sender(e.dc) + result: MegagroupStats = await client._call(sender, GetMegagroupStatsRequest( + channel=group, + dark=True + )) return [i.to_dict() for i in result.top_posters]