Compare commits
5 Commits
fc0e110a2c
...
39671dab91
Author | SHA1 | Date | |
---|---|---|---|
39671dab91 | |||
21a9042fcf | |||
c6a7ceb005 | |||
7a94bcd2bf | |||
e1abd7f2f2 |
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\"})"; }
|
17
clemmy.sh
Executable file
17
clemmy.sh
Executable file
@ -0,0 +1,17 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
source ./api.sh
|
||||||
|
source ./commands/commands.sh
|
||||||
|
source ./pretty.sh
|
||||||
|
source ./creds.sh
|
||||||
|
source ./utils.sh
|
||||||
|
|
||||||
|
while getopts "a:i:hv" o;do case "${o}" in
|
||||||
|
a) INSTANCE=${insts[$OPTARG]}; TOKE=${tokes[$OPTARG]};;
|
||||||
|
i) INSTANCE=$OPTARG;;
|
||||||
|
h) echo $actions; exit;;
|
||||||
|
v) echo 0.1.1; exit;;
|
||||||
|
esac done
|
||||||
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
$*
|
30
commands/accounts.sh
Normal file
30
commands/accounts.sh
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#Account hoardan
|
||||||
|
whoami(){ echo $INSTANCE $TOKE; }
|
||||||
|
login()
|
||||||
|
{
|
||||||
|
post "user/login" "{\"username_or_email\":\"$1\",\"password\":\"$2\"}"
|
||||||
|
}
|
||||||
|
register()
|
||||||
|
{
|
||||||
|
get "site" ".site_view.site | .open_registration,.require_email_verification,.require_application,.application_question" | jq -r . | read reg em app appq
|
||||||
|
if [ $reg == false ]; then
|
||||||
|
echo "Sorry, this instance does not accept registrations; try to contact them to ask for an account."; exit
|
||||||
|
fi
|
||||||
|
if [ $em == true ]; then em="(required)"; else em=""; fi
|
||||||
|
namedget reg_username "Desired username (required)"
|
||||||
|
namedget reg_pw "Password (required)"
|
||||||
|
namedget reg_pw2 "Verify password"
|
||||||
|
if [ ! reg_pw == reg_pw2 ]; then echo "passwords don't match (continuing anyway, expect failure later though)"; fi
|
||||||
|
namedget reg_email "Email address $em"
|
||||||
|
if [ $app == true ]; then namedget reg_appa "Application question: $appq"; fi
|
||||||
|
result="$(post "user/register" "{\"username\":\"$reg_username\",\"password\":\"$reg_pw\",\"password_verify\":\"$reg_pw2\",\"email\":\"$reg_email\",\"answer\":\"$reg_appa\"}")"
|
||||||
|
if [ ! $(jq .error <<< "result") == "captcha_incorrect" ]; then
|
||||||
|
jq <<< "result"; exit;
|
||||||
|
fi
|
||||||
|
a="$(get "user/get_captcha" ".ok")"
|
||||||
|
reg_uuid=$(jq -r '.uuid' <<< "$a")
|
||||||
|
jq -r '.wav' <<< "$a" | base64 -d > "captcha.wav"
|
||||||
|
jq -r '.png' <<< "$a" | base64 -d > "captcha.png"
|
||||||
|
namedget reg_captcha "Please open captcha.wav and captcha.png and input the text - in that order, no spaces"
|
||||||
|
post "user/register" "{\"username\":\"$reg_username\",\"password\":\"$reg_pw\",\"password_verify\":\"$reg_pw2\",\"email\":\"$reg_email\",\"answer\":\"$reg_appa\",\"captcha_uuid\":\"$reg_uuid\",\"captcha_answer\":\"$reg_captcha\"}"
|
||||||
|
}
|
8
commands/commands.sh
Normal file
8
commands/commands.sh
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
actions="notifs notifs2 comments freepost shitpost follow unfollow home deref whoami login"
|
||||||
|
#Endpoints in other files mostly.
|
||||||
|
source commands/accounts.sh
|
||||||
|
source commands/communities.sh
|
||||||
|
source commands/lurking.sh
|
||||||
|
source commands/posts.sh
|
||||||
|
#Misc
|
||||||
|
deref(){ getauth "resolve_object" "" "q=$*"; }
|
4
commands/communities.sh
Normal file
4
commands/communities.sh
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
#Community hoardan
|
||||||
|
follow(){ post "community/follow" "{\"community_id\":$1,\"follow\":true}"; }
|
||||||
|
unfollow(){ post "community/follow" "{\"community_id\":$1,\"follow\":false}"; }
|
||||||
|
following(){ echo "use <home> instead"; } # Maybe this will help.
|
5
commands/lurking.sh
Normal file
5
commands/lurking.sh
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
#Lurkan
|
||||||
|
notifs(){ getauth "user/replies" ".replies | reverse | $notifs"; }
|
||||||
|
notifs2(){ getauth "user/mention" ".mentions | reverse | $notifs"; }
|
||||||
|
home(){ getauth "post/list" ".posts | $posts" "type_=Subscribed"; }
|
||||||
|
comments(){ getauth "post" "(.post_view | $showpost), (.comments | reverse | $comments)" "id=$1"; }
|
7
commands/posts.sh
Normal file
7
commands/posts.sh
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#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"; }
|
||||||
|
#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\"}"; }
|
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"
|
@ -1,78 +0,0 @@
|
|||||||
#!/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
|
|
||||||
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"
|
|
||||||
|
|
||||||
#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\"})"; }
|
|
||||||
|
|
||||||
#Utils
|
|
||||||
getbody(){ a=$(cat); while read n; do b="$b\n$n"; done <<< "$a"; c=${b//\"/\\\"}; body="${c:2}"; }
|
|
||||||
|
|
||||||
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=$*"; }
|
|
||||||
|
|
||||||
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
utils.sh
Normal file
23
utils.sh
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
#Utils
|
||||||
|
|
||||||
|
getbody()
|
||||||
|
{
|
||||||
|
echo "Write your comment, press ctrl+d on a blank line to submit"
|
||||||
|
a=$(cat)
|
||||||
|
while read n; do
|
||||||
|
b="$b\n$n"
|
||||||
|
done <<< "$a"
|
||||||
|
c=${b//\"/\\\"}
|
||||||
|
body="${c:2}"
|
||||||
|
}
|
||||||
|
|
||||||
|
namedget()
|
||||||
|
{
|
||||||
|
echo $2:
|
||||||
|
if [ $3 ]; then
|
||||||
|
echo "(Press ctrl+d on a blank line to submit)"
|
||||||
|
read $1 <<< $(cat)
|
||||||
|
else
|
||||||
|
read $1
|
||||||
|
fi
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user