Skip to content

Commit

Permalink
Merge pull request #193 from topkecleon/develop
Browse files Browse the repository at this point in the history
Bashbot Version 1.52
  • Loading branch information
gnadelwartz authored Jun 27, 2022
2 parents 479f41c + bc71f37 commit 4591b35
Show file tree
Hide file tree
Showing 84 changed files with 138 additions and 121 deletions.
2 changes: 1 addition & 1 deletion README.html
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,6 @@ <h3>Blocked by telegram?</h3>
<p>@Gnadelwartz</p>
<h2>That's it all guys!</h2>
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
<h4>$$VERSION$$ v1.51-0-g6e66a28</h4>
<h4>$$VERSION$$ v1.52-0-g1a83202</h4>
</body>
</html>
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -242,4 +242,4 @@ See `mycommnds.sh.dist` for an example.

If you feel that there's something missing or if you found a bug, feel free to submit a pull request!

#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
2 changes: 1 addition & 1 deletion README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -319,5 +319,5 @@ That's it all guys!
If you feel that there's something missing or if you found a bug, feel free to submit a
pull request!

$$VERSION$$ v1.51-0-g6e66a28
$$VERSION$$ v1.52-0-g1a83202

2 changes: 1 addition & 1 deletion addons/antiFlood.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# this addon counts how many files, e.g. stickers, are sent to
# a chat and takes actions if threshold is reached
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db

# used events:
#
Expand Down
2 changes: 1 addition & 1 deletion addons/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# Addons can register to bashbot events at startup
# by providing their name and a callback per event
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#
# If an event occurs each registered event function is called.
#
Expand Down
46 changes: 23 additions & 23 deletions bashbot.rc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/bin/sh
#!/bin/bash
# description: Start or stop telegram-bash-bot
#
# example service script to run bashbot in background as specified user
#
# tested on: ubuntu, opensuse, debian
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
# shellcheck disable=SC2009
# shellcheck disable=SC2181
# shellcheck disable=SC2250
Expand Down Expand Up @@ -59,63 +59,63 @@ hooklog="WEBHOOK"


# check for bot status
stat=""
ps -f -u "${runas}" | grep "${name}" | grep -qF "bashbot.sh startbot"
if [ "$?" = "0" ]; then
# printf "bashbot (%s) is running in poll mode\n" "${name}"
stat="poll"
stat="${stat} polling"
fi
ps -f -u "${runas}" | grep "${name}" | grep -qF "process_batch.sh --startbot"
if [ "$?" = "0" ]; then
#printf "bashbot (%s) is running in webhook mode\n" "${name}"
stat="${stat} webhook"
elif [ "${name}" != "unknown" ]; then
#printf "bashbot (%s) is stopped\n" "${name}"
stat="stop"
else
ps -f -u "${runas}" | grep "${name}" | grep -qF "process_batch.sh --startbot"
if [ "$?" = "0" ]; then
#printf "bashbot (%s) is running in webhook mode\n" "${name}"
stat="hook"
elif [ "${name}" != "unknown" ]; then
#printf "bashbot (%s) is stopped\n" "${name}"
stat="stop"
else
stat="unknown"
fi
stat="unknown"
fi

case "$1" in
'start')
[ "${stat}" != "stop" ] && printf "Warning, bot is running in mode: %s\n" "${stat}"
[ "${stat}" != "stop" ] && printf "Warning, bot is already running in mode: %s\n" "${stat}"
$runcmd "$bashbot start $mode" # >/dev/null 2>&1 </dev/null
RETVAL=$?
;;
'starthook')
[ -p "${FIFO}" ] || printf "Warning, webhook pipe not found: %s\n" "${FIFO##*/}"
[ "${stat}" != "stop" ] && printf "Warning, bot is running in mode: %s\n" "${stat}"
[ "${stat}" != "stop" ] && printf "Warning, bot is already running in mode: %s\n" "${stat}"
printf "Starting bashbot in webhook mode ... "
$runcmd "$webhook $mode </dev/null &>>${bashbotdir}/logs/${hooklog}.log &" # >/dev/null 2>&1 </dev/null
sleep 1
$0 status
RETVAL=$?
;;
'stop')
[ "${stat}" != "poll" ] && printf "Warning, bot is not in poll mode: %s\n" "${stat}"
[[ "${stat}" != *"poll"* ]] && printf "Warning, bot is not in poll mode: %s\n" "${stat}"
$runcmd "$bashbot stop $mode"
RETVAL=$?
;;
'stophook')
[ "${stat}" != "hook" ] && printf "Warning, bot is not in webhook mode: %s\n" "${stat}"
[[ "${stat}" != *"hook"* ]] && printf "Warning, bot is not in webhook mode: %s\n" "${stat}"
printf "Stopping bashbot webhook mode ... "
KILLID="$(ps -f -u "${runas}" | grep "process_batch.sh --startbot" | sed -E 's/[^0-9]+([0-9]+).*/\1/' | tr -s "\r\n" " ")"
if [ -n "${KILLID}" ]; then
$runcmd "kill ${KILLID}; wait ${KILLID} 2>/dev/null"
$runcmd "kill ${KILLID} 2>/dev/null; wait ${KILLID} 2>/dev/null"
sleep 1
fi
RETVAL=$?
$0 status
;;
'status')
case "${stat}" in
"poll"*) printf "bashbot (%s) is running in poll mode\n" "${name}"
*"poll"*) printf "bashbot (%s) is running in polling mode\n" "${name}"
RETVAL=0
;;
"hook"*) printf "bashbot (%s) is running in webhook mode\n" "${name}"
;;&
*"hook"*) printf "bashbot (%s) is running in webhook mode\n" "${name}"
RETVAL=0
;;
"stop"*) printf "bashbot (%s) is not running\n" "${name}"
*"stop"*) printf "bashbot (%s) is not running\n" "${name}"
RETVAL=1
;;
*) printf "bashbot (%s) status is %s\n" "${name}" "${stat}"
Expand All @@ -137,7 +137,7 @@ case "$1" in
;;
'suspendback'|'resumeback'|'killback')
# shellcheck disable=SC2250
$runcmd "$bashbot $1 $mode"
$runcmd "$bashbot $1"
RETVAL=$?
# kill inotifywait from runuser
if [ "$1" != "resumeback" ]; then
Expand Down
14 changes: 7 additions & 7 deletions bashbot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
# 8 - curl/wget missing
# 10 - not bash!
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
##################################################################

# are we running in a terminal?
Expand Down Expand Up @@ -550,14 +550,14 @@ if detect_curl ; then
# $1 URL, $2 hack: log getJson if not ""
getJson(){
# shellcheck disable=SC2086
"${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
"${BASHBOT_CURL}" -sL -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" -K - <<<"url=$1"
}
# curl variant for sendJson
# usage: "JSON" "URL"
sendJson_do(){
# shellcheck disable=SC2086
"${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
-d "$1" -X POST "$2" -H "Content-Type: application/json" | "${JSONSHFILE}" -b -n 2>/dev/null
-d "$1" -X POST -K - <<<"url=$2" -H "Content-Type: application/json" | "${JSONSHFILE}" -b -n 2>/dev/null
}
#$1 Chat, $2 what, $3 file, $4 URL, $5 caption
sendUpload() {
Expand All @@ -566,11 +566,11 @@ if detect_curl ; then
[ -n "${BASHBOTDEBUG}" ] &&\
log_update "sendUpload CHAT=$1 WHAT=$2 FILE=$3 CAPT=$5"
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -K - <<<"url=$4" -F "chat_id=$1"\
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -b -n 2>/dev/null )"
else
# shellcheck disable=SC2086
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -K - <<<"url=$4" -F "chat_id=$1"\
-F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -b -n 2>/dev/null )"
fi
sendJsonResult "${res}" "sendUpload (curl)" "$@"
Expand All @@ -581,14 +581,14 @@ else
if _exists wget; then
getJson(){
# shellcheck disable=SC2086
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1"
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - -i <<<"$1"
}
# curl variant for sendJson
# usage: "JSON" "URL"
sendJson_do(){
# shellcheck disable=SC2086
wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data="$1" \
--header='Content-Type:application/json' "$2" | "${JSONSHFILE}" -b -n 2>/dev/null
--header='Content-Type:application/json' -i <<<"$2" | "${JSONSHFILE}" -b -n 2>/dev/null
}
sendUpload() {
log_error "Sorry, wget does not support file upload"
Expand Down
2 changes: 1 addition & 1 deletion bin/any_command.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ USAGE='any_command.sh [-h|--help] [--force|--reference] bot_command args ...'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 30.01.2021 10:24
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/bashbot_env.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 18.12.2020 12:27
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

############
Expand Down
2 changes: 1 addition & 1 deletion bin/bashbot_init.inc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 27.01.2021 13:42
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================
# shellcheck disable=SC2059

Expand Down
2 changes: 1 addition & 1 deletion bin/bashbot_stats.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ USAGE='bashbot_stats.sh [-h|--help] [debug]'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 23.12.2020 20:34
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

# set bashbot environment
Expand Down
2 changes: 1 addition & 1 deletion bin/delete_message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 03.01.2021 15:37
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/edit_buttons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" "text|url" ...'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 21.01.2021 08:10
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/edit_message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID]
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 23.12.2020 16:52
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/kickban_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ USAGE='kickban_user.sh [-h|--help] [-u|--unban] "CHAT[ID]" "USER[ID]" [debug]'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 25.01.2021 20:34
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/process_batch.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ USAGE='process_batch.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n]
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 27.02.2021 13:14
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/process_update.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ USAGE='process_update.sh [-h|--help] [debug] [<file]'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 30.01.2021 19:14
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/promote_user.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ USAGE='promote_user.sh [-h|--help] "CHAT[ID]" "USER[ID]" "right[:true|false]" ..
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 25.01.2021 22:34
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/send_broadcast.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 16.12.2020 16:14
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/send_buttons.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "message" "text|url" ...'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 18.01.2021 11:34
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/send_dice.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 07.02.2021 18:45
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
2 changes: 1 addition & 1 deletion bin/send_file.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [deb
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 25.12.2020 20:24
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand Down
19 changes: 15 additions & 4 deletions bin/send_message.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@ USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]'
#
# DESCRIPTION: send a message to the given user/group
#
# OPTIONS: format - normal, markdown, html (optional)
# OPTIONS: format - normal, markdown, html, stdin, - (optional)
# CHAT[ID] - ID number of CHAT or BOTADMIN to send to yourself
# message - message to send in specified format
# if no format is givern send_message() format is used
#
# use format "stdin" to read message from stdin or from a file:
# send_message.sh stdin "CHAT[ID]" <file
# df -h | send_message.sh - "CHAT[ID]"
#
# -h - display short help
# --help - this help
#
Expand All @@ -22,7 +26,7 @@ USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]'
# AUTHOR: KayM (gnadelwartz), [email protected]
# CREATED: 16.12.2020 11:34
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#===============================================================================

####
Expand All @@ -41,6 +45,10 @@ case "$1" in
SEND="send_html_message"
shift
;;
"stdin"|"-")
FILE="stdin"
shift
;;
esac

# set bashbot environment
Expand All @@ -56,7 +64,10 @@ else
fi

# send message in selected format
"${SEND}" "${CHAT}" "$2"

if [ "${FILE}" = "stdin" ]; then
"${SEND}" "${CHAT}" "$(cat)"
else
"${SEND}" "${CHAT}" "$2"
fi
# output send message result
print_result
2 changes: 1 addition & 1 deletion commands.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
#
#### $$VERSION$$ v1.51-6-g6490f67
#### $$VERSION$$ v1.52-1-g0dae2db
#

# bashbot locale defaults to c.UTF-8, adjust locale in mycommands.sh if needed
Expand Down
Loading

0 comments on commit 4591b35

Please sign in to comment.