Add join/part message class.

This commit is contained in:
poljar (Damir Jelić) 2018-02-12 13:51:45 +01:00
parent dbf7df2e84
commit 7be29e2b3f
2 changed files with 35 additions and 9 deletions

View file

@ -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

View file

@ -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)