Admin commands, Markdown escaping, and minor improvements
This commit is contained in:
21
konata.sh
21
konata.sh
@@ -8,8 +8,10 @@ chat=$(jq -r '.message.chat.id' <<< $input)
|
|||||||
user=$(jq -r '.message.from.username' <<< $input)
|
user=$(jq -r '.message.from.username' <<< $input)
|
||||||
|
|
||||||
sendmsg(){
|
sendmsg(){
|
||||||
|
# Escape any special characters first, see https://0x0.st/NO7J.
|
||||||
|
fmt=$(sed 's/[][`~!@#$%^&*()-_=+{}\|;:",<.>/?'"'"']/\\&/g' <<< $1 | sed 's/\t//g')
|
||||||
curl -X POST "https://api.telegram.org/bot$token/sendMessage" \
|
curl -X POST "https://api.telegram.org/bot$token/sendMessage" \
|
||||||
-d "chat_id=$chat" -d "text=$1"
|
-d "chat_id=$chat" -d "parse_mode=markdownv2" -d "text=$fmt"
|
||||||
}
|
}
|
||||||
|
|
||||||
alive(){
|
alive(){
|
||||||
@@ -21,10 +23,13 @@ hiya(){
|
|||||||
}
|
}
|
||||||
|
|
||||||
stat(){
|
stat(){
|
||||||
|
admin
|
||||||
total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
|
total=$(grep MemTotal /proc/meminfo | awk '{print $2}')
|
||||||
avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
|
avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}')
|
||||||
used=$(bc <<< "$total-$avail")
|
used=$(bc <<< "$total-$avail")
|
||||||
sendmsg "I am using $used KB of memory."
|
sendmsg "$(uptime | cut -c2-)
|
||||||
|
I am using ${used}K of memory and \
|
||||||
|
$(df -h / | tail -n1 | awk '{print $3}') of storage."
|
||||||
}
|
}
|
||||||
|
|
||||||
cv(){
|
cv(){
|
||||||
@@ -38,6 +43,18 @@ id(){
|
|||||||
sendmsg "Chat ID: $chat"
|
sendmsg "Chat ID: $chat"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fail(){
|
||||||
|
sendmsg "Sorry, you are not allowed to use this command!"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
admin(){
|
||||||
|
case $user in
|
||||||
|
ghnou) continue ;;
|
||||||
|
*) fail ;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
/alive*) alive ;;
|
/alive*) alive ;;
|
||||||
/stat*) stat ;;
|
/stat*) stat ;;
|
||||||
|
Reference in New Issue
Block a user