diff --git a/dev/release.sh b/dev/release.sh index a94dafa..e920cbd 100755 --- a/dev/release.sh +++ b/dev/release.sh @@ -12,7 +12,7 @@ printf '\nPerforming last-minute formatting...\n' black src isort src git add . || true -git commit -am "Format code for release $VERSION" || true +git commit -am "[auto] Format code for release $VERSION" || true printf '\nCreating release branch...\n' git tag -m "Release $VERSION_P" "$VERSION" diff --git a/src/niobot/client.py b/src/niobot/client.py index 9e2434b..0e32ddc 100644 --- a/src/niobot/client.py +++ b/src/niobot/client.py @@ -20,7 +20,6 @@ from .attachment import BaseAttachment from .commands import Command, Module from .exceptions import * -from .patches.nio__responses import DirectRoomsErrorResponse, DirectRoomsResponse from .utils import Typing, force_await, run_blocking from .utils.help_command import default_help_command @@ -734,20 +733,10 @@ async def get_dm_rooms( :param user: The user ID or object to get DM rooms for. :return: A dictionary of user IDs to lists of rooms, or a list of rooms. """ - # When https://github.com/poljar/matrix-nio/pull/451/ is merged in the next version of matrix-nio, - # this function should be changed to use Api.list_direct_rooms. - # For now, I'll just pull the code from the PR and whack it in here. - # It's ugly, but it's better than what we had before: - # https://github.com/nexy7574/niobot/blob/216509/src/niobot/client.py#L668-L701 - - result = await self._send( - DirectRoomsResponse, - "GET", - nio.Api._build_path( - ["user", self.user_id, "account_data", "m.direct"], {"access-token", self.access_token} - ), - ) - if isinstance(result, DirectRoomsErrorResponse): + if not hasattr(self, "list_direct_rooms"): + raise RuntimeError("You must have matrix-nio version 0.24.0 or later to use this feature.") + result = await self.list_direct_rooms() + if isinstance(result, nio.DirectRoomsErrorResponse()): raise GenericMatrixError("Failed to get DM rooms", response=result) if user: user_id = self._get_id(user) diff --git a/src/niobot/patches/nio__responses.py b/src/niobot/patches/nio__responses.py index 7f4159d..e3454c9 100644 --- a/src/niobot/patches/nio__responses.py +++ b/src/niobot/patches/nio__responses.py @@ -1,33 +1,8 @@ +# OUTDATED AND NOT USED ANYMORE # Pull from https://github.com/poljar/matrix-nio/pull/451 temporarily. -from dataclasses import dataclass, field -from typing import Any, Dict, List, Union - -from nio.responses import ErrorResponse, Response +from nio.responses import DirectRoomsErrorResponse, DirectRoomsResponse __all__ = ( "DirectRoomsErrorResponse", "DirectRoomsResponse", -) - - -class DirectRoomsErrorResponse(ErrorResponse): - pass - - -@dataclass -class DirectRoomsResponse(Response): - """A response containing a list of direct rooms. - Attributes: - rooms (List[str]): The rooms joined by the account. - """ - - rooms: Dict[str, List[str]] = field() - - @classmethod - def from_dict( - cls, - parsed_dict: Dict[Any, Any], - ) -> Union["DirectRoomsResponse", DirectRoomsErrorResponse]: - if parsed_dict.get("errcode") is not None: - return DirectRoomsErrorResponse.from_dict(parsed_dict) - return cls(parsed_dict) +) \ No newline at end of file