generated from anoadragon453/nio-template
-
Notifications
You must be signed in to change notification settings - Fork 2
/
message_responses.py
42 lines (29 loc) · 1.18 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
# coding=utf-8
import logging
from chat_functions import send_text_to_room
logger = logging.getLogger(__name__)
class Message(object):
def __init__(self, client, store, config, message_content, room, event):
"""Initialize a new Message
Args:
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)