MatrixGPT/matrix_gpt/bot/message_responses.py

56 lines
1.4 KiB
Python
Raw Normal View History

2023-03-18 02:14:45 -06:00
import logging
from nio import AsyncClient, MatrixRoom, RoomMessageText
from .chat_functions import send_text_to_room
# from .config import Config
from .storage import Storage
logger = logging.getLogger('MatrixGPT')
class Message:
def __init__(
self,
client: AsyncClient,
store: Storage,
# config: Config,
message_content: str,
room: MatrixRoom,
event: RoomMessageText,
openai,
):
"""Initialize a new Message
Args:
client: nio client used to interact with matrix.
store: Bot storage.
config: Bot configuration parameters.
message_content: The body of the message.
room: The room the event came from.
event: 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) -> None:
"""Process and possibly respond to the message"""
if self.message_content.lower() == "hello world":
await self._hello_world()
async def _hello_world(self) -> None:
"""Say hello"""
text = "Hello, world!"
await send_text_to_room(self.client, self.room.room_id, text)