2020-12-25 20:57:07 +01:00
|
|
|
printf "Content-Type: text/plain\n\n"
|
|
|
|
|
|
|
|
input=$(cat /dev/stdin)
|
|
|
|
token=1493641835:AAGR7kLksUIjcrM-PXiVEM_yxLGqLGRWKZA
|
|
|
|
|
2020-12-26 13:48:27 +01:00
|
|
|
cmd=$(jq -r '.message.text' <<< $input)
|
|
|
|
args=$(cut -d" " -f2- <<< $cmd)
|
2020-12-25 20:57:07 +01:00
|
|
|
chat=$(jq -r '.message.chat.id' <<< $input)
|
2020-12-26 01:08:36 +01:00
|
|
|
user=$(jq -r '.message.from.username' <<< $input)
|
2020-12-25 20:57:07 +01:00
|
|
|
|
|
|
|
sendmsg(){
|
2020-12-26 12:32:10 +01:00
|
|
|
# Escape any special characters first, see https://0x0.st/NO7J.
|
|
|
|
fmt=$(sed 's/[][`~!@#$%^&*()-_=+{}\|;:",<.>/?'"'"']/\\&/g' <<< $1 | sed 's/\t//g')
|
2020-12-26 01:08:36 +01:00
|
|
|
curl -X POST "https://api.telegram.org/bot$token/sendMessage" \
|
2020-12-26 12:32:10 +01:00
|
|
|
-d "chat_id=$chat" -d "parse_mode=markdownv2" -d "text=$fmt"
|
2020-12-25 20:57:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
alive(){
|
2020-12-26 01:08:36 +01:00
|
|
|
sendmsg "Alive and well!"
|
|
|
|
}
|
|
|
|
|
|
|
|
hiya(){
|
|
|
|
sendmsg "Hiya! :3"
|
2020-12-25 20:57:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
stat(){
|
2020-12-26 12:32:10 +01:00
|
|
|
admin
|
2020-12-25 20:57:07 +01:00
|
|
|
total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
|
|
|
|
avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
|
|
|
|
used=$(bc <<< "$total-$avail")
|
2020-12-26 12:32:10 +01:00
|
|
|
sendmsg "$(uptime | cut -c2-)
|
|
|
|
I am using ${used}K of memory and \
|
|
|
|
$(df -h / | tail -n1 | awk '{print $3}') of storage."
|
2020-12-26 01:08:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
cv(){
|
2020-12-26 13:48:27 +01:00
|
|
|
stats=$(curl -sL corona.lmao.ninja/v2/countries/$args)
|
2020-12-26 01:08:36 +01:00
|
|
|
country=$(jq -r '.country' <<< $stats)
|
|
|
|
cases=$(jq -r '.todayCases' <<< $stats)
|
|
|
|
sendmsg "Today's COVID-19 cases for $country: $cases. Stay safe!"
|
|
|
|
}
|
|
|
|
|
|
|
|
id(){
|
|
|
|
sendmsg "Chat ID: $chat"
|
2020-12-25 20:57:07 +01:00
|
|
|
}
|
|
|
|
|
2020-12-26 12:32:10 +01:00
|
|
|
fail(){
|
|
|
|
sendmsg "Sorry, you are not allowed to use this command!"
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
|
|
|
|
admin(){
|
|
|
|
case $user in
|
|
|
|
ghnou) continue ;;
|
|
|
|
*) fail ;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2020-12-25 20:57:07 +01:00
|
|
|
case "$cmd" in
|
|
|
|
/alive*) alive ;;
|
|
|
|
/stat*) stat ;;
|
2020-12-26 01:08:36 +01:00
|
|
|
/cv*|/corona*) cv ;;
|
|
|
|
/id*) id ;;
|
|
|
|
@konatasanbot*) hiya ;;
|
2020-12-25 20:57:07 +01:00
|
|
|
esac
|