From 757b71dff270b8ac35e1aa628e48ddd07b47986b Mon Sep 17 00:00:00 2001
From: HarHarLinks <2803622+HarHarLinks@users.noreply.github.com>
Date: Sat, 17 Feb 2024 13:54:29 +0100
Subject: [PATCH 1/2] check sender and bot PL before accepting room reminder
---
matrix_reminder_bot/bot_commands.py | 17 +++++++++++++++++
1 file changed, 17 insertions(+)
diff --git a/matrix_reminder_bot/bot_commands.py b/matrix_reminder_bot/bot_commands.py
index 877ec87..d2dba96 100644
--- a/matrix_reminder_bot/bot_commands.py
+++ b/matrix_reminder_bot/bot_commands.py
@@ -338,8 +338,25 @@ async def _remind_me(self):
"""Set a reminder that will remind only the user who created it"""
await self._remind(target=self.event.sender)
+ async def _insufficient_room_ping_pl(self):
+ room_ping_pl = self.room.power_levels.defaults.notifications.get('room')
+ sender_pl = self.room.power_levels.users.get(self.event.sender, 0)
+ bot_pl = self.room.power_levels.users.get(self.client.user_id, 0)
+ if sender_pl < room_ping_pl:
+ insufficient = f"You ({sender_pl}
) do"
+ elif bot_pl < room_ping_pl:
+ insufficient = f"The bot ({bot_pl}
) does"
+
+ if insufficient is not None:
+ text = f"Insufficient rights: {insufficient} not have the required power level to ping the whole room ({room_ping_pl}
)."
+ await send_text_to_room(self.client, self.room.room_id, text)
+ return True
+
@command_syntax("[every ;] ; ")
async def _remind_room(self):
+ if await self._insufficient_room_ping_pl():
+ return
+
"""Set a reminder that will mention the room that the reminder was created in"""
await self._remind()
From a1a121d9f757305177b31df35f9de7805dd2b67b Mon Sep 17 00:00:00 2001
From: HarHarLinks <2803622+HarHarLinks@users.noreply.github.com>
Date: Sat, 17 Feb 2024 15:11:00 +0100
Subject: [PATCH 2/2] lint
---
matrix_reminder_bot/bot_commands.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/matrix_reminder_bot/bot_commands.py b/matrix_reminder_bot/bot_commands.py
index d2dba96..4c78759 100644
--- a/matrix_reminder_bot/bot_commands.py
+++ b/matrix_reminder_bot/bot_commands.py
@@ -339,7 +339,7 @@ async def _remind_me(self):
await self._remind(target=self.event.sender)
async def _insufficient_room_ping_pl(self):
- room_ping_pl = self.room.power_levels.defaults.notifications.get('room')
+ room_ping_pl = self.room.power_levels.defaults.notifications.get("room")
sender_pl = self.room.power_levels.users.get(self.event.sender, 0)
bot_pl = self.room.power_levels.users.get(self.client.user_id, 0)
if sender_pl < room_ping_pl: