Merge pull request #861 from vector-im/bot-future-type-check

Add type checking & None check on bot login future
This commit is contained in:
Tulir Asokan
2022-10-31 14:36:19 +02:00
committed by GitHub
+6 -1
View File
@@ -15,7 +15,7 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from __future__ import annotations from __future__ import annotations
from typing import Awaitable, Callable, Literal from typing import TYPE_CHECKING, Awaitable, Callable, Literal
import logging import logging
import time import time
@@ -57,6 +57,9 @@ from .abstract_user import AbstractUser
from .db import BotChat, Message as DBMessage from .db import BotChat, Message as DBMessage
from .types import TelegramID from .types import TelegramID
if TYPE_CHECKING:
from asyncio import Future
ReplyFunc = Callable[[str], Awaitable[Message]] ReplyFunc = Callable[[str], Awaitable[Message]]
BanFunc = Callable[[RoomID, UserID, str], Awaitable[None]] BanFunc = Callable[[RoomID, UserID, str], Awaitable[None]]
TelegramAdminPermission = Literal[ TelegramAdminPermission = Literal[
@@ -87,6 +90,7 @@ class Bot(AbstractUser):
tuple[int, int], tuple[int, int],
tuple[ChatParticipantAdmin | ChatParticipantCreator | None, float], tuple[ChatParticipantAdmin | ChatParticipantCreator | None, float],
] ]
_login_wait_fut: Future | None
required_permissions: dict[str, TelegramAdminPermission] = { required_permissions: dict[str, TelegramAdminPermission] = {
"portal": None, "portal": None,
"invite": "invite_users", "invite": "invite_users",
@@ -147,6 +151,7 @@ class Bot(AbstractUser):
self.tgid = TelegramID(info.id) self.tgid = TelegramID(info.id)
self.tg_username = info.username self.tg_username = info.username
self.mxid = pu.Puppet.get_mxid_from_id(self.tgid) self.mxid = pu.Puppet.get_mxid_from_id(self.tgid)
if self._login_wait_fut:
self._login_wait_fut.set_result(None) self._login_wait_fut.set_result(None)
self._login_wait_fut = None self._login_wait_fut = None