Compare commits
23 Commits
39671dab91
...
master
Author | SHA1 | Date | |
---|---|---|---|
8cd519fe75 | |||
b1cb700ef7 | |||
ba29b1491d | |||
b3185b2d25 | |||
261f125761 | |||
e9ed7b3e11 | |||
07950c0be7 | |||
840ec2723b | |||
c0ab52f1c3 | |||
eb656567cf | |||
92fb247756 | |||
b31c474ff0 | |||
bcd456e55b | |||
ebd79fc601 | |||
555ef1db3a | |||
0629575417 | |||
f7c329af97 | |||
64672de712 | |||
aec63608a5 | |||
3831900f53 | |||
890087df08 | |||
b7159cecef | |||
8488962826 |
23
PKGBUILD
23
PKGBUILD
@@ -1,18 +1,23 @@
|
|||||||
# Maintainer: Zergling_man, from fedora.email
|
# Maintainer: Zergling_man, from fedora.email
|
||||||
|
#Well, it seems to work now.
|
||||||
|
|
||||||
pkgname=clemmy
|
pkgname=clemmy
|
||||||
pkgver=0.1.0
|
pkgver=0.2.0
|
||||||
pkgrel=1
|
pkgrel=2
|
||||||
pkgdesc='A pure bash client for lemmy, with multiaccount support.'
|
pkgdesc='A pure bash client for lemmy, with multiaccount support.'
|
||||||
arch=('any')
|
arch=('any')
|
||||||
url='https://gitea.rakka.tk/Zergling_man/clemmy'
|
url='http://precious.harpy.faith/Zergling_man/clemmy'
|
||||||
license=('GPL' 'custom:plusnigger.autism.exposed')
|
license=('GPL' 'custom:plusnigger.autism.exposed')
|
||||||
depends=('curl' 'jq')
|
depends=('curl' 'jq')
|
||||||
source=('https://gitea.rakka.tk/Zergling_man/clemmy/raw/branch/master/shitty_api.sh')
|
makedepends=('git')
|
||||||
sha256sums=('f3a3c9453158ca713b5a5fb21e0510a681a143ae74fc105364901248ad2f86b9')
|
source=('git+http://precious.harpy.faith/Zergling_man/clemmy.git')
|
||||||
|
sha256sums=('SKIP') #Don't know how to use this on a repo.
|
||||||
|
|
||||||
package() {
|
package() {
|
||||||
install -d ${pkgdir}/usr/bin
|
cd ${pkgname}
|
||||||
cp ${srcdir}/shitty_api.sh ${pkgdir}/usr/bin/shitty_api
|
install -d ${pkgdir}/usr/bin ${pkgdir}/opt/clemmy
|
||||||
chmod +x ${pkgdir}/usr/bin/shitty_api
|
rm -rf README.txt .git
|
||||||
}
|
cp -r . ${pkgdir}/opt/clemmy
|
||||||
|
ln -s /opt/clemmy/clemmy.sh ${pkgdir}/usr/bin/clemmy
|
||||||
|
chmod +x ${pkgdir}/opt/clemmy/clemmy.sh
|
||||||
|
}
|
||||||
|
@@ -1 +1,2 @@
|
|||||||
A bash client for lemmy. Lots TODO, user guide will be in the program itself.
|
A bash client for lemmy. Lots TODO, user guide will be in the program itself.
|
||||||
|
Entry point is clemmy.sh, -h is not very useful yet (but it's better than nothing).
|
9
api.sh
9
api.sh
@@ -1,8 +1,7 @@
|
|||||||
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
|
baseurl(){ if [ -z $INSEC ]; then sec=s; fi; echo "http$sec://$INSTANCE/api/v3/"; } # This needs to be a function so updates to INSTANCE affect it. This is a very old bug lmao
|
||||||
|
|
||||||
#Generics
|
#Generics
|
||||||
get(){ curl -s "$(baseurl)$1?${*:3}" | jq "$2"; }
|
get(){ curl -sH "Cookie:jwt=$TOKE" "$(baseurl)$1?${*:3}" | jq "${2:-.}"; }
|
||||||
getauth(){ get "$1" "$2" "auth=$TOKE&${*:3}"; }
|
post(){ curl -sH "Cookie:jwt=$TOKE" "$(baseurl)$1" --json "${*:2}"; }
|
||||||
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.
|
# 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\"})"; }
|
put(){ curl -sX PUT "$(baseurl)$1" --json "$(echo ${*:2} | jq '.+{"auth":"'$TOKE'"}')"; }
|
18
clemmy.sh
18
clemmy.sh
@@ -1,16 +1,18 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
|
|
||||||
source ./api.sh
|
imps=$(dirname $(realpath $0))
|
||||||
source ./commands/commands.sh
|
|
||||||
source ./pretty.sh
|
|
||||||
source ./creds.sh
|
|
||||||
source ./utils.sh
|
|
||||||
|
|
||||||
while getopts "a:i:hv" o;do case "${o}" in
|
source $imps/api.sh
|
||||||
a) INSTANCE=${insts[$OPTARG]}; TOKE=${tokes[$OPTARG]};;
|
source $imps/commands/commands.sh
|
||||||
|
source $imps/pretty.sh
|
||||||
|
source $imps/creds.sh
|
||||||
|
source $imps/utils.sh
|
||||||
|
|
||||||
|
while getopts "a:hi:v" o;do case "${o}" in
|
||||||
|
a) select_account $OPTARG;;
|
||||||
i) INSTANCE=$OPTARG;;
|
i) INSTANCE=$OPTARG;;
|
||||||
h) echo $actions; exit;;
|
h) echo $actions; exit;;
|
||||||
v) echo 0.1.1; exit;;
|
v) echo 0.1.7; exit;;
|
||||||
esac done
|
esac done
|
||||||
shift $((OPTIND-1))
|
shift $((OPTIND-1))
|
||||||
|
|
||||||
|
@@ -2,8 +2,9 @@
|
|||||||
whoami(){ echo $INSTANCE $TOKE; }
|
whoami(){ echo $INSTANCE $TOKE; }
|
||||||
login()
|
login()
|
||||||
{
|
{
|
||||||
post "user/login" "{\"username_or_email\":\"$1\",\"password\":\"$2\"}"
|
post "user/login" '{"username_or_email":"'$1'","password":"'$2'"}'
|
||||||
}
|
}
|
||||||
|
|
||||||
register()
|
register()
|
||||||
{
|
{
|
||||||
get "site" ".site_view.site | .open_registration,.require_email_verification,.require_application,.application_question" | jq -r . | read reg em app appq
|
get "site" ".site_view.site | .open_registration,.require_email_verification,.require_application,.application_question" | jq -r . | read reg em app appq
|
||||||
@@ -17,14 +18,14 @@ register()
|
|||||||
if [ ! reg_pw == reg_pw2 ]; then echo "passwords don't match (continuing anyway, expect failure later though)"; fi
|
if [ ! reg_pw == reg_pw2 ]; then echo "passwords don't match (continuing anyway, expect failure later though)"; fi
|
||||||
namedget reg_email "Email address $em"
|
namedget reg_email "Email address $em"
|
||||||
if [ $app == true ]; then namedget reg_appa "Application question: $appq"; fi
|
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\"}")"
|
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
|
if [ ! $(jq .error <<< "$result") == "captcha_incorrect" ]; then
|
||||||
jq <<< "result"; exit;
|
jq <<< "$result"; exit;
|
||||||
fi
|
fi
|
||||||
a="$(get "user/get_captcha" ".ok")"
|
a="$(get "user/get_captcha" ".ok")"
|
||||||
reg_uuid=$(jq -r '.uuid' <<< "$a")
|
reg_uuid=$(jq -r '.uuid' <<< "$a")
|
||||||
jq -r '.wav' <<< "$a" | base64 -d > "captcha.wav"
|
jq -r '.wav' <<< "$a" | base64 -d > "captcha.wav"
|
||||||
jq -r '.png' <<< "$a" | base64 -d > "captcha.png"
|
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"
|
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\"}"
|
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'"}'
|
||||||
}
|
}
|
26
commands/admin.sh
Normal file
26
commands/admin.sh
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
pendcount()
|
||||||
|
{
|
||||||
|
get "admin/registration_application/count" ".registration_applications"
|
||||||
|
}
|
||||||
|
|
||||||
|
pending()
|
||||||
|
{
|
||||||
|
applications=$(get "admin/registration_application/list" ".registration_applications" "unread_only=true")
|
||||||
|
i=0
|
||||||
|
app=$(jq ".[$i] // empty" <<< "$applications")
|
||||||
|
while [ -n "$app" ]; do
|
||||||
|
appid=$(jq -r .registration_application.id <<< "$app")
|
||||||
|
jq '.registration_application.id, (.creator | .name,.published,.bio,"bot: "+.bot_account,"matrix: "+.matrix_user_id,.avatar,.banner), "captcha: "+.registration_application.answer' <<< "$app"
|
||||||
|
ans= # Better make sure this resets lol
|
||||||
|
while [ ! ans = 'y' -a ! ans = 'n' -a ! ans = 's' ]; do
|
||||||
|
namedget ans "Accept? (y)es (n)o (s)kip"
|
||||||
|
done
|
||||||
|
case $ans in
|
||||||
|
y) put "admin/registration_application/approve" '{"id":'$appid',"approve":true}';;
|
||||||
|
n) namedget rejected "Why not?" true; put "admin/registration_application/approve" '{"id":'$appid',"deny_reason":"'$rejected'","approve":false}';;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
addadmin(){ echo "stub"; }
|
||||||
|
remadmin(){ echo "stub"; }
|
@@ -1,8 +1,12 @@
|
|||||||
actions="notifs notifs2 comments freepost shitpost follow unfollow home deref whoami login"
|
actions="notifs notifs2 comments freepost shitpost follow unfollow home deref whoami login pendcount pending"
|
||||||
#Endpoints in other files mostly.
|
#Endpoints in other files mostly.
|
||||||
source commands/accounts.sh
|
imps=$(dirname $(realpath $0))
|
||||||
source commands/communities.sh
|
|
||||||
source commands/lurking.sh
|
source $imps/commands/accounts.sh
|
||||||
source commands/posts.sh
|
source $imps/commands/communities.sh
|
||||||
|
source $imps/commands/lurking.sh
|
||||||
|
source $imps/commands/posts.sh
|
||||||
|
source $imps/commands/admin.sh
|
||||||
|
|
||||||
#Misc
|
#Misc
|
||||||
deref(){ getauth "resolve_object" "" "q=$*"; }
|
deref(){ get "resolve_object" "" "q=$*"; }
|
@@ -1,4 +1,10 @@
|
|||||||
#Community hoardan
|
#Community hoardan
|
||||||
follow(){ post "community/follow" "{\"community_id\":$1,\"follow\":true}"; }
|
follow(){ post "community/follow" '{"community_id":'$1',"follow":true}'; }
|
||||||
unfollow(){ post "community/follow" "{\"community_id\":$1,\"follow\":false}"; }
|
unfollow(){ post "community/follow" '{"community_id":'$1',"follow":false}'; }
|
||||||
following(){ echo "use <home> instead"; } # Maybe this will help.
|
following(){ get "community/list" ".communities | $communities_jq" "type_=Subscribed"; } # Alright it's time
|
||||||
|
|
||||||
|
comcreate(){ namedget desc "The community's display name (can be edited later)"; post "community" '{"name":"'$1'","title":"'"$desc"'"}'; }
|
||||||
|
comedit(){ echo "stub"; }
|
||||||
|
comdelete(){ namedget confirm "are you sure? (y/n)"; if [ confirm == "y" ]; then post "community/delete" '{"community_id":"'$1'","deleted":true}'; fi; }
|
||||||
|
addmod(){ echo "stub"; }
|
||||||
|
remmod(){ echo "stub"; }
|
@@ -1,5 +1,7 @@
|
|||||||
#Lurkan
|
#Lurkan
|
||||||
notifs(){ getauth "user/replies" ".replies | reverse | $notifs"; }
|
notifs(){ get "user/replies" ".replies | reverse | $notifs_jq"; }
|
||||||
notifs2(){ getauth "user/mention" ".mentions | reverse | $notifs"; }
|
notifs2(){ echo "use mentions instead"; }
|
||||||
home(){ getauth "post/list" ".posts | $posts" "type_=Subscribed"; }
|
mentions(){ get "user/mention" ".mentions | reverse | $notifs_jq"; }
|
||||||
comments(){ getauth "post" "(.post_view | $showpost), (.comments | reverse | $comments)" "id=$1"; }
|
home(){ get "post/list" ".posts | $posts_jq" "type_=Subscribed"; }
|
||||||
|
#This has to get complex now -.-
|
||||||
|
comments(){ get "post" "(.post_view | $full_post_jq)" "id=$1"; get "comment/list" "(.comments | reverse | $comments_jq)" "post_id=$1&sort=New"; }
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
#Post hoardan
|
#Post hoardan
|
||||||
save(){ put "post/save" "{\"post_id\":$1,\"save\":true}"; }
|
save(){ put "post/save" '{"post_id":'$1',"save":true}'; }
|
||||||
unsave(){ put "post/save" "{\"post_id\":$1,\"save\":false}"; }
|
unsave(){ put "post/save" '{"post_id":'$1',"save":false}'; }
|
||||||
load(){ getauth "post/list" ".posts | .[] | $postsummary" "type_=All&saved_only=true"; }
|
load(){ get "post/list" ".posts | .[] | $short_post_jq" "type_=All&saved_only=true"; }
|
||||||
#Postan
|
#Postan
|
||||||
freepost(){ getbody; post "post" "{\"community_id\":$1,\"name\":\"${*:2}\",\"body\":\"$body\"}"; }
|
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\"}"; }
|
shitpost(){ getbody; postid=$1; parentid=$2; if [ -z $parentid ]; then parentid=null; fi; post "comment" '{"post_id":'$postid',"parent_id":'$parentid',"content":"'$body'"}'; }
|
16
creds.sh
16
creds.sh
@@ -1,4 +1,5 @@
|
|||||||
if [ ! -f ~/.config/clemmy/accounts.csv ]; then
|
if [ ! -f ~/.config/clemmy/accounts.csv ]; then
|
||||||
|
mkdir -p ~/.config/clemmy
|
||||||
touch ~/.config/clemmy/accounts.csv
|
touch ~/.config/clemmy/accounts.csv
|
||||||
echo "Do you already have an account? y/n"
|
echo "Do you already have an account? y/n"
|
||||||
read choice
|
read choice
|
||||||
@@ -10,11 +11,16 @@ if [ ! -f ~/.config/clemmy/accounts.csv ]; then
|
|||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
accs=$(cat ~/.config/clemmy/accounts.csv)
|
touch ~/.config/clemmy/default_account
|
||||||
|
|
||||||
|
accsr=$(cat ~/.config/clemmy/accounts.csv)
|
||||||
i=0
|
i=0
|
||||||
for line in ${accs[*]}; do
|
for line in ${accsr[*]}; do
|
||||||
IFS=, read insts[$i] tokes[$i] <<< $line
|
accs[$i]="$line"
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
INSTANCE=${insts[0]}
|
|
||||||
TOKE=${tokes[0]}
|
select_account(){ IFS=, read INSTANCE TOKE INSEC <<< "${accs[$1]}"; }
|
||||||
|
defaultacc(){ echo -n $1 > ~/.config/clemmy/default_account; }
|
||||||
|
|
||||||
|
select_account $(cat ~/.config/clemmy/default_account)
|
||||||
|
31
pretty.sh
31
pretty.sh
@@ -1,23 +1,24 @@
|
|||||||
# Please don't abuse jq like this
|
# Please don't abuse jq like this
|
||||||
showpost='(.post | (.id | tostring)+" "+(.name | tostring)),
|
full_post_jq='(.post | (.id | tostring)+" "+(.name | tostring)),
|
||||||
(.post.url)+", "+(.creator.display_name // .creator.name)+":",
|
(.post.url)+", "+(.creator.display_name // .creator.name)+":",
|
||||||
((.comment // .post) | .published,
|
((.comment // .post) | .published,
|
||||||
(.body // .content)),
|
(.body // .content))'
|
||||||
""'
|
short_post_jq='(.post | (.id | tostring)+" "+(.name | tostring)),
|
||||||
postsummary='(.post | (.id | tostring)+" "+(.name | tostring)),
|
|
||||||
(.post.url)+", "+(.creator.display_name // .creator.name)+":",
|
(.post.url)+", "+(.creator.display_name // .creator.name)+":",
|
||||||
((.comment // .post) | .published),
|
((.comment // .post) | .published)'
|
||||||
""'
|
comment_jq='(.comment | .path[2:])+", "+(.creator.display_name // .creator.name)+":",
|
||||||
showcomment='(.comment | (.parent_id | tostring)+"->"+(.id | tostring))+", "+(.creator.display_name // .creator.name)+":",
|
|
||||||
((.comment // .post) | .published,
|
((.comment // .post) | .published,
|
||||||
(.body // .content)),
|
(.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.
|
#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)+":",
|
notif_jq='(.comment | (.parent_id | tostring)+"->"+(.id | tostring))+" ("+(.post | (.id | tostring))+"), "+(.creator.display_name // .creator.name)+":",
|
||||||
((.comment // .post) | .published,
|
((.comment // .post) | .published,
|
||||||
(.body // .content)),
|
(.body // .content))'
|
||||||
""'
|
community_jq='(.community | (.id | tostring)+" "+.actor_id,.description),
|
||||||
|
.subscribed,
|
||||||
|
(.counts | [.subscribers,.posts,.comments,.users_active_week] | join(" "))'
|
||||||
|
|
||||||
comments=".[] | $showcomment"
|
multi_jq(){ echo '.[] | '"$1"',""'; }
|
||||||
posts=".[] | $showpost"
|
comments_jq=$(multi_jq "$comment_jq")
|
||||||
notifs=".[] | $notif"
|
posts_jq=$(multi_jq "$full_post_jq")
|
||||||
|
notifs_jq=$(multi_jq "$notif_jq")
|
||||||
|
communities_jq=$(multi_jq "$community_jq")
|
Reference in New Issue
Block a user