From f181ffe7ab29b9bc3401da9792496abb9049ef03 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Wed, 17 Feb 2021 00:16:10 +0100 Subject: [PATCH] Add /konachan command --- konata.sh | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/konata.sh b/konata.sh index 2a3d9ab..005f3d0 100755 --- a/konata.sh +++ b/konata.sh @@ -67,6 +67,7 @@ help(){ - /id - Get the current chat's ID. - /ud \[term\] - Get a definition from Urban Dictionary. - /konata - Get one of my selfies :3 + - /konachan \[query\] - Get a picture from Konachan. - /4c \[board\] - Get a random image from 4chan. - /repo - Get my source code. Admin only commands: @@ -122,15 +123,24 @@ ud(){ } konata(){ - data=$(curl -s "https://konachan.net/post.json?limit=1&page=1&tags=order:random%20izumi_konata") + args="izumi_konata" + konachan +} + +konachan(){ + query=$(sed "s/\ /_/g" <<< ${args[*]}) + data=$(curl -s "https://konachan.net/post.json?limit=1&page=1&tags=order:random%20$query") jpeg=$(jq -r '.[0].jpeg_url' <<< $data) file=$(jq -r '.[0].file_url' <<< $data) sfw=$(jq -r '.[0].rating' <<< $data) if [ $sfw == "s" ] then sendpic "$jpeg" "[sauce]($file)" - else + elif [ $sfw == "q" ] || [ $sfw == "x" ] + then sendmsg "This picture appears to be NSFW! Here's the [sauce]($file)." + else + sendmsg "No data!" fi } @@ -141,7 +151,7 @@ konata(){ [ $(find $json -mmin +60) ] && rm $json [ ! -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) + img=$(curl -s https://a.4cdn.org/${args[0]}/thread/$thread.json | jq -r '.posts[].tim' | shuf | head -n1) url="https://i.4cdn.org/${args[0]}/$img" # TODO: Try to determine from JSON output whether image is PNG or JPG. sendpic "$url.jpg" @@ -220,6 +230,7 @@ case "$cmd" in /id@$bot) id ;; /ud@$bot*) ud ;; /konata@$bot*) konata ;; + /konachan@$bot*) konachan ;; /4c@$bot*) 4c ;; /repo@$bot) repo ;; # Administrative