55from haps import *
66from telethon .tl .custom import Message , Dialog
77
8- from commons .core .routing import Event
98from commons .core .clients .userclient import IUserClient
109from commons .core .descriptors .base import EntityDescriptor
1110from commons .core .util import string_similarity
1211from telethon .tl import TLObject
1312from telethon .utils import get_display_name as telethon_get_display_name
1413
15- T = TypeVar ('P' )
14+ T = TypeVar ("P" )
1615
1716
1817class EntityNotFoundError (Exception ):
@@ -22,26 +21,32 @@ class EntityNotFoundError(Exception):
2221def get_display_name (entity : Any ):
2322 if isinstance (entity , Dialog ):
2423 return entity .name
25- if hasattr (entity , ' title' ):
24+ if hasattr (entity , " title" ):
2625 return entity .title
2726 return telethon_get_display_name (entity )
2827
28+
2929@base
3030class ILookupService (ABC ):
3131 @abstractmethod
32- async def resolve_peer (self , descriptor : EntityDescriptor , raise_ = True ): pass
32+ async def resolve_peer (self , descriptor : EntityDescriptor , raise_ = True ):
33+ pass
3334
3435 @abstractmethod
35- async def resolve_full_peer (self , descriptor : EntityDescriptor ): pass
36+ async def resolve_full_peer (self , descriptor : EntityDescriptor ):
37+ pass
3638
3739 @abstractmethod
38- async def get_message_by_id (self , chat : Any , message_id : int ) -> Message : pass
40+ async def get_message_by_id (self , chat : Any , message_id : int ) -> Message :
41+ pass
3942
4043 @abstractmethod
41- async def get_previous_messages (self , event : Event , n : int = 1 ) -> List [Message ]: pass
44+ async def get_previous_messages (self , event : Event , n : int = 1 ) -> List [Message ]:
45+ pass
4246
4347 @abstractmethod
44- async def get_last_message_in_chat (self , input_chat : Any ) -> Message : pass
48+ async def get_last_message_in_chat (self , input_chat : Any ) -> Message :
49+ pass
4550
4651
4752@egg
@@ -63,11 +68,7 @@ async def resolve_full_peer(self, descriptor: EntityDescriptor):
6368 return self .client .session .get_input_entity (descriptor )
6469
6570 async def _resolve_chat_by_title (
66- self ,
67- title : str ,
68- confidence = 0.9 ,
69- aggressive = False ,
70- raise_ = True
71+ self , title : str , confidence = 0.9 , aggressive = False , raise_ = True
7172 ) -> TLObject :
7273 results = await self .client .get_dialogs (limit = 200 )
7374
@@ -87,11 +88,7 @@ def matches_query(found_name):
8788 return None
8889
8990 async def _resolve_user_by_title (
90- self ,
91- title : str ,
92- confidence = 0.9 ,
93- aggressive = False ,
94- raise_ = True
91+ self , title : str , confidence = 0.9 , aggressive = False , raise_ = True
9592 ) -> TLObject :
9693 results = await self .client .get_dialogs (limit = 40 )
9794
@@ -104,7 +101,9 @@ def matches_query(found_name):
104101 # Search failed.
105102 for d in results :
106103 try :
107- participants = self .client .iter_participants (d .input_entity , 200 , search = '' , aggressive = aggressive )
104+ participants = self .client .iter_participants (
105+ d .input_entity , 200 , search = "" , aggressive = aggressive
106+ )
108107 async for p in participants :
109108 if matches_query (get_display_name (p )):
110109 return p .entity
0 commit comments