From b85b566f1f15910ea2b6fd08022852b988b92927 Mon Sep 17 00:00:00 2001 From: Michael De Roover Date: Mon, 18 Jan 2021 16:03:26 +0100 Subject: [PATCH] Add various debugging utilities --- konata.sh | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/konata.sh b/konata.sh index 754129c..4d648f5 100755 --- a/konata.sh +++ b/konata.sh @@ -51,9 +51,16 @@ sendpic(){ -d "chat_id=$chat" -d "parse_mode=markdownv2" \ -d "photo=$1" -d "caption=$2" } +fdebug(){ + debug "Entered function $1()." +} +debug(){ + [ ! -z $debug ] && echo "[DEBUG] $1" >&2 +} # Public commands help(){ + fdebug "help" sendmsg "Hiya! I'm [ghnou](tg://user?id=990244311)'s personal bot, Konata. Currently I have the following features: - /help - Show this help message. @@ -71,10 +78,12 @@ help(){ } alive(){ + fdebug "alive" sendmsg "Alive and well!" } cv(){ + fdebug "cv" stats=$(curl -s "https://corona.lmao.ninja/v2/countries/$args") country=$(jq -r '.country' <<< $stats) cases=$(jq -r '.todayCases' <<< $stats) @@ -89,10 +98,12 @@ cv(){ } id(){ + fdebug "id" sendmsg "Chat ID: $chat" } ud(){ + fdebug "ud" 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 @@ -109,6 +120,7 @@ ud(){ } konata(){ + fdebug "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) file=$(jq -r '.[0].file_url' <<< $data) @@ -124,6 +136,7 @@ konata(){ # Administrative mp3(){ admin + fdebug "mp3" tmp="/tmp/mp3" [ -d $tmp ] && mkdir $tmp sendmsg "Downloading, this might take a while..." @@ -140,6 +153,7 @@ mp3(){ stat(){ admin + fdebug "stat" total=$(grep MemTotal /proc/meminfo | awk '{print $2}') avail=$(grep MemAvailable /proc/meminfo | awk '{print $2}') used=$(bc <<< "$total-$avail") @@ -150,20 +164,23 @@ stat(){ term(){ admin + fdebug "term" sendmsg "\`$(whoami)@${HOSTNAME}:${PWD}$\` \`$args\` \`$(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) continue ;; + ghnou) true ;; *) fail ;; esac + debug "Admin @$user tried to execute $cmd and was approved." } # Notes and such