Apply blocked nicknames to announces

main
Bob Mottram 2023-04-30 10:52:29 +01:00
parent a5ac68e698
commit 579a9e88dd
1 changed files with 22 additions and 7 deletions

View File

@ -726,7 +726,11 @@ def allowed_announce(base_dir: str, nickname: str, domain: str,
# cached announce blocks # cached announce blocks
if announce_blocked_cache: if announce_blocked_cache:
for blocked_str in announce_blocked_cache: for blocked_str in announce_blocked_cache:
if '*@' + domain in blocked_str: if block_nickname:
if block_nickname + '@*' in blocked_str:
return False
if block_domain:
if '*@' + block_domain in blocked_str:
return False return False
if block_handle: if block_handle:
if blocked_str == block_handle: if blocked_str == block_handle:
@ -736,6 +740,11 @@ def allowed_announce(base_dir: str, nickname: str, domain: str,
global_announce_blocks_filename = \ global_announce_blocks_filename = \
base_dir + '/accounts/noannounce.txt' base_dir + '/accounts/noannounce.txt'
if os.path.isfile(global_announce_blocks_filename): if os.path.isfile(global_announce_blocks_filename):
if block_nickname:
if text_in_file(block_nickname + '@*',
global_announce_blocks_filename, False):
return False
if block_domain:
if text_in_file('*@' + block_domain, if text_in_file('*@' + block_domain,
global_announce_blocks_filename, False): global_announce_blocks_filename, False):
return False return False
@ -749,7 +758,13 @@ def allowed_announce(base_dir: str, nickname: str, domain: str,
account_dir = acct_dir(base_dir, nickname, domain) account_dir = acct_dir(base_dir, nickname, domain)
blocking_filename = account_dir + '/noannounce.txt' blocking_filename = account_dir + '/noannounce.txt'
if os.path.isfile(blocking_filename): if os.path.isfile(blocking_filename):
if text_in_file('*@' + block_domain + '\n', blocking_filename, False): if block_nickname:
if text_in_file(block_nickname + '@*\n',
blocking_filename, False):
return False
if block_domain:
if text_in_file('*@' + block_domain + '\n',
blocking_filename, False):
return False return False
if block_handle: if block_handle:
if text_in_file(block_handle + '\n', blocking_filename, False): if text_in_file(block_handle + '\n', blocking_filename, False):