konata/konata.sh

29 lines
644 B
Bash
Raw Normal View History

2020-12-25 20:57:07 +01:00
printf "Content-Type: text/plain\n\n"
input=$(cat /dev/stdin)
token=1493641835:AAGR7kLksUIjcrM-PXiVEM_yxLGqLGRWKZA
cmd=$(jq -r '.message.text' <<< $input)
chat=$(jq -r '.message.chat.id' <<< $input)
sendmsg(){
curl -sX POST "https://api.telegram.org/bot$token/sendMessage" \
-d "chat_id=$chat" -d "parse_mode=markdownv2" -d "text=$1"
}
alive(){
sendmsg "Alive and well\!"
}
stat(){
total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
used=$(bc <<< "$total-$avail")
sendmsg "I am using $used KB of memory\."
}
case "$cmd" in
/alive*) alive ;;
/stat*) stat ;;
esac