Add /konachan command

This commit is contained in:
Michael De Roover 2021-02-17 00:16:10 +01:00
parent ce7bc467e8
commit f181ffe7ab
Signed by: vim
GPG Key ID: 075496E232CE04CB

View File

@ -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