From e5d0b5d216b28922266ea20aac2d1a9d2965033d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Mon, 18 Mar 2019 15:32:17 +0100 Subject: [PATCH] add examples for background and checkproc to commands.sh --- commands.sh | 29 +++++++++++++++++++++++++++-- notify | 19 +++++++++++++++++++ 2 files changed, 46 insertions(+), 2 deletions(-) create mode 100755 notify diff --git a/commands.sh b/commands.sh index e8db74a..104616b 100755 --- a/commands.sh +++ b/commands.sh @@ -49,8 +49,32 @@ else fi case "$MESSAGE" in '/question') - startproc "./question" + checkproc + if [ $res -gt 0 ] ; then + startproc "./question" + else + send_normal_message "${CHAT[ID]}" "$MESSAGE already running ..." + fi ;; + + '/run-notify') + myback="notify"; checkback "$myback" + if [ $res -gt 0 ] ; then + background "./notify 60" "$myback" # notify every 60 seconds + else + send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." + fi + ;; + '/stop-notify') + myback="notify"; checkback "$myback" + if [ $res -eq 0 ] ; then + killback "$myback" + send_normal_message "${CHAT[ID]}" "Background command $myback canceled." + else + send_normal_message "${CHAT[ID]}" "No background command $myback is currently running.." + fi + ;; + '/info') send_markdown_message "${CHAT[ID]}" "This is bashbot, the *Telegram* bot written entirely in *bash*." ;; @@ -82,7 +106,8 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) ;; '/cancel') - if tmux ls | grep -q $copname; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi + checkprog + if [ $res -eq 0 ] ; then killproc && send_message "${CHAT[ID]}" "Command canceled.";else send_message "${CHAT[ID]}" "No command is currently running.";fi ;; *) if tmux ls | grep -v send | grep -q $copname;then inproc; else send_message "${CHAT[ID]}" "$MESSAGE" "safe";fi diff --git a/notify b/notify new file mode 100755 index 0000000..f666c11 --- /dev/null +++ b/notify @@ -0,0 +1,19 @@ +#!/bin/bash + +# This file is public domain in the USA and all free countries. +# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) + +# check if $1 is a number +re='^[0-9]+$' +if [[ $1 =~ $re ]] ; then + SLEEP="$1" +else + SLEEP=10 # time between time notifications +fi + +# output current time every $1 seconds +while sleep $SLEEP +do + date "+* It's %k:%M:%S o' clock ..." +done +