diff --git a/aiomax/bot.py b/aiomax/bot.py index 1550579..6ddf9a3 100644 --- a/aiomax/bot.py +++ b/aiomax/bot.py @@ -60,7 +60,7 @@ def __init__( super().__init__(case_sensitive) self.access_token: str = access_token - self.session = None + self.session: aiohttp.ClientSession | None = None self.polling = False self.command_prefixes: str | list[str] = command_prefixes @@ -76,7 +76,7 @@ def __init__( self.username: str | None = None self.name: str | None = None self.description: str | None = None - self.bot_commands: list[BotCommand] = None + self.bot_commands: list[BotCommand] | None = None self.marker: int | None = None diff --git a/aiomax/router.py b/aiomax/router.py index e9a636d..2454737 100644 --- a/aiomax/router.py +++ b/aiomax/router.py @@ -37,7 +37,7 @@ def __init__( str, list[CommandHandler] ] = {} # commands in this router self.case_sensitive: bool = case_sensitive - self.parent = None # Parent bot of this router + self.parent: Router | None = None # Parent bot of this router self.routers: list[Router] = [] self.filters: dict[str, list[Callable]] = { "message_created": [], diff --git a/aiomax/types.py b/aiomax/types.py index 7b58f6c..5c86a6a 100644 --- a/aiomax/types.py +++ b/aiomax/types.py @@ -38,7 +38,7 @@ def __init__( self.name: str = name self.username: "str | None" = username self.is_bot: bool = is_bot - self.last_activity_time: int = ( + self.last_activity_time: float | None = ( last_activity_time / 1000 if last_activity_time else None ) self.description: "str | None" = description @@ -52,7 +52,7 @@ def __init__( ) self.is_owner: "bool | None" = is_owner self.is_admin: "bool | None" = is_admin - self.join_time: "int | None" = join_time / 1000 if join_time else None + self.join_time: "float | None" = join_time / 1000 if join_time else None self.permissions: "list[str] | None" = permissions def __repr__(self): @@ -429,7 +429,7 @@ def __eq__(self, other): return False @staticmethod - def from_json(data: dict) -> "MessageRecipient": + def from_json(data: dict) -> "MessageRecipient | None": if data is None: return None @@ -523,7 +523,7 @@ def __init__( self.markup: "list[Markup] | None" = markup @staticmethod - def from_json(data: dict) -> "MessageBody": + def from_json(data: dict) -> "MessageBody | None": if data is None: return None @@ -552,7 +552,7 @@ def __init__( self.chat_id: "int | None" = chat_id @staticmethod - def from_json(data: dict) -> "LinkedMessage": + def from_json(data: dict) -> "LinkedMessage | None": if data is None: return None @@ -706,7 +706,7 @@ async def reply( | buttons.KeyboardBuilder \ | None""" = None, attachments: "list[Attachment] | Attachment | None" = None, - ) -> "Message": + ) -> "Message | None": """ Reply to this message. @@ -742,7 +742,7 @@ async def edit( | buttons.KeyboardBuilder \ | None""" = None, attachments: "list[Attachment] | Attachment | None" = None, - ) -> "Message": + ) -> "Message | None": """ Edit a message @@ -812,7 +812,7 @@ async def send( | buttons.KeyboardBuilder \ | None""" = None, attachments: "list[Attachment] | Attachment | None" = None, - ) -> "Message": + ) -> "Message | None": """ Send a message to the chat where bot was started. @@ -1040,7 +1040,7 @@ def __init__( self.chat_id: int = chat_id self.type: str = type self.status: str = status - self.last_event_time: int = ( + self.last_event_time: float | None = ( last_event_time / 1000 if last_event_time else None ) self.participants_count: int = participants_count @@ -1091,7 +1091,7 @@ def __init__( payload: "str | None" = None, ): self.bot = bot - self.timestamp: int = timestamp / 1000 + self.timestamp: float = timestamp / 1000 self.callback_id: str = callback_id self.message: "Message | None" = message self.user: User = user @@ -1115,7 +1115,7 @@ async def send( | buttons.KeyboardBuilder \ | None""" = None, attachments: "list[Attachment] | Attachment | None" = None, - ) -> "Message": + ) -> "Message | None": """ Send a message to the chat that contains the message with the pressed button. @@ -1155,7 +1155,7 @@ async def reply( | buttons.KeyboardBuilder \ | None""" = None, attachments: "list[Attachment] | Attachment | None" = None, - ) -> "Message": + ) -> "Message | None": """ Reply to the message with the button. @@ -1283,7 +1283,7 @@ def __init__( :param message_id: Message ID on which the button was :param start_payload: Start payload specified by the button """ - self.timestamp: int = timestamp / 1000 + self.timestamp: float = timestamp / 1000 self.chat: Chat = chat self.message_id: "str | None" = message_id self.start_payload: "str | None" = start_payload @@ -1321,7 +1321,7 @@ def __init__( :param chat_id: ID of the chat the message was deleted in :param user_id: ID of the user who deleted the message """ - self.timestamp: int = timestamp / 1000 + self.timestamp: float = timestamp / 1000 self.message: "Message | None" = message self.message_id: "str | None" = message_id self.chat_id: "int | None" = chat_id @@ -1366,7 +1366,7 @@ def __init__( :param chat_id: Chat ID that had its title edited. :param title: New chat title """ - self.timestamp: int = timestamp / 1000 + self.timestamp: float = timestamp / 1000 self.user: User = user self.chat_id: "int | None" = chat_id self.title: "str | None" = title @@ -1406,7 +1406,7 @@ def __init__( :param is_channel: Whether the bot got added to / kicked from a channel or not """ - self.timestamp: int = timestamp / 1000 + self.timestamp: float = timestamp / 1000 self.user: User = user self.chat_id: "int | None" = chat_id self.is_channel: bool = is_channel @@ -1449,7 +1449,7 @@ def __init__( :param initiator: User ID of the inviter / kicker, if the user got invited by another user or kicked by an admin. """ - self.timestamp: int = timestamp / 1000 + self.timestamp: float = timestamp / 1000 self.user: User = user self.chat_id: "int | None" = chat_id self.is_channel: bool = is_channel diff --git a/aiomax/utils.py b/aiomax/utils.py index 96861d7..910258f 100644 --- a/aiomax/utils.py +++ b/aiomax/utils.py @@ -1,5 +1,5 @@ from inspect import signature -from typing import Callable, Literal +from typing import Any, Callable, Literal import aiohttp @@ -21,7 +21,7 @@ def get_message_body( """ Returns the body of the message as json. """ - body = {"text": text, "format": format, "notify": notify} + body: dict[str, Any] = {"text": text, "format": format, "notify": notify} # replying if reply_to: @@ -57,7 +57,7 @@ def get_message_body( for at in attachments or []: if not hasattr(at, "as_dict"): raise exceptions.AiomaxException( - "This attachmentcannot be sent" + "This attachment cannot be sent" ) body["attachments"].append(at.as_dict())