Only allow m.text and m.emote as input

This commit is contained in:
Tulir Asokan 2019-06-23 13:57:57 +03:00
parent 54cee71497
commit 8e16575d3b

View file

@ -13,9 +13,9 @@
# #
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>. # along with this program. If not, see <https://www.gnu.org/licenses/>.
from typing import Type from typing import Type, Tuple
from mautrix.types import EventType from mautrix.types import EventType, MessageType
from mautrix.util.config import BaseProxyConfig from mautrix.util.config import BaseProxyConfig
from maubot import Plugin, MessageEvent from maubot import Plugin, MessageEvent
@ -25,6 +25,8 @@ from .config import Config, ConfigError
class ReactBot(Plugin): class ReactBot(Plugin):
allowed_msgtypes: Tuple[MessageType, ...] = (MessageType.TEXT, MessageType.EMOTE)
@classmethod @classmethod
def get_config_class(cls) -> Type[BaseProxyConfig]: def get_config_class(cls) -> Type[BaseProxyConfig]:
return Config return Config
@ -42,7 +44,7 @@ class ReactBot(Plugin):
@event.on(EventType.ROOM_MESSAGE) @event.on(EventType.ROOM_MESSAGE)
async def event_handler(self, evt: MessageEvent) -> None: async def event_handler(self, evt: MessageEvent) -> None:
if evt.sender == self.client.mxid: if evt.sender == self.client.mxid or evt.content.msgtype not in self.allowed_msgtypes:
return return
for name, rule in self.config.rules.items(): for name, rule in self.config.rules.items():
match = rule.match(evt) match = rule.match(evt)