2019-10-04 15:44:19 +02:00
|
|
|
import logging
|
|
|
|
|
2020-08-10 00:02:07 +02:00
|
|
|
from my_project_name.chat_functions import send_text_to_room
|
|
|
|
|
2019-10-04 15:44:19 +02:00
|
|
|
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"""
|
2019-10-26 01:28:29 +02:00
|
|
|
if self.message_content.lower() == "hello world":
|
2019-11-08 00:31:18 +01:00
|
|
|
await self._hello_world()
|
2019-10-26 01:28:29 +02:00
|
|
|
|
2019-11-08 00:31:18 +01:00
|
|
|
async def _hello_world(self):
|
2019-10-26 01:28:29 +02:00
|
|
|
"""Say hello"""
|
|
|
|
text = "Hello, world!"
|
|
|
|
await send_text_to_room(self.client, self.room.room_id, text)
|