-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Forget last message when it gets redacted (#2)
- Loading branch information
Showing
3 changed files
with
15 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,25 @@ | ||
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): | ||
last_messages = {} | ||
|
||
@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"])])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters