Add various debugging utilities

This commit is contained in:
2021-01-18 16:03:26 +01:00
parent 64704875a2
commit b85b566f1f

View File

@@ -51,9 +51,16 @@ sendpic(){
-d "chat_id=$chat" -d "parse_mode=markdownv2" \ -d "chat_id=$chat" -d "parse_mode=markdownv2" \
-d "photo=$1" -d "caption=$2" -d "photo=$1" -d "caption=$2"
} }
fdebug(){
debug "Entered function $1()."
}
debug(){
[ ! -z $debug ] && echo "[DEBUG] $1" >&2
}
# Public commands # Public commands
help(){ help(){
fdebug "help"
sendmsg "Hiya! I'm [ghnou](tg://user?id=990244311)'s personal bot, Konata. sendmsg "Hiya! I'm [ghnou](tg://user?id=990244311)'s personal bot, Konata.
Currently I have the following features: Currently I have the following features:
- /help - Show this help message. - /help - Show this help message.
@@ -71,10 +78,12 @@ help(){
} }
alive(){ alive(){
fdebug "alive"
sendmsg "Alive and well!" sendmsg "Alive and well!"
} }
cv(){ cv(){
fdebug "cv"
stats=$(curl -s "https://corona.lmao.ninja/v2/countries/$args") stats=$(curl -s "https://corona.lmao.ninja/v2/countries/$args")
country=$(jq -r '.country' <<< $stats) country=$(jq -r '.country' <<< $stats)
cases=$(jq -r '.todayCases' <<< $stats) cases=$(jq -r '.todayCases' <<< $stats)
@@ -89,10 +98,12 @@ cv(){
} }
id(){ id(){
fdebug "id"
sendmsg "Chat ID: $chat" sendmsg "Chat ID: $chat"
} }
ud(){ ud(){
fdebug "ud"
enc=$(echo "$args" | sed "s/\ /%20/g") enc=$(echo "$args" | sed "s/\ /%20/g")
res=$(curl -s "https://api.urbandictionary.com/v0/define?term=$enc") res=$(curl -s "https://api.urbandictionary.com/v0/define?term=$enc")
if jq -re '.list[0].definition' <<< $res if jq -re '.list[0].definition' <<< $res
@@ -109,6 +120,7 @@ ud(){
} }
konata(){ konata(){
fdebug "konata"
data=$(curl -s "https://konachan.net/post.json?limit=1&page=1&tags=order:random%20izumi_konata") data=$(curl -s "https://konachan.net/post.json?limit=1&page=1&tags=order:random%20izumi_konata")
jpeg=$(jq -r '.[0].jpeg_url' <<< $data) jpeg=$(jq -r '.[0].jpeg_url' <<< $data)
file=$(jq -r '.[0].file_url' <<< $data) file=$(jq -r '.[0].file_url' <<< $data)
@@ -124,6 +136,7 @@ konata(){
# Administrative # Administrative
mp3(){ mp3(){
admin admin
fdebug "mp3"
tmp="/tmp/mp3" tmp="/tmp/mp3"
[ -d $tmp ] && mkdir $tmp [ -d $tmp ] && mkdir $tmp
sendmsg "Downloading, this might take a while..." sendmsg "Downloading, this might take a while..."
@@ -140,6 +153,7 @@ mp3(){
stat(){ stat(){
admin admin
fdebug "stat"
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")
@@ -150,20 +164,23 @@ stat(){
term(){ term(){
admin admin
fdebug "term"
sendmsg "\`$(whoami)@${HOSTNAME}:${PWD}$\` \`$args\` sendmsg "\`$(whoami)@${HOSTNAME}:${PWD}$\` \`$args\`
\`$(echo $args | bash - 2>&1)\`" \`$(echo $args | bash - 2>&1)\`"
} }
fail(){ fail(){
debug "User @$user tried to execute $cmd and was rejected."
sendmsg "Sorry, you are not allowed to use this command!" sendmsg "Sorry, you are not allowed to use this command!"
exit 1 exit 1
} }
admin(){ admin(){
case $user in case $user in
ghnou) continue ;; ghnou) true ;;
*) fail ;; *) fail ;;
esac esac
debug "Admin @$user tried to execute $cmd and was approved."
} }
# Notes and such # Notes and such