mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2025-08-07 13:34:59 +03:00
optimize imports
remove extra idents add check for dialog being a channel using input_entity of dialogs
This commit is contained in:
parent
7cc15514b6
commit
dc7527c762
|
@ -1,9 +1,6 @@
|
|||
from . import Draft
|
||||
from .. import TLObject, types
|
||||
from ..functions.channels import LeaveChannelRequest
|
||||
from ..functions.messages import DeleteHistoryRequest
|
||||
from .. import TLObject, types, functions
|
||||
from ... import utils
|
||||
from ...errors import PeerIdInvalidError
|
||||
|
||||
|
||||
class Dialog:
|
||||
|
@ -66,7 +63,6 @@ class Dialog:
|
|||
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}
|
||||
self._client = client
|
||||
|
@ -87,8 +83,8 @@ class Dialog:
|
|||
|
||||
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)
|
||||
isinstance(self.entity, types.Chat) or
|
||||
(isinstance(self.entity, types.Channel) and self.entity.megagroup)
|
||||
)
|
||||
self.is_channel = isinstance(self.entity, types.Channel)
|
||||
|
||||
|
@ -101,11 +97,10 @@ class Dialog:
|
|||
self.input_entity, *args, **kwargs)
|
||||
|
||||
async def delete(self):
|
||||
try:
|
||||
await self._client(DeleteHistoryRequest(self, 0))
|
||||
|
||||
except PeerIdInvalidError:
|
||||
await self._client(LeaveChannelRequest(self))
|
||||
if self.is_channel:
|
||||
await self._client(functions.channels.LeaveChannelRequest(self.input_entity))
|
||||
else:
|
||||
await self._client(functions.messages.DeleteHistoryRequest(self.input_entity, 0))
|
||||
|
||||
def to_dict(self):
|
||||
return {
|
||||
|
|
Loading…
Reference in New Issue
Block a user