From 68bb8e8b91da6e2e29d5e2cd16637d38edb808f1 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Wed, 30 May 2018 19:20:27 +0200 Subject: [PATCH] Add is_user/group/channel and title to Dialog --- telethon/tl/custom/dialog.py | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/telethon/tl/custom/dialog.py b/telethon/tl/custom/dialog.py index 74b2598a..c04b8c55 100644 --- a/telethon/tl/custom/dialog.py +++ b/telethon/tl/custom/dialog.py @@ -1,5 +1,5 @@ from . import Draft -from .. import TLObject +from .. import TLObject, types from ... import utils @@ -38,6 +38,9 @@ class Dialog: Display name for this dialog. For chats and channels this is their title, and for users it's "First-Name Last-Name". + title (`str`): + Alias for `name`. + unread_count (`int`): How many messages are currently unread in this dialog. Note that this value won't update when new messages arrive. @@ -49,6 +52,16 @@ class Dialog: draft (`telethon.tl.custom.draft.Draft`): The draft object in this dialog. It will not be ``None``, so you can call ``draft.set_message(...)``. + + is_user (`bool`): + ``True`` if the `entity` is a :tl:`User`. + + is_group (`bool`): + ``True`` if the `entity` is a :tl:`Chat` + or a :tl:`Channel` megagroup. + + is_channel (`bool`): + ``True`` if the `entity` is a :tl:`Channel`. """ def __init__(self, client, dialog, entities, messages): # Both entities and messages being dicts {ID: item} @@ -61,13 +74,20 @@ class Dialog: self.entity = entities[utils.get_peer_id(dialog.peer)] self.input_entity = utils.get_input_peer(self.entity) self.id = utils.get_peer_id(self.entity) # ^ May be InputPeerSelf() - self.name = utils.get_display_name(self.entity) + self.name = self.title = utils.get_display_name(self.entity) self.unread_count = dialog.unread_count self.unread_mentions_count = dialog.unread_mentions_count self.draft = Draft(client, dialog.peer, dialog.draft) + self.is_user = isinstance(self.entity, types.User) + self.is_group = ( + isinstance(self.entity, types.Chat) or + (isinstance(self.entity, types.Channel) and self.entity.megagroup) + ) + self.is_channel = isinstance(self.entity, types.Channel) + def send_message(self, *args, **kwargs): """ Sends a message to this dialog. This is just a wrapper around