Fix issues with Python 3.10 (#766)

This commit is contained in:
Dan 2021-10-06 17:12:49 +02:00 committed by GitHub
parent 428cbf56a6
commit 6efd01937f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -18,8 +18,6 @@
from typing import List from typing import List
from async_lru import alru_cache
import pyrogram import pyrogram
from pyrogram import raw from pyrogram import raw
from pyrogram import types from pyrogram import types
@ -105,18 +103,35 @@ class Sticker(Object):
self.thumbs = thumbs self.thumbs = thumbs
# self.mask_position = mask_position # self.mask_position = mask_position
cache = {}
@staticmethod @staticmethod
@alru_cache(maxsize=256)
async def _get_sticker_set_name(send, input_sticker_set_id): async def _get_sticker_set_name(send, input_sticker_set_id):
try: try:
return (await send( set_id = input_sticker_set_id[0]
set_access_hash = input_sticker_set_id[1]
name = Sticker.cache.get((set_id, set_access_hash), None)
if name is not None:
return name
name = (await send(
raw.functions.messages.GetStickerSet( raw.functions.messages.GetStickerSet(
stickerset=raw.types.InputStickerSetID( stickerset=raw.types.InputStickerSetID(
id=input_sticker_set_id[0], id=set_id,
access_hash=input_sticker_set_id[1] access_hash=set_access_hash
) )
) )
)).set.short_name )).set.short_name
Sticker.cache[(set_id, set_access_hash)] = name
if len(Sticker.cache) > 250:
for i in range(50):
Sticker.cache.pop(next(iter(Sticker.cache)))
return name
except StickersetInvalid: except StickersetInvalid:
return None return None