Skip to content

Commit 7657e25

Browse files
committed
Check if the bot is allowed to interact with the sender before responding to events.
1 parent 7cbff9c commit 7657e25

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

matrix_reminder_bot/callbacks.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from matrix_reminder_bot.bot_commands import Command
1515
from matrix_reminder_bot.config import CONFIG
1616
from matrix_reminder_bot.errors import CommandError
17-
from matrix_reminder_bot.functions import send_text_to_room
17+
from matrix_reminder_bot.functions import is_allowed_user, send_text_to_room
1818
from matrix_reminder_bot.storage import Storage
1919

2020
logger = logging.getLogger(__name__)
@@ -71,6 +71,13 @@ async def message(self, room: MatrixRoom, event: RoomMessageText):
7171
if event.sender == self.client.user:
7272
return
7373

74+
# Ignore messages from disallowed users
75+
if not is_allowed_user(event.sender):
76+
logger.debug(
77+
f"Ignoring event {event.event_id} in room {room.room_id} as the sender {event.sender} is not allowed."
78+
)
79+
return
80+
7481
# Ignore broken events
7582
if not event.body:
7683
return
@@ -123,6 +130,11 @@ async def invite(self, room: MatrixRoom, event: InviteMemberEvent):
123130
"""Callback for when an invite is received. Join the room specified in the invite"""
124131
logger.debug(f"Got invite to {room.room_id} from {event.sender}.")
125132

133+
# Don't respond to invites from disallowed users
134+
if not is_allowed_user(event.sender):
135+
logger.info(f"{event.sender} is not allowed, not responding to invite.")
136+
return
137+
126138
# Attempt to join 3 times before giving up
127139
for attempt in range(3):
128140
result = await self.client.join(room.room_id)

0 commit comments

Comments
 (0)