-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Properly implement DM room creation & retrieval #15
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, just a couple (mainly formatting) things that need doing before this can be merged :)
|
||
room = self.rooms.get(response.room_id) | ||
if not room: | ||
raise RuntimeError("DM room %r was created, but could not be found in the room list!" % room_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add documentation for the RuntimeError exception into the docstring? only ValueError and MessageException are documented at the moment
src/niobot/client.py
Outdated
await self._send( | ||
nio.DirectRoomsResponse, | ||
'PUT', | ||
nio.Api._build_path( ["user", self.user_id, "account_data", "m.direct"], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The whitespace is a little odd here - could you run ruff check --fix
and ruff format
& push on your fork? just for styling consistency
src/niobot/client.py
Outdated
) | ||
if isinstance(result, nio.RoomCreateError): | ||
raise GenericMatrixError("Failed to create DM room", response=result) | ||
|
||
dm_rooms = {} | ||
dm_rooms[user_id] = [result.room_id] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just being pedantic here but wouldn't it be cleaner to just do dm_rooms = {user_id: [result.room_id]}
?
Fixed the comments. Not sure how to submit PR again. |
No need to re-submit, changes are automatically added to the PR :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
All checks passed, merging. |
This is a bug fix for the send_message, get_dm_rooms, and create_dm_room functions.
I also added code to do a lazy check if there are rooms that are on the server, but not on the bot. I am not sure
why this is happening.
I added a call to set the m.direct type on the newly created dm_room. This is not really supported by
the nio-sdk library, which is missing the MDirectResponse type.