From 22348bee3734e1af106d8ffe905e5e613b3d62d6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 13 Aug 2024 23:22:01 +0200 Subject: [PATCH] Continued: - script is rejecting "reject" now in favor of "rejected" as there is "suspended" and "silenced" (past) already around - Please run `$ sqlite3 blocks.db "UPDATE blocks SET block_level = 'rejected' WHERE block_level = 'reject';"` --- fba/commands.py | 22 +++++++++++----------- fba/helpers/processing.py | 2 +- fba/models/blocks.py | 10 +++++----- fba/networks/friendica.py | 2 +- fba/networks/lemmy.py | 4 ++-- fba/networks/mastodon.py | 2 +- fba/networks/misskey.py | 2 +- fba/networks/pleroma.py | 7 ++++--- 8 files changed, 26 insertions(+), 25 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 153f45d..7c96e6e 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -461,7 +461,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: block["block_level"] = blocks.alias_block_level(block["block_level"]) logger.debug("block[block_level]='%s' - AFTER!", block["block_level"]) - if processing.block(blocker, block["blocked"], block["reason"], block["block_level"]) and block["block_level"] in ["reject", "suspend"] and config.get("bot_enabled"): + if processing.block(blocker, block["blocked"], block["reason"], block["block_level"]) and block["block_level"] in ["rejected", "suspended"] and config.get("bot_enabled"): logger.debug("Appending block[blocked]'%s',reason='%s' for blocker='%s' ...", block["blocked"], block["block_level"], blocker) blockdict.append({ "blocked": block["blocked"], @@ -631,7 +631,7 @@ def fetch_todon_wiki(args: argparse.Namespace) -> int: blocklist = { "silenced": list(), - "reject": list(), + "rejected": list(), } logger.debug("Fetching domainblocks from source_domain='%s'", source_domain) @@ -651,9 +651,9 @@ def fetch_todon_wiki(args: argparse.Namespace) -> int: suspended = doc.find("h3", {"id": "suspended_servers"}).find_next("ul").findAll("li") logger.info("Checking %d suspended entries ...", len(suspended)) - blocklist["reject"] = utils.find_domains(suspended, "div") + blocklist["rejected"] = utils.find_domains(suspended, "div") - blocking = blocklist["silenced"] + blocklist["reject"] + blocking = blocklist["silenced"] + blocklist["rejected"] blocker = "todon.eu" logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", blocker, len(blocking)) @@ -687,7 +687,7 @@ def fetch_todon_wiki(args: argparse.Namespace) -> int: logger.info("Adding new block: blocked='%s',block_level='%s'", blocked, block_level) - if processing.block(blocker, blocked, None, block_level) and block_level == "reject" and config.get("bot_enabled"): + if processing.block(blocker, blocked, None, block_level) and block_level in ["suspended", "rejected"] and config.get("bot_enabled"): logger.debug("Appending blocked='%s',reason='%s' for blocker='%s' ...", blocked, block_level, blocker) blockdict.append({ "blocked": blocked, @@ -738,7 +738,7 @@ def fetch_cs(args: argparse.Namespace): blocklist = { "silenced": list(), - "reject" : list(), + "rejected": list(), } source_domain = "raw.githubusercontent.com" @@ -766,16 +766,16 @@ def fetch_cs(args: argparse.Namespace): blocked = doc.find("h2", {"id": "blocked-instances"}).findNext("table").find("tbody") logger.debug("blocked[%s]()=%d", type(blocked), len(blocked)) - blocklist["reject"] = federation.find_domains(blocked) + blocklist["rejected"] = federation.find_domains(blocked) - blocking = blocklist["silenced"] + blocklist["reject"] + blocking = blocklist["silenced"] + blocklist["rejected"] blocker = "chaos.social" logger.debug("Invoking instances.set_total_blocks(%s, %d) ...", blocker, len(blocking)) instances.set_last_blocked(blocker) instances.set_total_blocks(blocker, blocking) - logger.debug("blocklist[silenced]()=%d,blocklist[reject]()=%d", len(blocklist["silenced"]), len(blocklist["reject"])) + logger.debug("blocklist[silenced]()=%d,blocklist[reject]()=%d", len(blocklist["silenced"]), len(blocklist["rejected"])) if len(blocking) > 0: blockdict = list() for block_level in blocklist: @@ -794,7 +794,7 @@ def fetch_cs(args: argparse.Namespace): logger.warning("Exception '%s' during fetching instances (fetch_cs) from row[domain]='%s'", type(exception), row["domain"]) instances.set_last_error(row["domain"], exception) - if processing.block(blocker, row["domain"], row["reason"], block_level) and block_level == "reject" and config.get("bot_enabled"): + if processing.block(blocker, row["domain"], row["reason"], block_level) and block_level in ["suspended", "rejected"] and config.get("bot_enabled"): logger.debug("Appending blocked='%s',reason='%s' for blocker='%s' ...", row["domain"], block_level, blocker) blockdict.append({ "blocked": row["domain"], @@ -1456,7 +1456,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: block["block_level"] = blocks.alias_block_level(block["block_level"]) logger.info("blocked='%s' has been deobfuscated to blocked='%s', adding ...", block["blocked"], blocked) - if processing.block(row["domain"], blocked, block["reason"], block["block_level"]) and block["block_level"] == "reject" and config.get("bot_enabled"): + if processing.block(row["domain"], blocked, block["reason"], block["block_level"]) and block["block_level"] in ["suspended", "rejected"] and config.get("bot_enabled"): logger.debug("Appending blocked='%s',reason='%s' for blocker='%s' ...", block["blocked"], block["block_level"], row["domain"]) blockdict.append({ "blocked": blocked, diff --git a/fba/helpers/processing.py b/fba/helpers/processing.py index 8fd5d81..04954d2 100644 --- a/fba/helpers/processing.py +++ b/fba/helpers/processing.py @@ -180,7 +180,7 @@ def csv_block(blocker: str, url: str, command: str): severity = blocks.alias_block_level(row["severity"]) else: logger.debug("row='%s' does not contain severity column, setting 'reject'", row) - severity = "reject" + severity = "rejected" if "reason" in row: reason = tidyup.reason(row["reason"]) if row["reason"] not in [None, ""] else None diff --git a/fba/models/blocks.py b/fba/models/blocks.py index 0c4f32c..c27bad3 100644 --- a/fba/models/blocks.py +++ b/fba/models/blocks.py @@ -36,7 +36,7 @@ def get_reason(blocker: str, blocked: str, block_level: str): raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]: + elif block_level in ["accept", "reject", "suspend", "silence", "nsfw", "quarantined_instances"]: raise ValueError(f"block_level='{block_level}' is not wanted.") elif blacklist.is_blacklisted(blocker): raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") @@ -71,7 +71,7 @@ def update_reason(reason: str, blocker: str, blocked: str, block_level: str): raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]: + elif block_level in ["accept", "reject", "suspend", "silence", "nsfw", "quarantined_instances"]: raise ValueError(f"block_level='{block_level}' is not wanted.") elif blacklist.is_blacklisted(blocker): raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") @@ -102,7 +102,7 @@ def update_last_seen(blocker: str, blocked: str, block_level: str): raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]: + elif block_level in ["accept", "reject", "suspend", "silence", "nsfw", "quarantined_instances"]: raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'") elif blacklist.is_blacklisted(blocker): raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") @@ -131,7 +131,7 @@ def is_instance_blocked(blocker: str, blocked: str, block_level: str = None) -> raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]: + elif block_level in ["accept", "reject", "suspend", "silence", "nsfw", "quarantined_instances"]: raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'") elif blacklist.is_blacklisted(blocker): raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") @@ -170,7 +170,7 @@ def add(blocker: str, blocked: str, reason: str, block_level: str): raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'") elif block_level == "": raise ValueError("Parameter 'block_level' is empty") - elif block_level in ["accept", "suspend", "silence", "nsfw", "quarantined_instances"]: + elif block_level in ["accept", "reject", "suspend", "silence", "nsfw", "quarantined_instances"]: raise ValueError(f"blocked='{blocked}' has unwanted block_level='{block_level}'") elif blacklist.is_blacklisted(blocker): raise Exception(f"blocker='{blocker}' is blacklisted but function invoked") diff --git a/fba/networks/friendica.py b/fba/networks/friendica.py index 05efa9a..47a2475 100644 --- a/fba/networks/friendica.py +++ b/fba/networks/friendica.py @@ -104,7 +104,7 @@ def fetch_blocks(domain: str) -> list: "blocker" : domain, "blocked" : blocked, "reason" : reason, - "block_level": "reject", + "block_level": "rejected", }) logger.debug("blocklist()=%d - EXIT!", len(blocklist)) diff --git a/fba/networks/lemmy.py b/fba/networks/lemmy.py index 8a9712d..d16bf6c 100644 --- a/fba/networks/lemmy.py +++ b/fba/networks/lemmy.py @@ -201,7 +201,7 @@ def fetch_blocks(domain: str) -> list: "blocker" : domain, "blocked" : blocked, "reason" : None, - "block_level": "reject", + "block_level": "rejected", }) logger.debug("blocklist()=%d - EXIT!", len(blocklist)) @@ -226,7 +226,7 @@ def fetch_blocks(domain: str) -> list: "blocker" : domain, "blocked" : blocked, "reason" : None, - "block_level": "reject", + "block_level": "rejected", }) else: logger.warning("Cannot fetch /instances due to error: response.ok='%s',response.status_code=%d,response.details='%s'", response.ok, response.status_code, response.reason) diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index b379ae0..4f2af7b 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -152,7 +152,7 @@ def fetch_blocks_from_about(domain: str) -> dict: logger.debug("Returning blocklist for domain='%s' - EXIT!", domain) return { - "reject" : blocklist["Suspended servers"], + "rejected" : blocklist["Suspended servers"], "media_removal" : blocklist["Filtered media"], "followers_only": blocklist["Limited servers"] + blocklist["Silenced servers"], } diff --git a/fba/networks/misskey.py b/fba/networks/misskey.py index e7c7053..5d71e58 100644 --- a/fba/networks/misskey.py +++ b/fba/networks/misskey.py @@ -313,7 +313,7 @@ def fetch_blocks(domain: str) -> list: "blocker" : domain, "blocked" : blocked, "reason" : None, - "block_level": "reject", + "block_level": "rejected", }) logger.debug("count=%d", count) diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 87c1049..27956b3 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -46,8 +46,8 @@ language_mapping = { "media_removal" : "media_removal", "media force-set as sensitive": "media_nsfw", "nsfw" : "media_nsfw", - "reject" : "reject", - "suspended servers": "reject", + "reject" : "rejected", + "suspended servers": "suspended", "silenced servers" : "silenced", "removal from \"the whole known network\" timeline": "federated_timeline_removal", } @@ -328,7 +328,8 @@ def fetch_blocks_from_about(domain: str) -> dict: break blocklist = { - "reject" : [], + "rejected" : [], + "suspended" : [], "filtered_media": [], "followers_only": [], "silenced" : [], -- 2.39.5