improved status list formatting (html) and added save state on clear

Signed-off-by: Sebastian Schmittner <sebastian.schmittner@eecc.de>
This commit is contained in:
Sebastian Schmittner 2023-02-01 12:10:32 +01:00
parent 72acb78fba
commit 9dff166f15
No known key found for this signature in database
GPG Key ID: DF6DF57D5F9D539F
1 changed files with 17 additions and 6 deletions

View File

@ -1,3 +1,5 @@
import html
from modules.common.module import BotModule from modules.common.module import BotModule
@ -18,19 +20,28 @@ class MatrixModule(BotModule):
await bot.send_text(room, self.help()) await bot.send_text(room, self.help())
elif args[0] == "show": elif args[0] == "show":
if len(args) > 1: if len(args) > 1:
if args[1] in self.status: await self.send_status(bot=bot, room=room, user=args[1])
await bot.send_text(room, f"Status message of {args[1]}: {self.status[args[1]]}")
else: else:
await bot.send_text(room, f"No status known for {args[1]}") await self.send_status(bot=bot, room=room)
else:
await bot.send_text(room, f"All status messages:\n{self.status}")
elif args[0] == "clear": elif args[0] == "clear":
self.status.pop(event.sender) self.status.pop(event.sender)
bot.save_settings()
await bot.send_text(room, f"Cleared status of {event.sender}") await bot.send_text(room, f"Cleared status of {event.sender}")
else: else:
self.status[event.sender] = " ".join(args) self.status[event.sender] = " ".join(args)
bot.save_settings() bot.save_settings()
await bot.send_text(room, f"Status message of {event.sender}: {self.status[event.sender]}") await self.send_status(bot=bot, room=room, user=event.sender)
async def send_status(self, bot, room, user=None):
if user:
if user in self.status:
await bot.send_text(room, f"Status message of {user}: {self.status[user]}")
else:
await bot.send_text(room, f"No status known for {user}")
else:
await bot.send_html(room, "<b>All status messages:</b><br/><ul><li>" +
"</li><li>".join([f"<b>{html.escape(key)}:</b> {html.escape(value)}" for key, value in self.status.items()]) +
"</li></ul>", f"All status messages:\n{self.status}")
def get_settings(self): def get_settings(self):
data = super().get_settings() data = super().get_settings()