mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-21 23:25:08 +00:00
bin: use BOTNAME BOTADMIN
This commit is contained in:
parent
e6838d1436
commit
b454827109
@ -30,7 +30,7 @@ BOTCOMMANDS="-h help init start stop status suspendback resumeback killb
|
||||
# 8 - curl/wget missing
|
||||
# 10 - not bash!
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-67-g53e936e
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
##################################################################
|
||||
|
||||
# are we running in a terminal?
|
||||
|
@ -21,7 +21,7 @@ USAGE='any_command.sh [-h|--help] [--force|--reference] bot_command args ...'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 30.01.2021 10:24
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-7-ga9ed559
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -68,7 +68,7 @@ fi
|
||||
# ready, do stuff here -----
|
||||
COMMAND="$1"
|
||||
if [ "$2" == "BOTADMIN" ]; then
|
||||
ARG1="${BOT_ADMIN}"
|
||||
ARG1="${BOTADMIN}"
|
||||
else
|
||||
ARG1="$2"
|
||||
fi
|
||||
|
@ -1,93 +0,0 @@
|
||||
#!/bin/bash
|
||||
#===============================================================================
|
||||
#
|
||||
# FILE: bashbot_env.inc.sh
|
||||
#
|
||||
# USAGE: source bashbot_env.inc.sh [debug]
|
||||
#
|
||||
# DESCRIPTION: set bashbot environment for all scripts in this directory
|
||||
#
|
||||
# OPTIONS: $1 - will be forwarded ro bashbot, e.g. debug
|
||||
#
|
||||
# LICENSE: WTFPLv2 http://www.wtfpl.net/txt/copying/
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 18.12.2020 12:27
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-67-g53e936e
|
||||
#===============================================================================
|
||||
|
||||
############
|
||||
# set where your bashbot lives
|
||||
export BASHBOT_HOME BASHBOT_ETC BASHBOT_VAR FILE_REGEX ME
|
||||
|
||||
# default: one dir up
|
||||
BASHBOT_HOME="$(cd "${BASH_SOURCE[0]%/*}/../" >/dev/null 2>&1 && pwd)"
|
||||
[ "${BASHBOT_HOME}" = "" ] && BASHBOT_HOME="../"
|
||||
|
||||
# set you own BASHBOT_HOME if different, e.g.
|
||||
# BASHBOT_HOME="/usr/local/telegram-bot-bash"
|
||||
BASHBOT_VAR="${BASHBOT_HOME}"
|
||||
BASHBOT_ETC="${BASHBOT_HOME}"
|
||||
|
||||
#####
|
||||
# if files are not readable, eviroment is wrong or bashbot is not initialized
|
||||
|
||||
# check for bashbot
|
||||
if [ ! -r "${BASHBOT_HOME}/bashbot.sh" ]; then
|
||||
printf "%s\n" "Bashbot.sh not found in \"${BASHBOT_HOME}\""
|
||||
exit 4
|
||||
fi
|
||||
|
||||
dev=" Are we in dev or did you forget to run init?"
|
||||
# check for botconfig.jssh readable
|
||||
if [ ! -r "${BASHBOT_ETC}/botconfig.jssh" ]; then
|
||||
printf "%s\n" "Bashbot config file in \"${BASHBOT_ETC}\" does not exist or is not readable. ${dev}"
|
||||
exit 3
|
||||
fi
|
||||
# check for count.jssh readable
|
||||
if [ ! -r "${BASHBOT_VAR}/count.jssh" ]; then
|
||||
printf "%s\n" "Bashbot count file in \"${BASHBOT_VAR}\" does not exist or is not readable. ${dev}"
|
||||
exit 3
|
||||
fi
|
||||
|
||||
# shellcheck disable=SC1090
|
||||
source "${BASHBOT_HOME}/bashbot.sh" source "$1"
|
||||
|
||||
# overwrite bot FILE regex to BASHBOT_VAR
|
||||
# change this to the location you want to allow file uploads from
|
||||
UPLOADDIR="${BASHBOT_VAR%/bin*}"
|
||||
FILE_REGEX="${UPLOADDIR}/.*"
|
||||
|
||||
# get and check ADMIN and NAME
|
||||
# shellcheck disable=SC2153
|
||||
BOT_ADMIN="${BOTADMIN}"
|
||||
BOT_NAME="$(getConfigKey "botname")"
|
||||
ME="${BOT_NAME}"
|
||||
[[ -z "${BOT_ADMIN}" || "${BOT_ADMIN}" == "?" ]] && printf "%s\n" "${ORANGE}Warning: Botadmin not set, send bot command${NC} /start"
|
||||
[[ -z "${BOT_NAME}" ]] && printf "%s\n" "${ORANGE}Warning: Botname not set, run bashbot.sh botname"
|
||||
|
||||
# default webhook pipe
|
||||
export WEBHOOK="${DATADIR}/webhook-fifo-${ME}"
|
||||
|
||||
|
||||
# output command result or Telegram response
|
||||
print_result() { jssh_printDB "BOTSENT" | sort -r; }
|
||||
print_response() { jssh_printDB "UPD"; }
|
||||
|
||||
# check and output help
|
||||
print_help() {
|
||||
case "$1" in
|
||||
'')
|
||||
printf "missing arguments\n"
|
||||
;&
|
||||
"-h"*)
|
||||
printf 'usage: %s\n' "${USAGE}"
|
||||
exit 1
|
||||
;;
|
||||
'--h'*)
|
||||
sed -n '/^#====/,/^#====/p' <"$0"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
@ -11,7 +11,7 @@
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 27.01.2021 13:42
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-59-ga9ac7ea
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
# shellcheck disable=SC2059
|
||||
|
||||
|
@ -17,7 +17,7 @@ USAGE='bashbot_stats.sh [-h|--help] [debug]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 23.12.2020 20:34
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
# set bashbot environment
|
||||
@ -27,7 +27,7 @@ source "${0%/*}/bashbot_env.inc.sh" "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
|
||||
echo -e "${GREEN}Hi I'm ${BOT_NAME}.${NC}"
|
||||
echo -e "${GREEN}Hi I'm ${BOTNAME}.${NC}"
|
||||
declare -A STATS
|
||||
jssh_readDB_async "STATS" "${COUNTFILE}"
|
||||
for MSG in ${!STATS[*]}
|
||||
|
@ -20,7 +20,7 @@ USAGE='delete_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" [debug]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 03.01.2021 15:37
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -34,7 +34,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -26,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "MESSAGE[ID]" "text|url" ...'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 21.01.2021 08:10
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -40,7 +40,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -23,7 +23,7 @@ USAGE='send_edit_message.sh [-h|--help] [format|caption] "CHAT[ID]" "MESSAGE[ID]
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 23.12.2020 16:52
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -55,7 +55,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -20,7 +20,7 @@ USAGE='kickban_user.sh [-h|--help] [-u|--unban] "CHAT[ID]" "USER[ID]" [debug]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 25.01.2021 20:34
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
|
@ -21,7 +21,7 @@ USAGE='process_update.sh [-h|--help] [-s|--startbot] [-w|--watch] [-n|--lines n]
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 27.02.2021 13:14
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-60-g2415814
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -83,7 +83,7 @@ tail ${follow} ${lines} "${file}" |\
|
||||
do
|
||||
# read json from stdin and convert update format
|
||||
# replace any ID named BOTADMIN with ID of bot admin
|
||||
: "${input//\"id\":BOTADMIN,/\"id\":${BOT_ADMIN},}"
|
||||
: "${input//\"id\":BOTADMIN,/\"id\":${BOTADMIN},}"
|
||||
json='{"result": ['"${_}"']}'
|
||||
UPDATE="$(${JSONSHFILE} -b -n <<<"${json}" 2>/dev/null)"
|
||||
|
||||
|
@ -15,7 +15,7 @@ USAGE='process_update.sh [-h|--help] [debug] [<file]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 30.01.2021 19:14
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-53-g941598d
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -33,7 +33,7 @@ print_help "${1:-nix}"
|
||||
# read json from stdin and convert update format
|
||||
# replace any ID named BOTADMIN with ID of bot admin
|
||||
json='{"result": ['"$(cat)"']}'
|
||||
json="${json//\"id\":BOTADMIN,/\"id\":${BOT_ADMIN},}"
|
||||
json="${json//\"id\":BOTADMIN,/\"id\":${BOTADMIN},}"
|
||||
UPDATE="$(${JSONSHFILE} -b -n <<<"${json}" 2>/dev/null)"
|
||||
|
||||
# process telegram update
|
||||
|
@ -25,7 +25,7 @@ USAGE='promote_user.sh [-h|--help] "CHAT[ID]" "USER[ID]" "right[:true|false]" ..
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 25.01.2021 22:34
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-53-g941598d
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
|
@ -28,7 +28,7 @@ USAGE='broadcast_message.sh [-h|--help] [--doit] [--groups|--both|--db=file] [fo
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 16.12.2020 16:14
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -91,7 +91,7 @@ if [ -z "${SENDALL[*]}" ]; then
|
||||
fi
|
||||
|
||||
# loop over users
|
||||
printf "${GREEN}Sending broadcast message to ${SENDTO}${GROUPSALSO} of ${BOT_NAME} using database:${NC}${GREY} ${database##*/}"
|
||||
printf "${GREEN}Sending broadcast message to ${SENDTO}${GROUPSALSO} of ${BOTNAME} using database:${NC}${GREY} ${database##*/}"
|
||||
|
||||
{ # dry run
|
||||
[ -z "${DOIT}" ] && printf "${NC}\n${ORANGE}DRY RUN! use --doit as first argument to execute broadcast...${NC}\n"
|
||||
|
@ -26,7 +26,7 @@ USAGE='send_message.sh [-h|--help] "CHAT[ID]" "message" "text|url" ...'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 18.01.2021 11:34
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -40,7 +40,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -21,7 +21,7 @@ USAGE='send_dice.sh [-h|--help] "CHAT[ID]" "emoji" [debug]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 07.02.2021 18:45
|
||||
#
|
||||
#### $$VERSION$$ v1.45-dev-8-g069570e
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -35,7 +35,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -1 +0,0 @@
|
||||
edit_message.sh
|
@ -25,7 +25,7 @@ USAGE='send_file.sh [-h|--help] "CHAT[ID]" "file|URL" "caption ...." [type] [deb
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 25.12.2020 20:24
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -39,7 +39,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -22,7 +22,7 @@ USAGE='send_message.sh [-h|--help] [format] "CHAT[ID]" "message ...." [debug]'
|
||||
# AUTHOR: KayM (gnadelwartz), kay@rrr.de
|
||||
# CREATED: 16.12.2020 11:34
|
||||
#
|
||||
#### $$VERSION$$ v1.40-0-gf9dab50
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
#===============================================================================
|
||||
|
||||
####
|
||||
@ -50,7 +50,7 @@ print_help "$1"
|
||||
####
|
||||
# ready, do stuff here -----
|
||||
if [ "$1" == "BOTADMIN" ]; then
|
||||
CHAT="${BOT_ADMIN}"
|
||||
CHAT="${BOTADMIN}"
|
||||
else
|
||||
CHAT="$1"
|
||||
fi
|
||||
|
@ -6,7 +6,7 @@
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
# shellcheck disable=SC1117,SC2059
|
||||
#### $$VERSION$$ v1.45-dev-67-g53e936e
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
@ -5,7 +5,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.45-dev-67-g53e936e
|
||||
#### $$VERSION$$ v1.45-dev-68-ge6838d1
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user