Make /4c available to all users

This commit is contained in:
Michael De Roover 2021-02-07 17:12:19 +01:00
parent f8f2db52d3
commit 6b0053233b
Signed by: vim
GPG Key ID: 075496E232CE04CB

View File

@ -68,12 +68,12 @@ help(){
- /id - Get the current chat's ID.
- /ud \[term\] - Get a definition from Urban Dictionary.
- /konata - Get one of my selfies :3
- /4c [board] - Get a random image from 4chan.
- /repo - Get my source code.
Admin only commands:
- /mp3 \[link\] - Download an mp3 file from YouTube.
- /stat - Uptime, memory, storage stats.
- /term - Execute a command on the system.
- /4c - Get a random image from 4chan.
And a lot more to come!"
}
@ -128,6 +128,21 @@ konata(){
sendmsg "This picture appears to be NSFW! Here's the [sauce]($file)."
fi
}
4c(){
tmp="/tmp/4chan"
json="$tmp/${args[0]}.json"
[ ! -d $tmp ] && mkdir $tmp
[ $(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)
url="https://i.4cdn.org/${args[0]}/$img"
# TODO: Try to determine from JSON output whether image is PNG or JPG.
sendpic "$url.jpg"
sendpic "$url.png"
}
repo(){
sendmsg "You can find my source code [here](https://git.ghnou.su/ghnou/konata)."
}
@ -165,21 +180,6 @@ term(){
\`$(echo ${args[*]} | bash - 2>&1)\`"
}
4c(){
admin
tmp="/tmp/4chan"
json="$tmp/${args[0]}.json"
[ ! -d $tmp ] && mkdir $tmp
[ $(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)
url="https://i.4cdn.org/${args[0]}/$img"
# 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!"
@ -215,12 +215,12 @@ case "$cmd" in
/id@$bot) id ;;
/ud@$bot*) ud ;;
/konata@$bot*) konata ;;
/4c@$bot*) 4c ;;
/repo@$bot) repo ;;
# Administrative
/mp3@$bot*) mp3 ;;
/stat@$bot) stat ;;
/term@$bot*) term ;;
/4c*) 4c ;;
# Notes and such
!anyone*) anyone ;;
esac