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:
@@ -4,7 +4,7 @@ import itertools
|
||||
import time
|
||||
import typing
|
||||
|
||||
from .. import errors, utils, hints
|
||||
from .. import errors, helpers, utils, hints
|
||||
from ..errors import MultiError, RPCError
|
||||
from ..helpers import retry_range
|
||||
from ..tl import TLRequest, types, functions
|
||||
@@ -258,12 +258,20 @@ class UserMethods:
|
||||
else:
|
||||
inputs.append(await self.get_input_entity(x))
|
||||
|
||||
users = [x for x in inputs
|
||||
if isinstance(x, (types.InputPeerUser, types.InputPeerSelf))]
|
||||
chats = [x.chat_id for x in inputs
|
||||
if isinstance(x, types.InputPeerChat)]
|
||||
channels = [x for x in inputs
|
||||
if isinstance(x, types.InputPeerChannel)]
|
||||
lists = {
|
||||
helpers._EntityType.USER: [],
|
||||
helpers._EntityType.CHAT: [],
|
||||
helpers._EntityType.CHANNEL: [],
|
||||
}
|
||||
for x in inputs:
|
||||
try:
|
||||
lists[helpers._entity_type(x)].append(x)
|
||||
except TypeError:
|
||||
pass
|
||||
|
||||
users = lists[helpers._EntityType.USER]
|
||||
chats = lists[helpers._EntityType.CHAT]
|
||||
channels = lists[helpers._EntityType.CHANNEL]
|
||||
if users:
|
||||
# GetUsersRequest has a limit of 200 per call
|
||||
tmp = []
|
||||
|
Reference in New Issue
Block a user