mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-07 21:44:57 +03:00
add delete method for dialogs
This commit is contained in:
parent
785071a5cd
commit
7cc15514b6
|
@ -1,6 +1,9 @@
|
||||||
from . import Draft
|
from . import Draft
|
||||||
from .. import TLObject, types
|
from .. import TLObject, types
|
||||||
|
from ..functions.channels import LeaveChannelRequest
|
||||||
|
from ..functions.messages import DeleteHistoryRequest
|
||||||
from ... import utils
|
from ... import utils
|
||||||
|
from ...errors import PeerIdInvalidError
|
||||||
|
|
||||||
|
|
||||||
class Dialog:
|
class Dialog:
|
||||||
|
@ -63,6 +66,7 @@ class Dialog:
|
||||||
is_channel (`bool`):
|
is_channel (`bool`):
|
||||||
``True`` if the `entity` is a :tl:`Channel`.
|
``True`` if the `entity` is a :tl:`Channel`.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, client, dialog, entities, messages):
|
def __init__(self, client, dialog, entities, messages):
|
||||||
# Both entities and messages being dicts {ID: item}
|
# Both entities and messages being dicts {ID: item}
|
||||||
self._client = client
|
self._client = client
|
||||||
|
@ -83,8 +87,8 @@ class Dialog:
|
||||||
|
|
||||||
self.is_user = isinstance(self.entity, types.User)
|
self.is_user = isinstance(self.entity, types.User)
|
||||||
self.is_group = (
|
self.is_group = (
|
||||||
isinstance(self.entity, types.Chat) or
|
isinstance(self.entity, types.Chat) or
|
||||||
(isinstance(self.entity, types.Channel) and self.entity.megagroup)
|
(isinstance(self.entity, types.Channel) and self.entity.megagroup)
|
||||||
)
|
)
|
||||||
self.is_channel = isinstance(self.entity, types.Channel)
|
self.is_channel = isinstance(self.entity, types.Channel)
|
||||||
|
|
||||||
|
@ -96,6 +100,13 @@ class Dialog:
|
||||||
return await self._client.send_message(
|
return await self._client.send_message(
|
||||||
self.input_entity, *args, **kwargs)
|
self.input_entity, *args, **kwargs)
|
||||||
|
|
||||||
|
async def delete(self):
|
||||||
|
try:
|
||||||
|
await self._client(DeleteHistoryRequest(self, 0))
|
||||||
|
|
||||||
|
except PeerIdInvalidError:
|
||||||
|
await self._client(LeaveChannelRequest(self))
|
||||||
|
|
||||||
def to_dict(self):
|
def to_dict(self):
|
||||||
return {
|
return {
|
||||||
'_': 'Dialog',
|
'_': 'Dialog',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user