mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-10 19:46:36 +03:00
Add chat_id-like convenience properties to the events
This commit is contained in:
parent
259bb6ace1
commit
93b5909be5
|
@ -251,7 +251,7 @@ class ChatAction(EventBuilder):
|
|||
@property
|
||||
def user(self):
|
||||
"""
|
||||
The single user that takes part in this action (e.g. joined).
|
||||
The first user that takes part in this action (e.g. joined).
|
||||
|
||||
Might be ``None`` if the information can't be retrieved or
|
||||
there is no user taking part.
|
||||
|
@ -267,6 +267,14 @@ class ChatAction(EventBuilder):
|
|||
if self.input_users:
|
||||
return self._input_users[0]
|
||||
|
||||
@property
|
||||
def user_id(self):
|
||||
"""
|
||||
Returns the marked signed ID of the first user, if any.
|
||||
"""
|
||||
if self.input_users:
|
||||
return utils.get_peer_id(self._input_users[0])
|
||||
|
||||
@property
|
||||
def users(self):
|
||||
"""
|
||||
|
@ -311,3 +319,11 @@ class ChatAction(EventBuilder):
|
|||
except (TypeError, ValueError):
|
||||
pass
|
||||
return self._input_users
|
||||
|
||||
@property
|
||||
def user_ids(self):
|
||||
"""
|
||||
Returns the marked signed ID of the users, if any.
|
||||
"""
|
||||
if self.input_users:
|
||||
return [utils.get_peer_id(u) for u in self._input_users]
|
||||
|
|
|
@ -192,6 +192,14 @@ class EventCommon(abc.ABC):
|
|||
|
||||
return self._chat
|
||||
|
||||
@property
|
||||
def chat_id(self):
|
||||
"""
|
||||
Returns the marked integer ID of the chat, if any.
|
||||
"""
|
||||
if self._chat_peer:
|
||||
return utils.get_peer_id(self._chat_peer)
|
||||
|
||||
def __str__(self):
|
||||
return TLObject.pretty_format(self.to_dict())
|
||||
|
||||
|
|
|
@ -258,6 +258,14 @@ class NewMessage(EventBuilder):
|
|||
|
||||
return self._sender
|
||||
|
||||
@property
|
||||
def sender_id(self):
|
||||
"""
|
||||
Returns the marked sender integer ID, if present.
|
||||
"""
|
||||
if self.input_sender:
|
||||
return utils.get_peer_id(self._input_sender)
|
||||
|
||||
@property
|
||||
def text(self):
|
||||
"""
|
||||
|
|
|
@ -151,3 +151,13 @@ class UserUpdate(EventBuilder):
|
|||
def user(self):
|
||||
"""Alias around the chat (conversation)."""
|
||||
return self.chat
|
||||
|
||||
@property
|
||||
def input_user(self):
|
||||
"""Alias around the input chat."""
|
||||
return self.input_chat
|
||||
|
||||
@property
|
||||
def user_id(self):
|
||||
"""Alias around `chat_id`."""
|
||||
return self.chat_id
|
||||
|
|
Loading…
Reference in New Issue
Block a user