Merge pull request #232 from european-epc-competence-center/status_module
improved status list formatting (html) and added save state on clear
This commit is contained in:
commit
5da7e36e94
|
@ -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()
|
||||||
|
|
Loading…
Reference in New Issue