Implement protecting toots by tag

This commit is contained in:
Gabriel Augendre 2020-05-23 09:42:13 +02:00
parent 14cc23f8dc
commit 6ea44f6ed3
4 changed files with 26 additions and 8 deletions

View file

@ -60,6 +60,14 @@ protected_toots = 103362008817616000
103361883565013391
103363106195441418
# Tags you want to protect (never delete).
# Tags are matched case insensitively and are only matched for original toots (not for boosts):
# if you boost a toot containing #ScreenshotSunday it won't be protected by this rule.
# You MUST omit the `#` part of the tag.
protected_tags = 100DaysToOffload
screenshotsunday
# Another account
[Mastodon.social]
api_base_url = https://mastodon.social

View file

@ -124,7 +124,7 @@ def _format_toot(toot: dict, protection_reason: str = ""):
else:
message = f"original toot {toot['url']}"
if protection_reason:
message = f"{message} protected because of {protection_reason}"
message = f"{message} protected because {protection_reason}"
return message
@ -152,16 +152,25 @@ def _toot_protection_reason(toot: dict, section) -> Optional[str]:
original_id = toot["reblog"].get("id")
created_at = toot["created_at"]
protected_toots = map(int, section.get("protected_toots", "").split())
protected_tags = section.get("protected_tags", "").lower().split()
time_limit = pendulum.now(tz=section.get("timezone")).subtract(
days=section.getint("days_count")
)
if boost_count >= section.getint("boost_limit"):
return "boost count"
if favorite_count >= section.getint("favorite_limit"):
return "favorite count"
boost_limit = section.getint("boost_limit")
if boost_count >= boost_limit:
return "boost count is over limit {} >= {}".format(boost_count, boost_limit)
favorite_limit = section.getint("favorite_limit")
if favorite_count >= favorite_limit:
return "favorite count is over limit {} >= {}".format(
favorite_count, favorite_limit
)
if id_ in protected_toots or original_id in protected_toots:
return "protected id"
return "{} or {} is a protected id".format(id_, original_id)
if created_at >= time_limit:
return "creation time"
return "creation time {} is later than limit {}".format(created_at, time_limit)
for tag in toot.get("tags", []):
tag_name = tag.get("name").lower()
if tag_name and tag_name in protected_tags:
return "{} is a protected tag".format(tag_name)
return None

View file

@ -47,6 +47,7 @@ def _get_default_config():
"app_secret_file": "mastodon_social_app.secret",
"user_secret_file": "mastodon_social_user.secret",
"protected_toots": "1234\n5678",
"protected_tags": "TagToProtect",
}
return default_config

View file

@ -1,6 +1,6 @@
[tool.poetry]
name = "cleantoots"
version = "0.3.6"
version = "0.4.0"
description = "Cleanup your toot history."
license = "GPL-3.0-or-later"
authors = ["Gabriel Augendre <gabriel@augendre.info>"]