Merge pull request #36 from Linus2punkt0/mastodon-visibility-setting

Added visibility setting for mastodon posts
This commit is contained in:
Linus Svensson
2023-10-08 22:38:26 +02:00
committed by GitHub
2 changed files with 14 additions and 4 deletions

View File

@@ -332,17 +332,24 @@ def toot(post, replyTo, images, doPost):
writeLog("Uploading image " + filename)
res = mastodon.media_post(filename)
mediaIds.append(res.id)
# Visibility is set to whatever is set in the settings file. If that is hybrid, it sets the visibility either to public or unlisted depending on
# if it is a reply in a thread or not.
visibility = settings.mastodonVisibility
if visibility == "hybrid" and replyTo:
visibility = "unlisted"
elif visibility == "hybrid":
visibility = "public"
# I wanted to make this part a little neater, but didn't get it to work and gave up. So here we are.
# If post is both reply and has images it is posted as both a reply and with images (duh).
# If just either of the two it is posted with just that, and if neither it is just posted as a text post.
if replyTo and mediaIds:
a = mastodon.status_post(post, in_reply_to_id=replyTo, media_ids=mediaIds)
a = mastodon.status_post(post, in_reply_to_id=replyTo, media_ids=mediaIds, visibility=visibility)
elif replyTo:
a = mastodon.status_post(post, in_reply_to_id=replyTo, visibility="unlisted")
a = mastodon.status_post(post, in_reply_to_id=replyTo, visibility=visibility)
elif mediaIds:
a = mastodon.status_post(post, media_ids=mediaIds, visibility="unlisted")
a = mastodon.status_post(post, media_ids=mediaIds, visibility=visibility)
else:
a = mastodon.status_post(post, visibility="unlisted")
a = mastodon.status_post(post, visibility=visibility)
writeLog("Posted to mastodon")
id = a["id"]
return id

View File

@@ -28,6 +28,9 @@ maxRetries = 5
# Sets max time limit (in hours) for fetching posts. If no database exists, all posts within this time
# period will be posted.
postTimeLimit = 12
# mastodonVisibility sets what visibility should be used when posting to Mastodon. Options are "public" for always public, "unlisted" for always unlisted,
# "private" for always private and "hybrid" for all posts public except responses in threads (meaning first post in a thread is public and the rest unlisted).
mastodonVisibility = "hybrid"
# Override settings with environment variables if they exist
Twitter = os.environ.get('TWITTER_CROSSPOSTING').lower() == 'true' if os.environ.get('TWITTER_CROSSPOSTING') else Twitter