diff --git a/mautrix_telegram/commands/handler.py b/mautrix_telegram/commands/handler.py index 61e16874..958dc60a 100644 --- a/mautrix_telegram/commands/handler.py +++ b/mautrix_telegram/commands/handler.py @@ -23,8 +23,8 @@ from mautrix.bridge.commands import (HelpSection, CommandEvent as BaseCommandEve CommandHandler as BaseCommandHandler, CommandProcessor as BaseCommandProcessor, CommandHandlerFunc, command_handler as base_command_handler) +from mautrix.util.format_duration import format_duration -from ..util import format_duration from .. import user as u, context as c, portal as po @@ -77,10 +77,11 @@ class CommandHandler(BaseCommandHandler): def __init__(self, handler: Callable[[CommandEvent], Awaitable[EventID]], management_only: bool, name: str, help_text: str, help_args: str, help_section: HelpSection, needs_auth: bool, needs_puppeting: bool, - needs_matrix_puppeting: bool, needs_admin: bool) -> None: + needs_matrix_puppeting: bool, needs_admin: bool, **kwargs) -> None: super().__init__(handler, management_only, name, help_text, help_args, help_section, needs_auth=needs_auth, needs_puppeting=needs_puppeting, - needs_matrix_puppeting=needs_matrix_puppeting, needs_admin=needs_admin) + needs_matrix_puppeting=needs_matrix_puppeting, needs_admin=needs_admin, + **kwargs) async def get_permission_error(self, evt: CommandEvent) -> Optional[str]: if self.needs_puppeting and not evt.sender.puppet_whitelisted: diff --git a/mautrix_telegram/commands/telegram/auth.py b/mautrix_telegram/commands/telegram/auth.py index cc10c22d..7b8e62d5 100644 --- a/mautrix_telegram/commands/telegram/auth.py +++ b/mautrix_telegram/commands/telegram/auth.py @@ -27,11 +27,11 @@ from telethon.tl.types import User from mautrix.types import (EventID, UserID, MediaMessageEventContent, ImageInfo, MessageType, TextMessageEventContent) +from mautrix.util.format_duration import format_duration as fmt_duration from ... import user as u from ...types import TelegramID from ...commands import command_handler, CommandEvent, SECTION_AUTH -from ...util import format_duration as fmt_duration try: import qrcode diff --git a/mautrix_telegram/util/__init__.py b/mautrix_telegram/util/__init__.py index b2bfa88e..023ef0de 100644 --- a/mautrix_telegram/util/__init__.py +++ b/mautrix_telegram/util/__init__.py @@ -1,5 +1,4 @@ from .file_transfer import transfer_file_to_matrix, convert_image from .parallel_file_transfer import parallel_transfer_to_telegram -from .format_duration import format_duration from .recursive_dict import recursive_del, recursive_set, recursive_get from .color_log import ColorFormatter diff --git a/mautrix_telegram/util/format_duration.py b/mautrix_telegram/util/format_duration.py deleted file mode 100644 index d079cc0d..00000000 --- a/mautrix_telegram/util/format_duration.py +++ /dev/null @@ -1,35 +0,0 @@ -# mautrix-telegram - A Matrix-Telegram puppeting bridge -# Copyright (C) 2019 Tulir Asokan -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . - - -def format_duration(seconds: int) -> str: - def pluralize(count: int, singular: str) -> str: - return singular if count == 1 else singular + "s" - - def include(count: int, word: str) -> str: - return f"{count} {pluralize(count, word)}" if count > 0 else "" - - minutes, seconds = divmod(seconds, 60) - hours, minutes = divmod(minutes, 60) - days, hours = divmod(hours, 24) - parts = [a for a in [ - include(days, "day"), - include(hours, "hour"), - include(minutes, "minute"), - include(seconds, "second")] if a] - if len(parts) > 2: - return "{} and {}".format(", ".join(parts[:-1]), parts[-1]) - return " and ".join(parts) diff --git a/mautrix_telegram/web/common/auth_api.py b/mautrix_telegram/web/common/auth_api.py index 8b1a2dc0..c020dd54 100644 --- a/mautrix_telegram/web/common/auth_api.py +++ b/mautrix_telegram/web/common/auth_api.py @@ -24,9 +24,9 @@ from aiohttp import web from telethon.errors import * from mautrix.bridge import OnlyLoginSelf, InvalidAccessToken +from mautrix.util.format_duration import format_duration from ...commands.telegram.auth import enter_password -from ...util import format_duration from ...puppet import Puppet from ...user import User diff --git a/optional-requirements.txt b/optional-requirements.txt index 1c9b5752..d8fd7fa8 100644 --- a/optional-requirements.txt +++ b/optional-requirements.txt @@ -27,4 +27,4 @@ aiosqlite>=0.17,<0.18 #/e2be python-olm>=3,<4 pycryptodome>=3,<4 -unpaddedbase64>=1,<2 +unpaddedbase64>=1,<3 diff --git a/requirements.txt b/requirements.txt index be9bfb0e..fc7bd5e2 100644 --- a/requirements.txt +++ b/requirements.txt @@ -5,7 +5,7 @@ python-magic>=0.4,<0.5 commonmark>=0.8,<0.10 aiohttp>=3,<4 yarl>=1,<2 -mautrix>=0.13rc1,<0.14 +mautrix>=0.13.1,<0.14 telethon>=1.24,<1.25 telethon-session-sqlalchemy>=0.2.14,<0.3 # Temporarily always depend on aiosqlite to prevent breaking old installs