2023-06-21 00:07:49 +00:00
|
|
|
import requests
|
|
|
|
|
|
|
|
from pythorhead import Lemmy
|
2023-08-09 14:20:10 +00:00
|
|
|
from pythonseer import Fediseer
|
|
|
|
from pythonseer.types import FormatType
|
2023-06-21 00:07:49 +00:00
|
|
|
|
|
|
|
# Your own instance's domain
|
|
|
|
LEMMY_DOMAIN = "lemmy.dbzer0.com"
|
|
|
|
USERNAME = "username"
|
|
|
|
PASSWORD = "password"
|
|
|
|
# If there's this many registered users per local post+comments, this site will be considered suspicious
|
|
|
|
ACTIVITY_SUSPICION = 20
|
2023-06-25 22:53:55 +00:00
|
|
|
# If there's this many registered users per active monthly user, this site will be considered suspicious
|
|
|
|
MONTHLY_ACTIVITY_SUSPICION = 500
|
2023-06-21 00:07:49 +00:00
|
|
|
# Extra domains you can block. You can just delete the contents if you want to only block suspicious domains
|
|
|
|
blacklist = {
|
|
|
|
"truthsocial.com",
|
2023-08-09 14:20:10 +00:00
|
|
|
"threads.net",
|
2023-06-21 00:07:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
lemmy = Lemmy(f"https://{LEMMY_DOMAIN}")
|
|
|
|
if lemmy.log_in(USERNAME, PASSWORD) is False:
|
|
|
|
raise Exception("Could not log in to lemmy")
|
|
|
|
|
2023-08-09 14:20:10 +00:00
|
|
|
fediseer = Fediseer()
|
2023-06-21 00:07:49 +00:00
|
|
|
print("Fetching suspicions")
|
2023-08-09 14:20:10 +00:00
|
|
|
sus = fediseer.suspicions.get(
|
|
|
|
activity_suspicion=ACTIVITY_SUSPICION,
|
|
|
|
active_suspicion=MONTHLY_ACTIVITY_SUSPICION,
|
|
|
|
format=FormatType.LIST
|
|
|
|
)
|
|
|
|
print("Fetching censures")
|
|
|
|
censures = fediseer.censure.get_given(LEMMY_DOMAIN, FormatType.LIST)
|
|
|
|
defed = blacklist | set(censures["domains"]) | set(sus["domains"])
|
2023-06-25 22:53:55 +00:00
|
|
|
# I need to retrieve the site info because it seems if "RequireApplication" is set
|
2023-08-09 14:20:10 +00:00
|
|
|
# We need to always re-set the application_question.
|
2023-06-25 22:53:55 +00:00
|
|
|
# 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"]
|
2023-06-21 00:07:49 +00:00
|
|
|
print("Editing Defederation list")
|
2023-06-25 22:53:55 +00:00
|
|
|
if application_question:
|
|
|
|
ret = lemmy.site.edit(
|
|
|
|
blocked_instances=list(defed),
|
|
|
|
application_question=application_question,
|
|
|
|
)
|
|
|
|
else:
|
|
|
|
ret = lemmy.site.edit(
|
|
|
|
blocked_instances=list(defed),
|
|
|
|
)
|
2023-08-09 14:20:10 +00:00
|
|
|
print("Edit Successful")
|