Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Commit

Permalink
Disallow ignoring hungryserv bridge bots as well
Browse files Browse the repository at this point in the history
  • Loading branch information
bradtgmurray committed Feb 13, 2023
1 parent c162554 commit 431eed9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
9 changes: 7 additions & 2 deletions synapse/storage/databases/main/account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
logger = logging.getLogger(__name__)

# Regex pattern for detecting a bridge bot (cached here for performance)
BOT_PATTERN = re.compile(r"^@_.*_bot\:.*")
SYNAPSE_BOT_PATTERN = re.compile(r"^@_.*_bot\:*")
HUNGRYSERV_BOT_PATTERN = re.compile(r"^@[a-z]+bot\:beeper.local")


class AccountDataWorkerStore(PushRulesWorkerStore, CacheInvalidationWorkerStore):
Expand Down Expand Up @@ -619,7 +620,11 @@ def _add_account_data_for_user(
ignored_users = content.get("ignored_users", {})
if isinstance(ignored_users, dict):
content["ignored_users"] = {
u: v for u, v in ignored_users.items() if not BOT_PATTERN.match(u)
u: v
for u, v in ignored_users.items()
if not (
SYNAPSE_BOT_PATTERN.match(u) or HUNGRYSERV_BOT_PATTERN.match(u)
)
}

# no need to lock here as account_data has a unique constraint on
Expand Down
8 changes: 7 additions & 1 deletion tests/storage/test_account_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,13 @@ def test_ignoring_bot_users(self) -> None:
self._update_ignore_list("@other:test", "@another:remote", "@_other_bot:test")
self.assert_ignored(self.user, {"@other:test", "@another:remote"})

self._update_ignore_list("@_other_bot:test")
self._update_ignore_list("@iamnotabot:beeper.com")
self.assert_ignored(self.user, {"@iamnotabot:beeper.com"})

self._update_ignore_list("@_other_bot:beeper.com")
self.assert_ignored(self.user, set())

self._update_ignore_list("@whatsappbot:beeper.local")
self.assert_ignored(self.user, set())

def test_caching(self) -> None:
Expand Down

0 comments on commit 431eed9

Please sign in to comment.