From b9d2b611a3592d34bbf010e834a62c866f661a78 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Sun, 7 Feb 2021 10:43:27 +0100 Subject: [PATCH] Add 4c command --- konata.sh | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/konata.sh b/konata.sh index 57be7b4..00c2ed1 100755 --- a/konata.sh +++ b/konata.sh @@ -10,7 +10,7 @@ printf "Content-Type: text/plain\n\n" input=$(cat /dev/stdin) msg=$(jq -r '.message.text' <<< $input) cmd=$(cut -d" " -f1 <<< $msg) -args=$(cut -d" " -f2- <<< $msg) +args=($(cut -d" " -f2- <<< $msg)) chat=$(jq -r '.message.chat.id' <<< $input) user=$(jq -r '.message.from.username' <<< $input) @@ -134,7 +134,7 @@ repo(){ mp3(){ admin tmp="/tmp/mp3" - [ -d $tmp ] && mkdir $tmp + [ ! -d $tmp ] && mkdir $tmp sendmsg "Downloading, this might take a while..." youtube-dl -f 140 --max-filesize 50M -o "$tmp/%(title)s.%(ext)s" "$args" rm $tmp/*.part @@ -163,6 +163,25 @@ term(){ \`$(echo $args | bash - 2>&1)\`" } +4c(){ + admin + tmp="/tmp/4chan" + json="$tmp/${args[0]}.json" + [ ! -d $tmp ] && mkdir $tmp + [ ! -f $json ] && wget -O $json https://a.4cdn.org/${args[0]}/threads.json + thread=$(jq -r '.[].threads[].no' < $json | shuf | head -n1) + img=$(curl https://a.4cdn.org/${args[0]}/thread/$thread.json | jq -r '.posts[].tim' | shuf | head -n1) + url="https://i.4cdn.org/${args[0]}/$img" + sendlog "JSON: $json + Temp: $tmp + Thread: $thread + IMG: $img + URL: [JPG]($url.jpg) [PNG]($url.png)" + # TODO: Try to determine from JSON output whether image is PNG or JPG. + sendpic "$url.jpg" + sendpic "$url.png" +} + fail(){ debug "User @$user tried to execute $cmd and was rejected." sendmsg "Sorry, you are not allowed to use this command!" @@ -203,6 +222,7 @@ case "$cmd" in /mp3@$bot*) mp3 ;; /stat@$bot) stat ;; /term@$bot*) term ;; + /4c*) 4c ;; # Notes and such !anyone*) anyone ;; esac