some more comment polishing

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2020-08-01 11:37:32 +02:00
parent aec73450af
commit c4ab7ff4ee
3 changed files with 19 additions and 22 deletions

View File

@ -3,20 +3,20 @@
# do not edit, this file will be overwritten on update # do not edit, this file will be overwritten on update
# bashbot, the Telegram bot written in bash. # bashbot, the Telegram bot written in bash.
# Written by Drew (@topkecleon) and Daniil Gentili (@danogentili), KayM (@gnadelwartz). # Written by Drew (@topkecleon) KayM (@gnadelwartz).
# Also contributed: JuanPotato, BigNerd95, TiagoDanin, iicc1. # Also contributed: Daniil Gentili (@danogentili), JuanPotato, BigNerd95, TiagoDanin, iicc1.
# https://github.com/topkecleon/telegram-bot-bash # https://github.com/topkecleon/telegram-bot-bash
# Depends on JSON.sh (http://github.com/dominictarr/JSON.sh) (MIT/Apache), # Depends on JSON.sh (http://github.com/dominictarr/JSON.sh) (MIT/Apache),
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ 0.99-0-g2775000 #### $$VERSION$$ 0.99-5-gaec7345
# #
# Exit Codes: # Exit Codes:
# - 0 success (hopefully) # - 0 success (hopefully)
# - 1 can't change to dir # - 1 can't change to dir
# - 2 can't write to tmp, count or token # - 2 can't write to tmp, count or token
# - 3 user / command / file not found # - 3 user / command / file not found
# - 4 unknown command # - 4 unknown command
# - 5 cannot connect to telegram bot # - 5 cannot connect to telegram bot
@ -39,7 +39,6 @@ fi
_exists() { _exists() {
[ "$(LC_ALL=C type -t "${1}")" = "file" ] [ "$(LC_ALL=C type -t "${1}")" = "file" ]
} }
# execute function if exists # execute function if exists
_exec_if_function() { _exec_if_function() {
[ "$(LC_ALL=C type -t "${1}")" != "function" ] && return 1 [ "$(LC_ALL=C type -t "${1}")" != "function" ] && return 1
@ -50,7 +49,7 @@ _is_function() {
[ "$(LC_ALL=C type -t "${1}")" = "function" ] [ "$(LC_ALL=C type -t "${1}")" = "function" ]
} }
# round $1 in international notation! , returns float with $2 decimal digits # round $1 in international notation! , returns float with $2 decimal digits
# if $2 is not fiven or is not a positive number, it's set to zero # if $2 is not given or is not a positive number zero is assumed
_round_float() { _round_float() {
local digit="${2}"; [[ "${2}" =~ ^[0-9]+$ ]] || digit="0" local digit="${2}"; [[ "${2}" =~ ^[0-9]+$ ]] || digit="0"
LC_ALL=C printf "%.${digit}f" "${1}" LC_ALL=C printf "%.${digit}f" "${1}"
@ -64,13 +63,13 @@ getConfigKey() {
[[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3 [[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3
[ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${BOTCONFIG}.jssh" | tail -n 1 [ -r "${BOTCONFIG}.jssh" ] && sed -n 's/\["'"$1"'"\]\t*"\(.*\)"/\1/p' <"${BOTCONFIG}.jssh" | tail -n 1
} }
# $1 token # check if $1 seems a valid token
# return true if token seems to be valid # return true if token seems to be valid
check_token(){ check_token(){
[[ "${1}" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ ]] && return 0 [[ "${1}" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ ]] && return 0
return 1 return 1
} }
# log error to ERRORLOG with date # log $1 to ERRORLOG with date
log_error(){ log_error(){
printf "%s: %s\n" "$(date)" "$*" >>"${ERRORLOG}" printf "%s: %s\n" "$(date)" "$*" >>"${ERRORLOG}"
} }
@ -129,7 +128,7 @@ fi
[ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="$BASHBOT_HOME" [ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="$BASHBOT_HOME"
ADDONDIR="${BASHBOT_ETC:-.}/addons" ADDONDIR="${BASHBOT_ETC:-.}/addons"
RUNUSER="${USER}" # USER is overwritten by bashbot array RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original
# OK everything setup, lest start # OK everything setup, lest start
if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then
@ -155,12 +154,12 @@ COUNTFILE="${BASHBOT_VAR:-.}/count"
LOGDIR="${RUNDIR:-.}/logs" LOGDIR="${RUNDIR:-.}/logs"
# we assume everything is already set up correctly if we have TOKEN # assume everything already set up correctly if TOKEN is set
if [ -z "${BOTTOKEN}" ]; then if [ -z "${BOTTOKEN}" ]; then
# BOTCONFIG does not exist, create # BOTCONFIG does not exist, create
[ ! -f "${BOTCONFIG}.jssh" ] && [ ! -f "${BOTCONFIG}.jssh" ] &&
printf '["bot_config_key"]\t"config_key_value"\n' >>"${BOTCONFIG}.jssh" printf '["bot_config_key"]\t"config_key_value"\n' >>"${BOTCONFIG}.jssh"
# BOTTOKEN empty read ask user # do we have already a token?
if [ -z "$(getConfigKey "bottoken")" ]; then if [ -z "$(getConfigKey "bottoken")" ]; then
# convert old token # convert old token
if [ -r "${TOKENFILE}" ]; then if [ -r "${TOKENFILE}" ]; then
@ -178,7 +177,7 @@ if [ -z "${BOTTOKEN}" ]; then
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh" [ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
fi fi
# setup botadmin file # no boteadmin, setup botadmin
if [ -z "$(getConfigKey "botadmin")" ]; then if [ -z "$(getConfigKey "botadmin")" ]; then
# convert old admin # convert old admin
if [ -r "${BOTADMIN}" ]; then if [ -r "${BOTADMIN}" ]; then

View File

@ -15,7 +15,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ 0.99-0-g2775000 #### $$VERSION$$ 0.99-5-gaec7345
# #
# adjust your language setting here, e.g.when run from other user or cron. # adjust your language setting here, e.g.when run from other user or cron.
@ -27,7 +27,7 @@ export 'LANGUAGE=C.UTF-8'
unset IFS unset IFS
# set -f # if you are paranoid use set -f to disable globbing # set -f # if you are paranoid use set -f to disable globbing
# #-----------------------------
# this file *MUST* not edited! # this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there # copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
bashbot_info='This is bashbot, the Telegram bot written entirely in bash. bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
@ -35,7 +35,7 @@ It features background tasks and interactive chats, and can serve as an interfac
It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files. It currently can send, receive and forward messages, custom keyboards, photos, audio, voice, documents, locations and video files.
' '
# #-----------------------------
# this file *MUST* not edited! # this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there # copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
bashbot_help='Place your own commands and messages in mycommands.sh bashbot_help='Place your own commands and messages in mycommands.sh
@ -52,7 +52,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili) and KayM(@gnadelwar
Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash) Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
' '
# load modues on startup and always on on debug # load modules on startup and always on on debug
if [ -n "${1}" ]; then if [ -n "${1}" ]; then
# load all readable modules # load all readable modules
for modules in "${MODULEDIR:-.}"/*.sh ; do for modules in "${MODULEDIR:-.}"/*.sh ; do
@ -63,7 +63,7 @@ if [ -n "${1}" ]; then
done done
fi fi
# #----------------------------
# this file *MUST* not edited! # this file *MUST* not edited!
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values there # copy "mycommands.sh.dist" to "mycommnds.sh" and change the values there
# defaults to no inline and nonsense home dir # defaults to no inline and nonsense home dir

View File

@ -1,20 +1,18 @@
#!/bin/bash #!/bin/bash
# file: interactive.sh # file: interactive.sh
# template for an interactive chat # template for an interactive chat
# test it with: start_proc "${CHAT[ID]}" "./scripts/interactive.sh.clean" # test: start_proc "${CHAT[ID]}" "./scripts/interactive.sh.clean"
# #
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ 0.99-0-g2775000 #### $$VERSION$$ 0.99-5-gaec7345
###### ######
# parameters # parameters
# $1 $2 args as given to starct_proc chat script arg1 arg2 # $1 $2 args as given to start_proc chat script arg1 arg2
# $3 path to named pipe # $3 path to named pipe
# adjust your language setting here # adjust your language setting here
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment # https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
export 'LC_ALL=C.UTF-8' export 'LC_ALL=C.UTF-8'