From 63a06140f4bd531b578a162e23b30e61331bfdf9 Mon Sep 17 00:00:00 2001 From: db0 Date: Mon, 26 Jun 2023 00:53:55 +0200 Subject: [PATCH] fix update_blacklist --- examples/update_blacklist.py | 21 +++++++++++++++++++-- fediseer/apis/models/v1.py | 4 ++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/examples/update_blacklist.py b/examples/update_blacklist.py index 69208ec..87ce780 100644 --- a/examples/update_blacklist.py +++ b/examples/update_blacklist.py @@ -8,6 +8,8 @@ USERNAME = "username" PASSWORD = "password" # If there's this many registered users per local post+comments, this site will be considered suspicious ACTIVITY_SUSPICION = 20 +# If there's this many registered users per active monthly user, this site will be considered suspicious +MONTHLY_ACTIVITY_SUSPICION = 500 # Extra domains you can block. You can just delete the contents if you want to only block suspicious domains blacklist = { "truthsocial.com", @@ -21,8 +23,23 @@ if lemmy.log_in(USERNAME, PASSWORD) is False: raise Exception("Could not log in to lemmy") print("Fetching suspicions") -sus = requests.get(f"https://fediseer.com/api/v1/instances?activity_suspicion={ACTIVITY_SUSPICION}&domains=true", timeout=5).json() +sus = requests.get(f"https://fediseer.com/api/v1/instances?activity_suspicion={ACTIVITY_SUSPICION}&active_suspicion={MONTHLY_ACTIVITY_SUSPICION}domains=true", timeout=5).json() defed = blacklist | set(sus["domains"]) +# I need to retrieve the site info because it seems if "RequireApplication" is set +# We need to always re-set the application_question. +# So we retrieve it from the existing site, to set the same value +site = lemmy.site.get() +application_question = None +if site["site_view"]["local_site"]["registration_mode"] == "RequireApplication": + application_question = site["site_view"]["local_site"]["application_question"] print("Editing Defederation list") -ret = lemmy.site.edit(blocked_instances=list(defed)) +if application_question: + ret = lemmy.site.edit( + blocked_instances=list(defed), + application_question=application_question, + ) +else: + ret = lemmy.site.edit( + blocked_instances=list(defed), + ) print("Edit Successful") \ No newline at end of file diff --git a/fediseer/apis/models/v1.py b/fediseer/apis/models/v1.py index 1fe369e..43b7c7f 100644 --- a/fediseer/apis/models/v1.py +++ b/fediseer/apis/models/v1.py @@ -16,8 +16,8 @@ class Models: 'total_users': fields.Integer(description="The total amount of users registered in that instance"), 'active_users_monthly': fields.Integer(description="The amount of active users monthly."), 'signup': fields.Boolean(default=False,description="True when subscriptions are open, else False"), - 'activity_suspicion': fields.Float(description="Local Comments+Posts per user. Higher is worse"), - 'active_users_suspicion': fields.Float(description="Monthly active users per user. Higher is worse"), + 'activity_suspicion': fields.Float(description="Local users per Comments+Posts. Higher is worse"), + 'active_users_suspicion': fields.Float(description="Local users per monthly active user. Higher is worse"), }) self.response_model_model_Suspicions_get = api.model('SuspiciousInstances', { 'instances': fields.List(fields.Nested(self.response_model_suspicious_instances)),