Skip to content

Commit

Permalink
Forget last message when it gets redacted (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
rom4nik authored Oct 28, 2023
1 parent 154f73a commit 0c4ed16
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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:

Expand Down
17 changes: 13 additions & 4 deletions alternatingcaps.py
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"])]))
2 changes: 1 addition & 1 deletion maubot.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 0c4ed16

Please sign in to comment.