diff --git a/LICENSE b/LICENSE index 01a4297..4b4dd74 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022 Przemysław Romanik +Copyright (c) 2023 Przemysław Romanik Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: diff --git a/alternatingcaps.py b/alternatingcaps.py index fce4b86..a4280e1 100644 --- a/alternatingcaps.py +++ b/alternatingcaps.py @@ -1,6 +1,6 @@ -from maubot import Plugin, MessageEvent +from maubot import Plugin from maubot.handlers import command, event -from mautrix.types import EventType +from mautrix.types import EventType, MessageEvent, RedactionEvent class AlternatingCaps(Plugin): @@ -8,9 +8,18 @@ class AlternatingCaps(Plugin): @event.on(EventType.ROOM_MESSAGE) async def message_handler(self, evt: MessageEvent) -> None: - self.last_messages[evt.room_id] = evt.content.body + if evt.sender != self.client.mxid: + self.last_messages[evt.room_id] = { + "id": evt.event_id, + "body": evt.content.body + } + + @event.on(EventType.ROOM_REDACTION) + async def redaction_handler(self, evt: RedactionEvent) -> None: + if evt.room_id in self.last_messages and evt.redacts == self.last_messages[evt.room_id]["id"]: + self.last_messages.pop(evt.room_id) @command.new() async def altcaps(self, evt: MessageEvent) -> None: if evt.room_id in self.last_messages: - await evt.respond("".join([c.upper() if i % 2 else c.lower() for i, c in enumerate(self.last_messages[evt.room_id])])) + await evt.respond("".join([c.upper() if i % 2 else c.lower() for i, c in enumerate(self.last_messages[evt.room_id]["body"])])) diff --git a/maubot.yaml b/maubot.yaml index 965d64e..264fb8c 100644 --- a/maubot.yaml +++ b/maubot.yaml @@ -2,7 +2,7 @@ id: pl.rom4nik.maubot.alternatingcaps # A PEP 440 compliant version string. -version: 0.1.1 +version: 0.1.2 # The SPDX license identifier for the plugin. https://spdx.org/licenses/ # Optional, assumes all rights reserved if omitted.