mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 00:37:34 +00:00
some more comment polishing
This commit is contained in:
parent
aec73450af
commit
c4ab7ff4ee
23
bashbot.sh
23
bashbot.sh
@ -3,20 +3,20 @@
|
||||
# do not edit, this file will be overwritten on update
|
||||
|
||||
# bashbot, the Telegram bot written in bash.
|
||||
# Written by Drew (@topkecleon) and Daniil Gentili (@danogentili), KayM (@gnadelwartz).
|
||||
# Also contributed: JuanPotato, BigNerd95, TiagoDanin, iicc1.
|
||||
# Written by Drew (@topkecleon) KayM (@gnadelwartz).
|
||||
# Also contributed: Daniil Gentili (@danogentili), JuanPotato, BigNerd95, TiagoDanin, iicc1.
|
||||
# https://github.com/topkecleon/telegram-bot-bash
|
||||
|
||||
# Depends on JSON.sh (http://github.com/dominictarr/JSON.sh) (MIT/Apache),
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ 0.99-0-g2775000
|
||||
#### $$VERSION$$ 0.99-5-gaec7345
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 success (hopefully)
|
||||
# - 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
|
||||
# - 4 unknown command
|
||||
# - 5 cannot connect to telegram bot
|
||||
@ -39,7 +39,6 @@ fi
|
||||
_exists() {
|
||||
[ "$(LC_ALL=C type -t "${1}")" = "file" ]
|
||||
}
|
||||
|
||||
# execute function if exists
|
||||
_exec_if_function() {
|
||||
[ "$(LC_ALL=C type -t "${1}")" != "function" ] && return 1
|
||||
@ -50,7 +49,7 @@ _is_function() {
|
||||
[ "$(LC_ALL=C type -t "${1}")" = "function" ]
|
||||
}
|
||||
# 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() {
|
||||
local digit="${2}"; [[ "${2}" =~ ^[0-9]+$ ]] || digit="0"
|
||||
LC_ALL=C printf "%.${digit}f" "${1}"
|
||||
@ -64,13 +63,13 @@ getConfigKey() {
|
||||
[[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3
|
||||
[ -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
|
||||
check_token(){
|
||||
[[ "${1}" =~ ^[0-9]{8,10}:[a-zA-Z0-9_-]{35}$ ]] && return 0
|
||||
return 1
|
||||
}
|
||||
# log error to ERRORLOG with date
|
||||
# log $1 to ERRORLOG with date
|
||||
log_error(){
|
||||
printf "%s: %s\n" "$(date)" "$*" >>"${ERRORLOG}"
|
||||
}
|
||||
@ -129,7 +128,7 @@ fi
|
||||
[ -z "${BASHBOT_VAR}" ] && BASHBOT_VAR="$BASHBOT_HOME"
|
||||
|
||||
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
|
||||
if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then
|
||||
@ -155,12 +154,12 @@ COUNTFILE="${BASHBOT_VAR:-.}/count"
|
||||
|
||||
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
|
||||
# BOTCONFIG does not exist, create
|
||||
[ ! -f "${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
|
||||
# convert old token
|
||||
if [ -r "${TOKENFILE}" ]; then
|
||||
@ -178,7 +177,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
||||
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
|
||||
fi
|
||||
|
||||
# setup botadmin file
|
||||
# no boteadmin, setup botadmin
|
||||
if [ -z "$(getConfigKey "botadmin")" ]; then
|
||||
# convert old admin
|
||||
if [ -r "${BOTADMIN}" ]; then
|
||||
|
10
commands.sh
10
commands.sh
@ -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$$ 0.99-0-g2775000
|
||||
#### $$VERSION$$ 0.99-5-gaec7345
|
||||
#
|
||||
|
||||
# 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
|
||||
# set -f # if you are paranoid use set -f to disable globbing
|
||||
|
||||
#
|
||||
#-----------------------------
|
||||
# this file *MUST* not edited!
|
||||
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
|
||||
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.
|
||||
'
|
||||
|
||||
#
|
||||
#-----------------------------
|
||||
# this file *MUST* not edited!
|
||||
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the strings there
|
||||
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)
|
||||
'
|
||||
|
||||
# load modues on startup and always on on debug
|
||||
# load modules on startup and always on on debug
|
||||
if [ -n "${1}" ]; then
|
||||
# load all readable modules
|
||||
for modules in "${MODULEDIR:-.}"/*.sh ; do
|
||||
@ -63,7 +63,7 @@ if [ -n "${1}" ]; then
|
||||
done
|
||||
fi
|
||||
|
||||
#
|
||||
#----------------------------
|
||||
# this file *MUST* not edited!
|
||||
# copy "mycommands.sh.dist" to "mycommnds.sh" and change the values there
|
||||
# defaults to no inline and nonsense home dir
|
||||
|
@ -1,20 +1,18 @@
|
||||
#!/bin/bash
|
||||
# file: interactive.sh
|
||||
# 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.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ 0.99-0-g2775000
|
||||
#### $$VERSION$$ 0.99-5-gaec7345
|
||||
|
||||
######
|
||||
# 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
|
||||
|
||||
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
export 'LC_ALL=C.UTF-8'
|
||||
|
Loading…
Reference in New Issue
Block a user