2023-04-24 08:48:59 +00:00
|
|
|
from nio.events.room_events import RoomMessageText
|
|
|
|
from nio.rooms import MatrixRoom
|
|
|
|
|
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
async def command_systemmessage(room: MatrixRoom, event: RoomMessageText, bot):
|
2023-04-24 08:48:59 +00:00
|
|
|
system_message = " ".join(event.body.split()[2:])
|
|
|
|
|
|
|
|
if system_message:
|
2023-04-25 11:25:53 +00:00
|
|
|
bot.logger.log("Adding system message...")
|
2023-04-24 08:48:59 +00:00
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
with bot.database.cursor() as cur:
|
2023-04-24 08:48:59 +00:00
|
|
|
cur.execute(
|
2023-05-01 08:12:50 +00:00
|
|
|
"""
|
|
|
|
INSERT INTO room_settings (room_id, setting, value) VALUES (?, ?, ?)
|
|
|
|
ON CONFLICT (room_id, setting) DO UPDATE SET value = ?;
|
|
|
|
""",
|
|
|
|
(room.room_id, "system_message", system_message, system_message)
|
2023-04-24 08:48:59 +00:00
|
|
|
)
|
|
|
|
|
2023-05-01 06:11:43 +00:00
|
|
|
await bot.send_message(room, f"Alright, I've stored the system message: '{system_message}'.", True)
|
2023-04-25 11:25:53 +00:00
|
|
|
return
|
2023-04-24 08:48:59 +00:00
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
bot.logger.log("Retrieving system message...")
|
2023-04-24 08:48:59 +00:00
|
|
|
|
2023-04-25 11:25:53 +00:00
|
|
|
system_message = bot.get_system_message(room)
|
2023-04-24 08:48:59 +00:00
|
|
|
|
2023-05-01 08:12:50 +00:00
|
|
|
await bot.send_message(room, f"The current system message is: '{system_message}'.", True)
|