From 894316f0355186ab5211561ad0fd9a20c36ff1bb Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Fri, 28 Oct 2022 01:06:30 -0400 Subject: [PATCH] Add type checking & None check on bot login future --- mautrix_telegram/bot.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mautrix_telegram/bot.py b/mautrix_telegram/bot.py index 3d80b602..69baafe0 100644 --- a/mautrix_telegram/bot.py +++ b/mautrix_telegram/bot.py @@ -15,7 +15,7 @@ # along with this program. If not, see . from __future__ import annotations -from typing import Awaitable, Callable, Literal +from typing import TYPE_CHECKING, Awaitable, Callable, Literal import logging import time @@ -57,6 +57,9 @@ from .abstract_user import AbstractUser from .db import BotChat, Message as DBMessage from .types import TelegramID +if TYPE_CHECKING: + from asyncio import Future + ReplyFunc = Callable[[str], Awaitable[Message]] BanFunc = Callable[[RoomID, UserID, str], Awaitable[None]] TelegramAdminPermission = Literal[ @@ -87,6 +90,7 @@ class Bot(AbstractUser): tuple[int, int], tuple[ChatParticipantAdmin | ChatParticipantCreator | None, float], ] + _login_wait_fut: Future | None required_permissions: dict[str, TelegramAdminPermission] = { "portal": None, "invite": "invite_users", @@ -147,8 +151,9 @@ 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 + if self._login_wait_fut: + 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))