2022-08-27 15:46:03 +10:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
accs=$(cat ~/.config/clemmy/accounts.csv)
|
|
|
|
i=0
|
|
|
|
for line in ${accs[*]}; do
|
|
|
|
IFS=, read insts[$i] tokes[$i] <<< $line
|
|
|
|
i=$((i+1))
|
|
|
|
done
|
|
|
|
INSTANCE=${insts[0]}
|
|
|
|
TOKE=${tokes[0]}
|
|
|
|
|
|
|
|
baseurl="https://$INSTANCE/api/v3/"
|
|
|
|
# Please don't abuse jq like this
|
|
|
|
showcomment='(.post | (.id | tostring)+" "+(.name | tostring)),
|
2022-08-27 16:10:11 +10:00
|
|
|
(.post.url // (.comment | (.parent_id | tostring)+"->"+(.id | tostring)))+", "+(.creator.display_name // .creator.name)+":",
|
2022-08-27 15:46:03 +10:00
|
|
|
((.comment // .post) | .published,
|
|
|
|
(.body // .content)),
|
|
|
|
""'
|
|
|
|
|
|
|
|
comments=".[] | $showcomment"
|
|
|
|
|
|
|
|
#Generics
|
|
|
|
get(){ curl -s "$baseurl$1?${*:3}" | jq "$2"; }
|
|
|
|
getauth(){ get "$1" "$2" "auth=$TOKE&${*:3}"; }
|
|
|
|
post(){ curl -s "$baseurl$1" --json "$(echo ${*:2} | jq .+{\"auth\":\"$TOKE\"})"; }
|
2022-08-29 19:30:57 +10:00
|
|
|
# I'm just gonna clone this thing rather than try to palm the -X PUT into post. I can fix it later.
|
|
|
|
put(){ curl -sX PUT "$baseurl$1" --json "$(echo ${*:2} | jq .+{\"auth\":\"$TOKE\"})"; }
|
2022-08-27 15:46:03 +10:00
|
|
|
|
|
|
|
#Utils
|
|
|
|
getbody(){ a=$(cat); body=${a//\"/\\\"}; }
|
|
|
|
|
|
|
|
actions="notifs notifs2 comments freepost shitpost follow unfollow following deref whoami login"
|
|
|
|
#Endpoints.
|
2022-08-29 19:30:57 +10:00
|
|
|
#Lurkan
|
2022-08-27 15:46:03 +10:00
|
|
|
notifs(){ getauth "user/replies" ".replies | $comments"; }
|
|
|
|
notifs2(){ getauth "user/mention"; }
|
2022-08-29 19:30:57 +10:00
|
|
|
following(){ getauth "post/list" ".posts | $comments" "type_=Subscribed"; }
|
2022-08-27 15:46:03 +10:00
|
|
|
comments(){ getauth "post" "(.post_view | $showcomment), (.comments | reverse | $comments)" "id=$1"; }
|
2022-08-29 19:30:57 +10:00
|
|
|
#Postan
|
2022-08-27 15:46:03 +10:00
|
|
|
freepost(){ getbody; post "post" "{\"community_id\":$1,\"name\":\"$2\",\"body\":\"$body\"}"; }
|
2022-08-29 19:30:57 +10:00
|
|
|
shitpost(){ getbody; postid=$1; parentid=$2; post "comment" "{\"post_id\":$postid,\"parent_id\":$parentid,\"content\":\"$body\"}"; }
|
|
|
|
#Post hoardan
|
|
|
|
save(){ put "post/save" "{\"post_id\":$1,\"save\":true}"; }
|
|
|
|
unsave(){ put "post/save" "{\"post_id\":$1,\"save\":false}"; }
|
|
|
|
load(){ getauth "post/list" ".posts | $comments" "type_=All&saved_only=true"; }
|
|
|
|
#Community hoardan
|
2022-08-27 15:46:03 +10:00
|
|
|
follow(){ post "community/follow" "{\"community_id\":$1,\"follow\":true}"; }
|
|
|
|
unfollow(){ post "community/follow" "{\"community_id\":$1,\"follow\":false}"; }
|
2022-08-29 19:30:57 +10:00
|
|
|
#Account hoardan
|
2022-08-27 15:46:03 +10:00
|
|
|
whoami(){ echo $INSTANCE $TOKE; }
|
|
|
|
login(){ post "user/login" "{\"username_or_email\":\"$1\",\"password\":\"$2\"}"; }
|
2022-08-29 19:30:57 +10:00
|
|
|
#Misc
|
|
|
|
deref(){ getauth "resolve_object" "" "q=$*"; }
|
2022-08-27 15:46:03 +10:00
|
|
|
|
|
|
|
while getopts "a:h" o;do case "${o}" in
|
|
|
|
a) INSTANCE=${insts[$OPTARG]}; TOKE=${tokes[$OPTARG]};;
|
|
|
|
h) echo $actions; exit;;
|
|
|
|
esac done
|
|
|
|
shift $((OPTIND-1))
|
|
|
|
|
2022-08-29 19:30:57 +10:00
|
|
|
$*
|