Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check sender and bot PL before accepting room reminder #157

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions matrix_reminder_bot/bot_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<code>{sender_pl}</code>) do"
elif bot_pl < room_ping_pl:
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the use case of #80 is not possible to partially work around with PLs anymore, so it now needs to get addressed more than ever.

insufficient = f"The bot (<code>{bot_pl}</code>) does"

if insufficient is not None:
text = f"Insufficient rights: {insufficient} not have the required power level to ping the whole room (<code>{room_ping_pl}</code>)."
await send_text_to_room(self.client, self.room.room_id, text)
return True
Comment on lines +351 to +353
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
text = f"Insufficient rights: {insufficient} not have the required power level to ping the whole room (<code>{room_ping_pl}</code>)."
await send_text_to_room(self.client, self.room.room_id, text)
return True
raise CommandError(f"Insufficient rights: {insufficient} not have the required power level to ping the whole room (<code>{room_ping_pl}</code>).")


@command_syntax("[every <recurring time>;] <start time>; <reminder text>")
async def _remind_room(self):
if await self._insufficient_room_ping_pl():
return
Comment on lines +357 to +358
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if await self._insufficient_room_ping_pl():
return
self._insufficient_room_ping_pl()


"""Set a reminder that will mention the room that the reminder was created in"""
await self._remind()

Expand Down
Loading