Fix some bugs

This commit is contained in:
Tulir Asokan
2022-09-20 01:59:47 +03:00
parent 4db09f2240
commit 4210091e9a
4 changed files with 15 additions and 8 deletions
+6 -5
View File
@@ -301,17 +301,18 @@ class AbstractUser(ABC):
async def ensure_started(self, even_if_no_session=False) -> AbstractUser:
if self.connected:
return self
if even_if_no_session or await PgSession.has(self.mxid):
session_exists = await PgSession.has(self.mxid)
if even_if_no_session or session_exists:
self.log.debug(
"Starting client due to ensure_started"
f"(even_if_no_session={even_if_no_session})"
f"Starting client due to ensure_started({even_if_no_session=}, {session_exists=})"
)
await self.start(delete_unless_authenticated=not even_if_no_session)
return self
async def stop(self) -> None:
await self.client.disconnect()
self.client = None
if self.client:
await self.client.disconnect()
self.client = None
# region Telegram update handling
+5
View File
@@ -113,6 +113,7 @@ class Bot(AbstractUser):
)
self._me_info = None
self._me_mxid = None
self._login_wait_fut = self.loop.create_future()
async def get_me(self, use_cache: bool = True) -> tuple[User, UserID]:
if not use_cache or not self._me_mxid:
@@ -146,6 +147,8 @@ class Bot(AbstractUser):
self.tgid = TelegramID(info.id)
self.tg_username = info.username
self.mxid = pu.Puppet.get_mxid_from_id(self.tgid)
self._login_wait_fut.set_result(None)
self._login_wait_fut = None
chat_ids = [chat_id for chat_id, chat_type in self.chats.items() if chat_type == "chat"]
response = await self.client(GetChatsRequest(chat_ids))
@@ -418,6 +421,8 @@ class Bot(AbstractUser):
await self.add_chat(TelegramID(action.channel_id), "channel")
async def update(self, update) -> bool:
if self._login_wait_fut:
await self._login_wait_fut
if not isinstance(update, (UpdateNewMessage, UpdateNewChannelMessage)):
return False
if isinstance(update.message, MessageService):
+3 -2
View File
@@ -421,10 +421,11 @@ class User(DBUser, AbstractUser, BaseUser):
pass
self.tgid = None
ok = await self.client.log_out()
await self.client.session.delete()
sess = self.client.session
await self.stop()
await sess.delete()
await self.delete()
self.by_mxid.pop(self.mxid, None)
await self.stop()
self._track_metric(METRIC_LOGGED_IN, False)
return ok
+1 -1
View File
@@ -5,7 +5,7 @@ aiohttp>=3,<4
yarl>=1,<2
mautrix>=0.18.1,<0.19
#telethon>=1.24,<1.25
tulir-telethon==1.26.0a2
tulir-telethon==1.26.0a3
asyncpg>=0.20,<0.27
mako>=1,<2
setuptools