From c6a7ceb005a322d70e9c97764328c77f0c6a15c9 Mon Sep 17 00:00:00 2001 From: Zergling_man Date: Tue, 17 Jan 2023 01:46:39 +1100 Subject: [PATCH] MORE refactor --- clemmy.sh | 3 ++- commands.sh | 23 ----------------------- commands/accounts.sh | 3 +++ commands/commands.sh | 8 ++++++++ commands/communities.sh | 4 ++++ commands/lurking.sh | 5 +++++ commands/posts.sh | 7 +++++++ 7 files changed, 29 insertions(+), 24 deletions(-) delete mode 100644 commands.sh create mode 100644 commands/accounts.sh create mode 100644 commands/commands.sh create mode 100644 commands/communities.sh create mode 100644 commands/lurking.sh create mode 100644 commands/posts.sh diff --git a/clemmy.sh b/clemmy.sh index 92baeb3..3bb6997 100755 --- a/clemmy.sh +++ b/clemmy.sh @@ -1,9 +1,10 @@ #!/bin/sh source ./api.sh -source ./commands.sh +source ./commands/commands.sh source ./pretty.sh source ./creds.sh +source ./utils.sh while getopts "a:hv" o;do case "${o}" in a) INSTANCE=${insts[$OPTARG]}; TOKE=${tokes[$OPTARG]};; diff --git a/commands.sh b/commands.sh deleted file mode 100644 index 9eee878..0000000 --- a/commands.sh +++ /dev/null @@ -1,23 +0,0 @@ -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 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=$*"; } \ No newline at end of file diff --git a/commands/accounts.sh b/commands/accounts.sh new file mode 100644 index 0000000..01d0f6b --- /dev/null +++ b/commands/accounts.sh @@ -0,0 +1,3 @@ +#Account hoardan +whoami(){ echo $INSTANCE $TOKE; } +login(){ post "user/login" "{\"username_or_email\":\"$1\",\"password\":\"$2\"}"; } \ No newline at end of file diff --git a/commands/commands.sh b/commands/commands.sh new file mode 100644 index 0000000..33c0b1e --- /dev/null +++ b/commands/commands.sh @@ -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=$*"; } \ No newline at end of file diff --git a/commands/communities.sh b/commands/communities.sh new file mode 100644 index 0000000..788e539 --- /dev/null +++ b/commands/communities.sh @@ -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 instead"; } # Maybe this will help. \ No newline at end of file diff --git a/commands/lurking.sh b/commands/lurking.sh new file mode 100644 index 0000000..d4748b5 --- /dev/null +++ b/commands/lurking.sh @@ -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"; } \ No newline at end of file diff --git a/commands/posts.sh b/commands/posts.sh new file mode 100644 index 0000000..1e1f1f3 --- /dev/null +++ b/commands/posts.sh @@ -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\"}"; } \ No newline at end of file