Deepsource fixes

pull/1/head
hikariatama 2022-09-03 21:06:11 +00:00
parent c3553deed8
commit 30876ab5cf
3 changed files with 13 additions and 12 deletions

View File

@ -24,7 +24,7 @@ from aiogram.types import (
InputMediaAnimation,
InputMediaPhoto,
)
from aiogram.utils.exceptions import BadRequest, InvalidHTTPUrlContent, RetryAfter
from aiogram.utils.exceptions import BadRequest, RetryAfter
from telethon.tl.types import Message
from telethon.errors.rpcerrorlist import ChatSendInlineForbiddenError
@ -512,7 +512,7 @@ class Gallery(InlineUnit):
media=self._get_current_media(unit_id),
reply_markup=self._gallery_markup(unit_id),
)
except (InvalidHTTPUrlContent, BadRequest):
except BadRequest:
logger.debug("Error fetching photo content, attempting load next one")
del self._units[unit_id]["photos"][self._units[unit_id]["current_index"]]
self._units[unit_id]["current_index"] -= 1

View File

@ -14,7 +14,7 @@ import git
from telethon.tl.types import Message
from telethon.utils import get_display_name
from .. import loader, main, utils, version
from .. import loader, utils, version
from ..inline.types import InlineQuery
logger = logging.getLogger(__name__)

View File

@ -51,6 +51,7 @@ class CustomTelegramClient(TelegramClient):
self._hikka_fullchannel_cache = {}
self._hikka_fulluser_cache = {}
self.__forbidden_constructors = []
asyncio.ensure_future(self.cleaner())
async def force_get_entity(self, *args, **kwargs):
return await self.get_entity(*args, force=True, **kwargs)
@ -394,27 +395,27 @@ class CustomTelegramClient(TelegramClient):
def forbid_joins(self):
self.__forbidden_constructors.extend([615851205, 1817183516])
async def cleaner(client: TelegramClient):
async def cleaner(self):
while True:
for record, record_data in client._hikka_entity_cache.copy().items():
for record, record_data in self._hikka_entity_cache.copy().items():
if record_data.expired():
del client._hikka_entity_cache[record]
del self._hikka_entity_cache[record]
logger.debug(f"Cleaned outdated cache {record=}")
for chat, chat_data in client._hikka_perms_cache.copy().items():
for chat, chat_data in self._hikka_perms_cache.copy().items():
for user, user_data in chat_data.copy().items():
if user_data.expired():
del client._hikka_perms_cache[chat][user]
del self._hikka_perms_cache[chat][user]
logger.debug(f"Cleaned outdated perms cache {chat=} {user=}")
for channel_id, record in client._hikka_fullchannel_cache.copy().items():
for channel_id, record in self._hikka_fullchannel_cache.copy().items():
if record.expired():
del client._hikka_fullchannel_cache[channel_id]
del self._hikka_fullchannel_cache[channel_id]
logger.debug(f"Cleaned outdated fullchannel cache {channel_id=}")
for user_id, record in client._hikka_fulluser_cache.copy().items():
for user_id, record in self._hikka_fulluser_cache.copy().items():
if record.expired():
del client._hikka_fulluser_cache[user_id]
del self._hikka_fulluser_cache[user_id]
logger.debug(f"Cleaned outdated fulluser cache {user_id=}")
await asyncio.sleep(3)