mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-08 12:59:46 +00:00
Create a convenient class to wrap Dialog instances
This commit is contained in:
37
telethon/tl/custom/dialog.py
Normal file
37
telethon/tl/custom/dialog.py
Normal file
@@ -0,0 +1,37 @@
|
||||
from . import Draft
|
||||
from ... import utils
|
||||
|
||||
|
||||
class Dialog:
|
||||
"""
|
||||
Custom class that encapsulates a dialog (an open "conversation" with
|
||||
someone, a group or a channel) providing an abstraction to easily
|
||||
access the input version/normal entity/message etc. The library will
|
||||
return instances of this class when calling `client.get_dialogs()`.
|
||||
"""
|
||||
def __init__(self, client, dialog, entities, messages):
|
||||
# Both entities and messages being dicts {ID: item}
|
||||
self._client = client
|
||||
self.dialog = dialog
|
||||
self.pinned = bool(dialog.pinned)
|
||||
self.message = messages.get(dialog.top_message, None)
|
||||
self.date = getattr(self.message, 'date', None)
|
||||
|
||||
self.entity = entities[utils.get_peer_id(dialog.peer, add_mark=True)]
|
||||
self.input_entity = utils.get_input_peer(self.entity)
|
||||
self.name = utils.get_display_name(self.entity)
|
||||
|
||||
self.unread_count = dialog.unread_count
|
||||
self.unread_mentions_count = dialog.unread_mentions_count
|
||||
|
||||
if dialog.draft:
|
||||
self.draft = Draft(client, dialog.peer, dialog.draft)
|
||||
else:
|
||||
self.draft = None
|
||||
|
||||
def send_message(self, *args, **kwargs):
|
||||
"""
|
||||
Sends a message to this dialog. This is just a wrapper around
|
||||
client.send_message(dialog.input_entity, *args, **kwargs).
|
||||
"""
|
||||
return self._client.send_message(self.input_entity, *args, **kwargs)
|
Reference in New Issue
Block a user