From 2d95b54758e436cd7feb3da1ef7a4b18a7b7fcce Mon Sep 17 00:00:00 2001 From: Tulir Asokan Date: Wed, 17 Oct 2018 01:31:12 +0300 Subject: [PATCH] Remove event proxy class --- maubot/__init__.py | 1 - maubot/event.py | 64 ---------------------------------------------- 2 files changed, 65 deletions(-) delete mode 100644 maubot/event.py diff --git a/maubot/__init__.py b/maubot/__init__.py index 5dd2035..e829d9c 100644 --- a/maubot/__init__.py +++ b/maubot/__init__.py @@ -1,4 +1,3 @@ from .plugin_base import Plugin from .command_spec import CommandSpec, Command, PassiveCommand, Argument -from .event import FakeEvent as Event from .client import MaubotMatrixClient as Client diff --git a/maubot/event.py b/maubot/event.py deleted file mode 100644 index b779529..0000000 --- a/maubot/event.py +++ /dev/null @@ -1,64 +0,0 @@ -# maubot - A plugin-based Matrix bot system. -# Copyright (C) 2018 Tulir Asokan -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU Affero General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU Affero General Public License for more details. -# -# You should have received a copy of the GNU Affero General Public License -# along with this program. If not, see . -from typing import Awaitable, Union - -from mautrix.types import Event as MatrixEvent, EventType, MessageEventContent, MessageType, EventID -from mautrix.client.api.types.event.base import BaseRoomEvent -from mautrix.client import ClientAPI - - -class FakeEvent(BaseRoomEvent): - def __new__(cls, *args, **kwargs): - raise RuntimeError("Can't create instance of type hint header class") - - def respond(self, content: Union[str, MessageEventContent], - event_type: EventType = EventType.ROOM_MESSAGE) -> Awaitable[EventID]: - raise RuntimeError("Can't call methods of type hint header class") - - def reply(self, content: Union[str, MessageEventContent], - event_type: EventType = EventType.ROOM_MESSAGE) -> Awaitable[EventID]: - raise RuntimeError("Can't call methods of type hint header class") - - def mark_read(self) -> Awaitable[None]: - raise RuntimeError("Can't call methods of type hint header class") - - -class Event: - def __init__(self, client: ClientAPI, target: MatrixEvent): - self.client: ClientAPI = client - self.target: MatrixEvent = target - - def __getattr__(self, item): - return getattr(self.target, item) - - def __setattr__(self, key, value): - return setattr(self.target, key, value) - - def respond(self, content: Union[str, MessageEventContent], - event_type: EventType = EventType.ROOM_MESSAGE) -> Awaitable[EventID]: - if isinstance(content, str): - content = MessageEventContent(msgtype=MessageType.TEXT, body=content) - return self.client.send_message_event(self.target.room_id, event_type, content) - - def reply(self, content: Union[str, MessageEventContent], - event_type: EventType = EventType.ROOM_MESSAGE) -> Awaitable[EventID]: - if isinstance(content, str): - content = MessageEventContent(msgtype=MessageType.TEXT, body=content) - content.set_reply(self.target) - return self.client.send_message_event(self.target.room_id, event_type, content) - - def mark_read(self) -> Awaitable[None]: - return self.client.send_receipt(self.target.room_id, self.target.event_id, "m.read")