From cc067b256963f3497395b46062d8ee7e3ea781a7 Mon Sep 17 00:00:00 2001 From: Lonami Exo Date: Sun, 5 Aug 2018 11:05:01 +0200 Subject: [PATCH] Add Conversation to the sync magic module --- telethon/sync.py | 4 ++-- telethon/tl/custom/conversation.py | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/telethon/sync.py b/telethon/sync.py index 5395f8ad..15bc5859 100644 --- a/telethon/sync.py +++ b/telethon/sync.py @@ -18,7 +18,7 @@ from async_generator import isasyncgenfunction from .client.telegramclient import TelegramClient from .tl.custom import ( - Draft, Dialog, MessageButton, Forward, Message, InlineResult + Draft, Dialog, MessageButton, Forward, Message, InlineResult, Conversation ) from .tl.custom.chatgetter import ChatGetter from .tl.custom.sendergetter import SenderGetter @@ -83,4 +83,4 @@ def syncify(*types): syncify(TelegramClient, Draft, Dialog, MessageButton, - ChatGetter, SenderGetter, Forward, Message, InlineResult) + ChatGetter, SenderGetter, Forward, Message, InlineResult, Conversation) diff --git a/telethon/tl/custom/conversation.py b/telethon/tl/custom/conversation.py index d1e8cdbb..eb9f9b85 100644 --- a/telethon/tl/custom/conversation.py +++ b/telethon/tl/custom/conversation.py @@ -420,6 +420,9 @@ class Conversation(ChatGetter): except asyncio.CancelledError: pass + def __enter__(self): + return self._client.loop.run_until_complete(self.__aenter__()) + async def __aenter__(self): self._client._conversations[self._id] = self self._input_chat = \ @@ -439,5 +442,8 @@ class Conversation(ChatGetter): return self + def __exit__(self, *args): + return self._client.loop.run_until_complete(self.__aexit__(*args)) + async def __aexit__(self, *args): del self._client._conversations[self._id]