mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Handle all entity types on isinstance checks
Only the uses of `isinstance` against `InputPeer*` types were reviewed. Notably, `utils` is exempt on this because it needs to deal with everything on a case-by-case basis. Since the addition of `*FromMessage` peers, any manual `isinstance` checks to determine the type were prone to breaking or being forgotten to be updated, so a common `helpers._entity_type()` method was made to share this logic. Since the conversion to `Peer` would be too expensive, a simpler check against the name is made, which should be fast and cheap.
This commit is contained in:
@@ -3,7 +3,7 @@ import inspect
|
||||
import itertools
|
||||
import typing
|
||||
|
||||
from .. import utils, hints
|
||||
from .. import helpers, utils, hints
|
||||
from ..requestiter import RequestIter
|
||||
from ..tl import types, functions, custom
|
||||
|
||||
@@ -436,10 +436,11 @@ class DialogMethods:
|
||||
await client.delete_dialog('username')
|
||||
"""
|
||||
entity = await self.get_input_entity(entity)
|
||||
if isinstance(entity, types.InputPeerChannel):
|
||||
ty = helpers._entity_type(entity)
|
||||
if ty == helpers._EntityType.CHANNEL:
|
||||
return await self(functions.channels.LeaveChannelRequest(entity))
|
||||
|
||||
if isinstance(entity, types.InputPeerChat):
|
||||
if ty == helpers._EntityType.CHAT:
|
||||
result = await self(functions.messages.DeleteChatUserRequest(
|
||||
entity.chat_id, types.InputUserSelf()))
|
||||
else:
|
||||
|
Reference in New Issue
Block a user