From 7be29e2b3f4afbff81d3e8d1ea31d57c5a3dca9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?poljar=20=28Damir=20Jeli=C4=87=29?= Date: Mon, 12 Feb 2018 13:51:45 +0100 Subject: [PATCH] Add join/part message class. --- matrix/api.py | 28 ++++++++++++++++++++++++++++ matrix/commands.py | 16 +++++++--------- 2 files changed, 35 insertions(+), 9 deletions(-) diff --git a/matrix/api.py b/matrix/api.py index dcb4fa6..021816d 100644 --- a/matrix/api.py +++ b/matrix/api.py @@ -450,6 +450,34 @@ class MatrixBacklogMessage(MatrixGenericMessage): ) +class MatrixJoinMessage(MatrixGenericMessage): + def __init__(self, client, room_id): + self.room_id = room_id + + data = {"room_id": self.room_id} + + MatrixGenericMessage.__init__( + self, + MessageType.JOIN, + client.room_join, + data + ) + + +class MatrixPartMessage(MatrixGenericMessage): + def __init__(self, client, room_id): + self.room_id = room_id + + data = {"room_id": self.room_id} + + MatrixGenericMessage.__init__( + self, + MessageType.PART, + client.room_leave, + data + ) + + class MatrixUser: def __init__(self, name, display_name): self.name = name # type: str diff --git a/matrix/commands.py b/matrix/commands.py index d1be2a3..f388435 100644 --- a/matrix/commands.py +++ b/matrix/commands.py @@ -29,7 +29,9 @@ from matrix.api import ( MessageType, MatrixTopicMessage, MatrixRedactMessage, - MatrixBacklogMessage + MatrixBacklogMessage, + MatrixJoinMessage, + MatrixPartMessage ) from matrix.utils import key_from_value, tags_from_line_data from matrix.plugin_options import DebugType @@ -190,10 +192,8 @@ def matrix_command_join_cb(data, buffer, command): return _, room_id = split_args - message = MatrixMessage( - server, - OPTIONS, - MessageType.JOIN, + message = MatrixJoinMessage( + server.client, room_id=room_id ) server.send_or_queue(message) @@ -231,10 +231,8 @@ def matrix_command_part_cb(data, buffer, command): rooms = rooms.split(" ") for room_id in rooms: - message = MatrixMessage( - server, - OPTIONS, - MessageType.PART, + message = MatrixPartMessage( + server.client, room_id=room_id ) server.send_or_queue(message)