22
22
from telethon .tl .types import (TypeUpdate , UpdateNewMessage , UpdateNewChannelMessage ,
23
23
UpdateShortChatMessage , UpdateShortMessage , User as TLUser , Chat ,
24
24
ChatForbidden , UpdateFolderPeers , UpdatePinnedDialogs ,
25
- UpdateNotifySettings , NotifyPeer )
25
+ UpdateNotifySettings , NotifyPeer , InputUserSelf )
26
26
from telethon .tl .custom import Dialog
27
27
from telethon .tl .types .contacts import ContactsNotModified
28
28
from telethon .tl .functions .contacts import GetContactsRequest , SearchRequest
29
29
from telethon .tl .functions .account import UpdateStatusRequest
30
- from telethon .errors import AuthKeyDuplicatedError
30
+ from telethon .tl .functions .users import GetUsersRequest
31
+ from telethon .errors import (AuthKeyDuplicatedError , UserDeactivatedError , UserDeactivatedBanError ,
32
+ SessionRevokedError , UnauthorizedError )
31
33
32
34
from mautrix .client import Client
33
35
from mautrix .errors import MatrixRequestError , MNotFound
@@ -333,8 +335,22 @@ async def set_presence(self, online: bool = True) -> None:
333
335
if not self .is_bot :
334
336
await self .client (UpdateStatusRequest (offline = not online ))
335
337
338
+ async def get_me (self ) -> Optional [TLUser ]:
339
+ try :
340
+ return (await self .client (GetUsersRequest ([InputUserSelf ()])))[0 ]
341
+ except UnauthorizedError as e :
342
+ self .log .error (f"Authorization error in get_me(): { e } " )
343
+ await self .push_bridge_state (BridgeStateEvent .BAD_CREDENTIALS , error = "tg-auth-error" ,
344
+ message = str (e ), ttl = 3600 )
345
+ await self .stop ()
346
+ return None
347
+
336
348
async def update_info (self , info : TLUser = None ) -> None :
337
- info = info or await self .client .get_me ()
349
+ if not info :
350
+ info = await self .get_me ()
351
+ if not info :
352
+ self .log .warning ("get_me() returned None, aborting update_info()" )
353
+ return
338
354
changed = False
339
355
if self .is_bot != info .bot :
340
356
self .is_bot = info .bot
@@ -350,6 +366,7 @@ async def update_info(self, info: TLUser = None) -> None:
350
366
self .by_tgid [self .tgid ] = self
351
367
if changed :
352
368
await self .save ()
369
+ return info
353
370
354
371
async def log_out (self ) -> bool :
355
372
puppet = pu .Puppet .get (self .tgid )
0 commit comments