generated from 8go/nio-template
-
Notifications
You must be signed in to change notification settings - Fork 15
/
message_responses.py
59 lines (39 loc) · 1.57 KB
/
message_responses.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
#!/usr/bin/env python3
r"""message_responses.py.
0123456789012345678901234567890123456789012345678901234567890123456789012345678
0000000000111111111122222222223333333333444444444455555555556666666666777777777
# message_responses.py
Don't change tabbing, spacing, or formating as the
file is automatically linted and beautified.
"""
from chat_functions import send_text_to_room
import logging
logger = logging.getLogger(__name__)
class Message(object):
"""Process messages."""
def __init__(self, client, store, config, message_content, room, event):
"""Initialize a new Message.
Arguments:
---------
client (nio.AsyncClient): nio client used to interact with matrix
store (Storage): Bot storage
config (Config): Bot configuration parameters
message_content (str): The body of the message
room (nio.rooms.MatrixRoom): The room the event came from
event (nio.events.room_events.RoomMessageText): The event defining
the message
"""
self.client = client
self.store = store
self.config = config
self.message_content = message_content
self.room = room
self.event = event
async def process(self):
"""Process and possibly respond to the message."""
if self.message_content.lower() == "hello world":
await self._hello_world()
async def _hello_world(self):
"""Say hello."""
text = "Hello, world!"
await send_text_to_room(self.client, self.room.room_id, text)