Add room rule check to invites

Signed-off-by: Randshot <randshot@norealm.xyz>
This commit is contained in:
Randshot 2020-02-01 10:09:54 +01:00
parent fa6a6547ee
commit d1afb9811d
No known key found for this signature in database
GPG Key ID: 47E0D72B4F839031

View File

@ -52,6 +52,14 @@ class AntiSpam(object):
return rule.action == RECOMMENDATION_BAN return rule.action == RECOMMENDATION_BAN
return False return False
def is_room_banned(self, invite_room_id):
for room_id in self.rooms_to_lists:
ban_list = self.rooms_to_lists[room_id]
for rule in ban_list.room_rules:
if rule.matches(invite_room_id):
return rule.action == RECOMMENDATION_BAN
return False
def is_server_banned(self, server_name): def is_server_banned(self, server_name):
for room_id in self.rooms_to_lists: for room_id in self.rooms_to_lists:
ban_list = self.rooms_to_lists[room_id] ban_list = self.rooms_to_lists[room_id]
@ -91,6 +99,8 @@ class AntiSpam(object):
sender = UserID.from_string(inviter_user_id) sender = UserID.from_string(inviter_user_id)
if self.is_user_banned(sender.to_string()): if self.is_user_banned(sender.to_string()):
return False return False
if self.is_room_banned(room_id):
return False
if self.is_server_banned(sender.domain): if self.is_server_banned(sender.domain):
return False return False