Add option for setting posts’ scope

This commit is contained in:
Jaidyn Ann 2024-04-10 22:08:09 -05:00
parent 3048c4ad68
commit 3b130b7a28

View File

@ -17,6 +17,7 @@ usage() {
echo
echo ' -h print this message and exit'
echo ' -H file used to store/check quoted posts; to avoid duplicates'
echo ' -s scope for posts, one of: public/[unlisted]/private/direct'
echo
echo 'Posts tagged under HASHTAG will all be quote-posted to the'
echo 'Mastodon-compatible server at SERVER_URL.'
@ -92,7 +93,7 @@ quote_posts() {
# post_json $tagged_post-json
post_json() {
local tagged_post_json="$1"
printf '{ "content_type": "text/html", "visibility": "unlisted",'
printf '{ "content_type": "text/html", "visibility": "%s",' "$FEDI_SCOPE"
printf '"quote_id": "%s",' "$(echo "$tagged_post_json" | jq -r .id)"
printf '"expires_in": %s,' 864000
printf '"status": "%s" }\n' "$(post_body "$tagged_post_json")"
@ -176,7 +177,10 @@ env_subst() {
}
while getopts 'hH:' arg; do
FEDI_SCOPE="unlisted" # Default value.
while getopts 'hH:s:' arg; do
case $arg in
h)
usage
@ -185,9 +189,26 @@ while getopts 'hH:' arg; do
H)
HISTORY_FILE="$OPTARG"
;;
s)
OPTARG="$(echo "$OPTARG" | tr 'A-Z' 'a-z')"
if test "$OPTARG" = "unlisted" -o "$OPTARG" = "public" \
-o "$OPTARG" = "private" -o "$OPTARG" = "direct"; then
FEDI_SCOPE="$OPTARG"
else
1>&2 echo '$OPTARG is an invalid scope; must be one of:'
1>&2 echo ' • unlisted'
1>&2 echo ' • public'
1>&2 echo ' • private'
1>&2 echo ' • direct'
1>&2 echo
1>&2 echo 'Run with -h for more information.'
exit 6
fi
;;
esac
done
shift $((OPTIND-1))
HASHTAG="$1"
FEDI_SERVER="$2"