Add 4c command

This commit is contained in:
2021-02-07 10:43:27 +01:00
parent 16de3252c7
commit b9d2b611a3

View File

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