From 4c9069a8b1861c105e89a5420d08478446b2bb4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Thu, 8 Feb 2018 15:47:25 +0100 Subject: [PATCH] Make the room_id part of the kwargs in the MatrixMessage class. --- main.py | 3 +-- matrix/api.py | 26 +++++++++++++++++--------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/main.py b/main.py index fa92114..dd61919 100644 --- a/main.py +++ b/main.py @@ -416,8 +416,7 @@ def room_input_cb(server_name, buffer, input_data): } message = MatrixMessage(server, OPTIONS, MessageType.SEND, room_id=room_id, - formatted_message=formatted_data, - extra_data=extra_data) + formatted_message=formatted_data) server.send_or_queue(message) return W.WEECHAT_RC_OK diff --git a/matrix/api.py b/matrix/api.py index f698188..9f45949 100644 --- a/matrix/api.py +++ b/matrix/api.py @@ -222,7 +222,6 @@ class MatrixMessage: server, # type: MatrixServer options, # type: PluginOptions message_type, # type: MessageType - room_id=None, # type: str **kwargs ): # type: (...) -> None @@ -257,6 +256,7 @@ class MatrixMessage: self.request = server.client.sync(server.next_batch, sync_filter) elif message_type == MessageType.SEND: + assert self.room_id assert self.formatted_message data = {"content": formatted_to_plain(self.formatted_message)} @@ -265,40 +265,48 @@ class MatrixMessage: data["formatted_content"] = formatted_to_html( self.formatted_message) - self.room_id = room_id - self.request = server.client.room_send_message(room_id, **data) + self.request = server.client.room_send_message( + self.room_id, + **data + ) elif message_type == MessageType.TOPIC: + assert self.room_id assert self.topic - self.request = server.client.room_topic(room_id, self.topic) + self.request = server.client.room_topic(self.room_id, self.topic) elif message_type == MessageType.REDACT: + assert self.room_id assert self.event_id self.request = server.client.room_redact( - room_id, + self.room_id, self.event_id, self.reason ) elif message_type == MessageType.ROOM_MSG: + assert self.room_id assert self.token self.request = server.client.room_get_messages( - room_id, + self.room_id, start_token=self.token, limit=options.backlog_limit, ) elif message_type == MessageType.JOIN: - self.request = server.client.room_join(room_id) + assert self.room_id + self.request = server.client.room_join(self.room_id) elif message_type == MessageType.PART: - self.request = server.client.room_leave(room_id) + assert self.room_id + self.request = server.client.room_leave(self.room_id) elif message_type == MessageType.INVITE: + assert self.room_id assert self.user_id - self.request = server.client.room_invite(room_id, self.user_id) + self.request = server.client.room_invite(self.room_id, self.user_id) class MatrixUser: