mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-25 10:53:44 +03:00
Introduce PeerRef.SELF
This commit is contained in:
parent
c9006024e2
commit
9d17f36f7a
|
@ -11,6 +11,8 @@ from ...tl import abcs, types
|
||||||
PeerIdentifier: TypeAlias = int
|
PeerIdentifier: TypeAlias = int
|
||||||
PeerAuth: TypeAlias = Optional[int]
|
PeerAuth: TypeAlias = Optional[int]
|
||||||
|
|
||||||
|
SELF_USER_SENTINEL_ID = 0
|
||||||
|
|
||||||
USER_PREFIX = "u."
|
USER_PREFIX = "u."
|
||||||
GROUP_PREFIX = "g."
|
GROUP_PREFIX = "g."
|
||||||
CHANNEL_PREFIX = "c."
|
CHANNEL_PREFIX = "c."
|
||||||
|
@ -50,6 +52,13 @@ class PeerRef(abc.ABC):
|
||||||
self.identifier = identifier
|
self.identifier = identifier
|
||||||
self.authorization = authorization
|
self.authorization = authorization
|
||||||
|
|
||||||
|
SELF: UserRef
|
||||||
|
"""
|
||||||
|
A special :class:`UserRef` that can be used to refer to the logged-in user.
|
||||||
|
|
||||||
|
Who this user is will depend on the client instance making the request.
|
||||||
|
"""
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_str(cls, string: str, /) -> UserRef | GroupRef | ChannelRef:
|
def from_str(cls, string: str, /) -> UserRef | GroupRef | ChannelRef:
|
||||||
"""
|
"""
|
||||||
|
@ -166,14 +175,20 @@ class UserRef(PeerRef):
|
||||||
return ref
|
return ref
|
||||||
|
|
||||||
def _to_peer(self) -> abcs.Peer:
|
def _to_peer(self) -> abcs.Peer:
|
||||||
|
if self.identifier == SELF_USER_SENTINEL_ID:
|
||||||
|
raise ValueError("cannot obtain Peer from PeerRef.SELF")
|
||||||
return types.PeerUser(user_id=self.identifier)
|
return types.PeerUser(user_id=self.identifier)
|
||||||
|
|
||||||
def _to_input_peer(self) -> abcs.InputPeer:
|
def _to_input_peer(self) -> abcs.InputPeer:
|
||||||
|
if self.identifier == SELF_USER_SENTINEL_ID:
|
||||||
|
return types.InputPeerSelf()
|
||||||
return types.InputPeerUser(
|
return types.InputPeerUser(
|
||||||
user_id=self.identifier, access_hash=self.authorization or 0
|
user_id=self.identifier, access_hash=self.authorization or 0
|
||||||
)
|
)
|
||||||
|
|
||||||
def _to_input_user(self) -> types.InputUser:
|
def _to_input_user(self) -> abcs.InputUser:
|
||||||
|
if self.identifier == SELF_USER_SENTINEL_ID:
|
||||||
|
return types.InputUserSelf()
|
||||||
return types.InputUser(
|
return types.InputUser(
|
||||||
user_id=self.identifier, access_hash=self.authorization or 0
|
user_id=self.identifier, access_hash=self.authorization or 0
|
||||||
)
|
)
|
||||||
|
@ -252,3 +267,6 @@ class ChannelRef(PeerRef):
|
||||||
@property
|
@property
|
||||||
def _ref(self) -> Self:
|
def _ref(self) -> Self:
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
|
||||||
|
PeerRef.SELF = UserRef(SELF_USER_SENTINEL_ID)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user