oops
This commit is contained in:
parent
e1abd7f2f2
commit
7a94bcd2bf
8
api.sh
Normal file
8
api.sh
Normal file
|
@ -0,0 +1,8 @@
|
|||
baseurl(){ echo "https://$INSTANCE/api/v3/"; } # This needs to be a function so updates to INSTANCE affect it. This is a very old bug lmao
|
||||
|
||||
#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\"})"; }
|
||||
# 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\"})"; }
|
15
clemmy.sh
Executable file
15
clemmy.sh
Executable file
|
@ -0,0 +1,15 @@
|
|||
#!/bin/sh
|
||||
|
||||
source ./api.sh
|
||||
source ./commands.sh
|
||||
source ./pretty.sh
|
||||
source ./creds.sh
|
||||
|
||||
while getopts "a:hv" o;do case "${o}" in
|
||||
a) INSTANCE=${insts[$OPTARG]}; TOKE=${tokes[$OPTARG]};;
|
||||
h) echo $actions; exit;;
|
||||
v) echo 0.1.0; exit;;
|
||||
esac done
|
||||
shift $((OPTIND-1))
|
||||
|
||||
$*
|
23
commands.sh
Normal file
23
commands.sh
Normal file
|
@ -0,0 +1,23 @@
|
|||
actions="notifs notifs2 comments freepost shitpost follow unfollow home deref whoami login"
|
||||
#Endpoints.
|
||||
#Lurkan
|
||||
notifs(){ getauth "user/replies" ".replies | reverse | $notifs"; }
|
||||
notifs2(){ getauth "user/mention" ".mentions | reverse | $notifs"; }
|
||||
following(){ echo "use <home> instead"; } # Maybe this will help.
|
||||
home(){ getauth "post/list" ".posts | $posts" "type_=Subscribed"; }
|
||||
comments(){ getauth "post" "(.post_view | $showpost), (.comments | reverse | $comments)" "id=$1"; }
|
||||
#Postan
|
||||
freepost(){ getbody; post "post" "{\"community_id\":$1,\"name\":\"${*:2}\",\"body\":\"$body\"}"; }
|
||||
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 | .[] | $postsummary" "type_=All&saved_only=true"; }
|
||||
#Community hoardan
|
||||
follow(){ post "community/follow" "{\"community_id\":$1,\"follow\":true}"; }
|
||||
unfollow(){ post "community/follow" "{\"community_id\":$1,\"follow\":false}"; }
|
||||
#Account hoardan
|
||||
whoami(){ echo $INSTANCE $TOKE; }
|
||||
login(){ post "user/login" "{\"username_or_email\":\"$1\",\"password\":\"$2\"}"; }
|
||||
#Misc
|
||||
deref(){ getauth "resolve_object" "" "q=$*"; }
|
20
creds.sh
Normal file
20
creds.sh
Normal file
|
@ -0,0 +1,20 @@
|
|||
if [ ! -f ~/.config/clemmy/accounts.csv ]; then
|
||||
touch ~/.config/clemmy/accounts.csv
|
||||
echo "Do you already have an account? y/n"
|
||||
read choice
|
||||
if [ $choice == n ]; then
|
||||
register
|
||||
else
|
||||
login
|
||||
fi
|
||||
exit
|
||||
fi
|
||||
|
||||
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]}
|
23
pretty.sh
Normal file
23
pretty.sh
Normal file
|
@ -0,0 +1,23 @@
|
|||
# Please don't abuse jq like this
|
||||
showpost='(.post | (.id | tostring)+" "+(.name | tostring)),
|
||||
(.post.url)+", "+(.creator.display_name // .creator.name)+":",
|
||||
((.comment // .post) | .published,
|
||||
(.body // .content)),
|
||||
""'
|
||||
postsummary='(.post | (.id | tostring)+" "+(.name | tostring)),
|
||||
(.post.url)+", "+(.creator.display_name // .creator.name)+":",
|
||||
((.comment // .post) | .published),
|
||||
""'
|
||||
showcomment='(.comment | (.parent_id | tostring)+"->"+(.id | tostring))+", "+(.creator.display_name // .creator.name)+":",
|
||||
((.comment // .post) | .published,
|
||||
(.body // .content)),
|
||||
""'
|
||||
#Split this out because I specifically do want to include post IDs in some places. Or rather, I only don't want to include them on the comments view.
|
||||
notif='(.comment | (.parent_id | tostring)+"->"+(.id | tostring))+" ("+(.post | (.id | tostring))+"), "+(.creator.display_name // .creator.name)+":",
|
||||
((.comment // .post) | .published,
|
||||
(.body // .content)),
|
||||
""'
|
||||
|
||||
comments=".[] | $showcomment"
|
||||
posts=".[] | $showpost"
|
||||
notifs=".[] | $notif"
|
Loading…
Reference in New Issue
Block a user