diff --git a/konata.sh b/konata.sh index dd9e2e6..9c8efb3 100755 --- a/konata.sh +++ b/konata.sh @@ -31,28 +31,56 @@ sendmsg(){ fmt=$(sed 's/[>#+-=|{}.!]/\\&/g' <<< $1 | sed 's/\t//g') sendraw "$fmt" } + escape(){ sed "s/[$1]/\\\&/g" <<< $2 } + sendraw(){ curl -sX POST "https://api.telegram.org/bot$token/sendMessage" \ -d "chat_id=$chat" -d "parse_mode=markdownv2" \ -d "disable_web_page_preview=true" \ --data-urlencode "text=$1" } + sendlog(){ chat=$logchat sendmsg "$1" } + sendfile(){ curl -sF document=@"$1" "https://api.telegram.org/bot$token/sendDocument?chat_id=$chat" } + sendpic(){ curl -sX POST "https://api.telegram.org/bot$token/sendPhoto" \ -d "chat_id=$chat" -d "parse_mode=markdownv2" \ -d "photo=$1" -d "caption=$2" } +# Internal checks +args(){ + if [ -z ${args[*]} ] + then + sendmsg "Don't just click me like that. See /help@$bot for more info on how to use this bot." + exit 1 + fi +} + +admin(){ + case $user in + ghnou) true ;; + *) fail ;; + esac + debug "Admin @$user tried to execute $cmd and was approved." +} + +fail(){ + debug "User @$user tried to execute $cmd and was rejected." + sendmsg "Sorry, you are not allowed to use this command!" + exit 1 +} + # Debugging commands debug(){ [ ! -z $debug ] && echo "[DEBUG] $1" >&2 @@ -86,6 +114,7 @@ alive(){ } cv(){ + args stats=$(curl -s "https://corona.lmao.ninja/v2/countries/${args[*]}") mapfile -t cv <<< $(jq -cr '.[]' <<< $stats) if [ "${cv[4]}" == "0" ] @@ -114,6 +143,7 @@ id(){ } ud(){ + args enc=$(echo "${args[*]}" | sed "s/\ /%20/g") res=$(curl -s "https://api.urbandictionary.com/v0/define?term=$enc") if jq -re '.list[0].definition' <<< $res @@ -135,6 +165,7 @@ konata(){ } konachan(){ + args 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) @@ -152,6 +183,7 @@ konachan(){ } 4c(){ + args tmp="/tmp/4chan" json="$tmp/${args[0]}.json" [ ! -d $tmp ] && mkdir $tmp @@ -166,25 +198,24 @@ konachan(){ } lfy(){ + args query=$(sed "s/\ /+/g" <<< ${args[*]}) sendmsg "[Let me look that up for you](https://lmgtfy.app/?s=d&iee=1&q=$query)" } ip(){ - if [ ! -z ${args[0]} ] - then - ip=${args[0]} - res=$(curl -s http://ip-api.com/json/$ip) - # See https://0x0.st/Nlc0 for reference. - mapfile -t data <<< $(jq -cr '.[]' <<< $res) - sendmsg "*IP information for $ip:* - *Country:* ${data[1]} - *Region:* ${data[4]} - *City:* ${data[6]} ${data[5]} - *ISP:* ${data[10]} - *ASN:* ${data[12]} - *Time:* $(TZ=${data[9]} date +'%H:%M %Z')" - fi + args + ip=${args[0]} + res=$(curl -s http://ip-api.com/json/$ip) + # See https://0x0.st/Nlc0 for reference. + mapfile -t data <<< $(jq -cr '.[]' <<< $res) + sendmsg "*IP information for $ip:* + *Country:* ${data[1]} + *Region:* ${data[4]} + *City:* ${data[6]} ${data[5]} + *ISP:* ${data[10]} + *ASN:* ${data[12]} + *Time:* $(TZ=${data[9]} date +'%H:%M %Z')" } repo(){ @@ -194,6 +225,7 @@ repo(){ # Administrative mp3(){ admin + args tmp="/tmp/mp3" [ ! -d $tmp ] && mkdir $tmp sendmsg "Downloading, this might take a while..." @@ -224,20 +256,6 @@ term(){ \`$(echo ${args[*]} | bash - 2>&1)\`" } -fail(){ - debug "User @$user tried to execute $cmd and was rejected." - sendmsg "Sorry, you are not allowed to use this command!" - exit 1 -} - -admin(){ - case $user in - ghnou) true ;; - *) fail ;; - esac - debug "Admin @$user tried to execute $cmd and was approved." -} - # Notes and such anyone(){ sendmsg "Quite possibly. [Why do you ask?](https://dontasktoask.com)"