/
events.py
61 lines (42 loc) 路 1.73 KB
/
events.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
"""Matrix specific events."""
from opsdroid.events import Event
__all__ = [
"MatrixRoomAvatar",
"MatrixHistoryVisibility",
"MatrixJoinRules",
"MatrixPowerLevels",
"MatrixStateEvent",
]
class MatrixStateEvent(Event):
"""A Generic matrix state event."""
def __init__(self, key, content, *args, state_key=None, **kwargs): # noqa: D107
super().__init__(*args, **kwargs)
self.key = key
self.content = content
self.state_key = state_key
def __repr__(self):
"""Pretty representation of state events."""
return f"<MatrixStateEvent(room_id={self.target}, key={self.key}, content={self.content})>"
class MatrixPowerLevels(MatrixStateEvent):
"""Send power levels."""
def __init__(self, power_levels, *args, **kwargs): # noqa: D107
key = "m.room.power_levels"
super().__init__(key, power_levels, *args, **kwargs)
class MatrixJoinRules(MatrixStateEvent):
"""The room's join rules."""
def __init__(self, join_rule, *args, **kwargs): # noqa: D107
key = "m.room.join_rules"
content = {"join_rule": join_rule}
super().__init__(key, content, *args, **kwargs)
class MatrixHistoryVisibility(MatrixStateEvent):
"""The room's history visibility."""
def __init__(self, history_visibility, *args, **kwargs): # noqa: D107
key = "m.room.history_visibility"
content = {"history_visibility": history_visibility}
super().__init__(key, content, *args, **kwargs)
class MatrixRoomAvatar(MatrixStateEvent):
"""The room's avatar."""
def __init__(self, url, *args, **kwargs): # noqa: D107
key = "m.room.avatar"
content = {"url": url}
super().__init__(key, content, *args, **kwargs)