Merge pull request #146 Bashbot Version 1.0 preview

Version 1.0 preview
This commit is contained in:
Kay Marquardt 2020-08-08 18:01:39 +02:00 committed by GitHub
commit 99217c4e25
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 872 additions and 135 deletions

View File

@ -191,7 +191,7 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>Running a Telegram Bot means it is connected to the public and you never know what's send to your Bot.</p>
<p>Bash scripts in general are not designed to be bullet proof, so consider this Bot as a proof of concept. Bash programmers often struggle with 'quoting hell' and globbing, see <a href="https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells">Implications of wrong quoting</a></p>
<p>Whenever you are processing input from untrusted sources (messages, files, network) you must be as careful as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everything. In addition delete unused scripts and examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable all not used commands.</p>
<p><strong>Note:</strong> Until v0.941 (mai/22/2020) telegram-bot-bash had a remote code execution (RCE) bug, please update if you use an older version! see <a href="https://github.com/topkecleon/telegram-bot-bash/issues/125">Issue #125</a></p>
<p><strong>Note:</strong> Up to version v0.941 (mai/22/2020) telegram-bot-bash had a remote code execution (RCE) bug, please update if you use an older version! see <a href="https://github.com/topkecleon/telegram-bot-bash/issues/125">Issue #125</a></p>
<p>One of the most powerful features of unix shells is variable and command substitution using <code>${}</code> and <code>$()</code>, but as they are expanded in double quotes, this can lead to RCE and information disclosing bugs in complex scripts like bashbot. So it's more secure to escape or remove '$' in input from user, files or network.</p>
<p>A powerful tool to improve your scripts is <code>shellcheck</code>. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install shellcheck locally</a>. Shellcheck is used extensive in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a <a href="doc/7_develop.md">test suite</a> to check if important functionality is working as expected.</p>
<h3>Use printf whenever possible</h3>
@ -217,12 +217,12 @@ It features background tasks and interactive chats, and can serve as an interfac
<p><strong>Never run your Bot as root, this is the most dangerous you can do!</strong> Usually the user 'nobody' has almost no rights on unix/linux systems. See <a href="doc/4_expert.md">Expert use</a> on how to run your Bot as an other user.</p>
<h3>Secure your Bot installation</h3>
<p><strong>Your Bot configuration must no be readable from other users.</strong> Everyone who can read your Bots token is able to act as your Bot and has access to all chats the Bot is in!</p>
<p>Everyone with read access to your Bot files can extract your Bots data. Especially your Bot Token in <code>token</code> must be protected against other users. No one except you should have write access to the Bot files. The Bot should be restricted to have write access to <code>count</code> and <code>tmp-bot-bash</code> only, all other files must be write protected.</p>
<p>Everyone with read access to your Bot files can extract your Bots data. Especially your Bot config in <code>config.jssh</code> must be protected against other users. No one except you should have write access to the Bot files. The Bot should be restricted to have write access to <code>count.jssh</code> and <code>data-bot-bash</code> only, all other files must be write protected.</p>
<p>To set access rights for your bashbot installation to a reasonable default run <code>sudo ./bashbot.sh init</code> after every update or change to your installation directory.</p>
<h2>FAQ</h2>
<h3>Is this Bot insecure?</h3>
<p>Bashbot is not more (in)secure as any Bot written in an other language, we have done our best to make it as secure as possible. But YOU are responsible for the bot commands you wrote and you should know about the risks ...</p>
<p><strong>Note:</strong> Until v0.941 (mai/22/2020) telegram-bot-bash has a remote code execution bug, please update if you use an older version!</p>
<p><strong>Note:</strong> Up to version 0.941 (mai/22/2020) telegram-bot-bash had a remote code execution bug, please update if you use an older version!</p>
<h3>Why Bash and not the much better xyz?</h3>
<p>Well, that's a damn good question ... may be because I'm an unix admin from stone age. Nevertheless there are more reasons from my side:</p>
<ul>
@ -235,7 +235,7 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>At the beginning bashbot was simply the file <code>bashbot.sh</code> you can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more.</p>
<p>Hey no Problem, if you are finished with your cool bot run <code>dev/make-standalone.sh</code> to create a stripped down Version of your bot containing only 'bashbot.sh' and 'commands.sh'! For more information see <a href="doc/7_develop.md">Create a stripped down Version of your Bot</a></p>
<h3>Can I send messages from CLI and scripts?</h3>
<p>Of course, you can send messages from CLI and scripts, simply install bashbot as <a href="#Your-really-first-bashbot-in-a-nutshell">described here</a>, send the message '/start' to set yourself as botadmin and stop the bot with <code>./bashbot.sh kill</code>.</p>
<p>Of course, you can send messages from CLI and scripts, simply install bashbot as <a href="#Your-really-first-bashbot-in-a-nutshell">described here</a>, send the message '/start' to set yourself as botadmin and stop the bot with <code>./bashbot.sh stop</code>.</p>
<p>Run the following commands in your bash shell or script while you are in the installation directory:</p>
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb5-1" title="1"><span class="co"># prepare bash / script to send commands</span></a>
<a class="sourceLine" id="cb5-2" title="2"><span class="bu">export</span> <span class="va">BASHBOT_HOME=</span><span class="st">&quot;</span><span class="va">$(</span><span class="bu">pwd</span><span class="va">)</span><span class="st">&quot;</span></a>
@ -269,6 +269,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p>@Gnadelwartz</p>
<h2>That's it!</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$$ 0.99-0-g2775000</h4>
<h4>$$VERSION$$ 0.99-2-gacf9d84</h4>
</body>
</html>

View File

@ -129,7 +129,7 @@ Bash scripts in general are not designed to be bullet proof, so consider this Bo
Whenever you are processing input from untrusted sources (messages, files, network) you must be as careful as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everything. In addition delete unused scripts and examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable all not used commands.
**Note:** Until v0.941 (mai/22/2020) telegram-bot-bash had a remote code execution (RCE) bug, please update if you use an older version!
**Note:** Up to version v0.941 (mai/22/2020) telegram-bot-bash had a remote code execution (RCE) bug, please update if you use an older version!
see [Issue #125](https://github.com/topkecleon/telegram-bot-bash/issues/125)
One of the most powerful features of unix shells is variable and command substitution using ```${}``` and ```$()```,
@ -178,7 +178,7 @@ For the same reason every file your Bot can read is in danger to be disclosed. R
### Secure your Bot installation
**Your Bot configuration must no be readable from other users.** Everyone who can read your Bots token is able to act as your Bot and has access to all chats the Bot is in!
Everyone with read access to your Bot files can extract your Bots data. Especially your Bot Token in ```token``` must be protected against other users. No one except you should have write access to the Bot files. The Bot should be restricted to have write access to ```count``` and ```tmp-bot-bash``` only, all other files must be write protected.
Everyone with read access to your Bot files can extract your Bots data. Especially your Bot config in ```config.jssh``` must be protected against other users. No one except you should have write access to the Bot files. The Bot should be restricted to have write access to ```count.jssh``` and ```data-bot-bash``` only, all other files must be write protected.
To set access rights for your bashbot installation to a reasonable default run ```sudo ./bashbot.sh init``` after every update or change to your installation directory.
@ -187,7 +187,7 @@ To set access rights for your bashbot installation to a reasonable default run `
### Is this Bot insecure?
Bashbot is not more (in)secure as any Bot written in an other language, we have done our best to make it as secure as possible. But YOU are responsible for the bot commands you wrote and you should know about the risks ...
**Note:** Until v0.941 (mai/22/2020) telegram-bot-bash has a remote code execution bug, please update if you use an older version!
**Note:** Up to version 0.941 (mai/22/2020) telegram-bot-bash had a remote code execution bug, please update if you use an older version!
### Why Bash and not the much better xyz?
Well, that's a damn good question ... may be because I'm an unix admin from stone age. Nevertheless there are more reasons from my side:
@ -205,7 +205,7 @@ Hey no Problem, if you are finished with your cool bot run ```dev/make-standalon
### Can I send messages from CLI and scripts?
Of course, you can send messages from CLI and scripts, simply install bashbot as [described here](#Your-really-first-bashbot-in-a-nutshell),
send the message '/start' to set yourself as botadmin and stop the bot with ```./bashbot.sh kill```.
send the message '/start' to set yourself as botadmin and stop the bot with ```./bashbot.sh stop```.
Run the following commands in your bash shell or script while you are in the installation directory:
@ -261,4 +261,4 @@ bashbotBlockRecover() {
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-2-gacf9d84

View File

@ -170,8 +170,8 @@ globbing (set -f) and quote everything. In addition delete unused scripts and
examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable
all not used commands.
**Note:** Until v0.941 (mai/22/2020) telegram-bot-bash had a remote code
execution (RCE) bug, please update if you use an older version!
**Note:** Up to version v0.941 (mai/22/2020) telegram-bot-bash had a remote
code execution (RCE) bug, please update if you use an older version!
see [Issue #125](https://github.com/topkecleon/telegram-bot-bash/issues/125)
One of the most powerful features of unix shells is variable and command
@ -241,10 +241,10 @@ can read your Bots token is able to act as your Bot and has access to all chats
the Bot is in!
Everyone with read access to your Bot files can extract your Bots data.
Especially your Bot Token in ```token``` must be protected against other users.
No one except you should have write access to the Bot files. The Bot should be
restricted to have write access to ```count``` and ```tmp-bot-bash``` only,
all other files must be write protected.
Especially your Bot config in ```config.jssh``` must be protected against other
users. No one except you should have write access to the Bot files. The Bot
should be restricted to have write access to ```count.jssh``` and
```data-bot-bash``` only, all other files must be write protected.
To set access rights for your bashbot installation to a reasonable default run
```sudo ./bashbot.sh init``` after every update or change to your installation
@ -257,7 +257,7 @@ Bashbot is not more (in)secure as any Bot written in an other language, we have
done our best to make it as secure as possible. But YOU are responsible for the
bot commands you wrote and you should know about the risks ...
**Note:** Until v0.941 (mai/22/2020) telegram-bot-bash has a remote code
**Note:** Up to version 0.941 (mai/22/2020) telegram-bot-bash had a remote code
execution bug, please update if you use an older version!
### Why Bash and not the much better xyz?
@ -286,7 +286,7 @@ down Version of your Bot](doc/7_develop.md)
Of course, you can send messages from CLI and scripts, simply install bashbot
as [described here](#Your-really-first-bashbot-in-a-nutshell),
send the message '/start' to set yourself as botadmin and stop the bot with
```./bashbot.sh kill```.
```./bashbot.sh stop```.
Run the following commands in your bash shell or script while you are in the
installation directory:
@ -351,4 +351,4 @@ wait
If you feel that there's something missing or if you found a bug, feel free to
submit a pull request!
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-2-gacf9d84

View File

@ -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-10-gb9c8dc0
#
# 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}"
}
@ -110,7 +109,7 @@ fi
BOTCOMMANDS="start, stop, status, help, init, stats, broadcast, suspendback, resumeback, killback"
[[ -z "$1" && -z "${SOURCE}" ]] && echo -e "${ORANGE}Available commands: ${GREY}${BOTCOMMANDS}${NC}" && exit
if [ "$1" = "help" ]; then
HELP="README"
HELP="${BASHBOT_HOME:-.}/README"
if [ -n "${CLEAR}" ];then
_exists w3m && w3m "$HELP.html" && exit
_exists lynx && lynx "$HELP.html" && exit
@ -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
@ -874,7 +873,7 @@ process_message() {
LEFTMEBER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","left_chat_member","username"]}")"
LEFTMEMBER[ISBOT]="${UPD["result",${num},"message","left_chat_member","is_bot"]}"
[ -z "${MESSAGE[0]}" ] &&\
MESSAGE[0]="/_left_chat_member ${NEWMEMBER[ID]} ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
MESSAGE[0]="/_left_chat_member ${LEFTMEMBER[ID]} ${LEFTMEMBER[USERNAME]:=${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]}}"
fi
if grep -qs -e '\["result",'"${num}"',"message","new_chat_[tp]' <<<"${UPDATE}"; then
SERVICE[NEWTITLE]="$(JsonDecode "${UPD["result",${num},"message","new_chat_title"]}")"
@ -937,8 +936,10 @@ start_bot() {
# cleanup countfile on startup
jssh_deleteKeyDB "CLEAN_COUNTER_DATABASE_ON_STARTUP" "${COUNTFILE}"
[ -f "${COUNTFILE}.jssh.flock" ] && rm -f "${COUNTFILE}.jssh.flock"
jssh_deleteKeyDB "CLEAN_BOT_BOTCONFIG_ON_STARTUP" "${BOTCONFIG}"
# store start time and cleanup botconfig on startup
jssh_updateKeyDB "startup" "$(date)" "${BOTCONFIG}"
[ -f "${BOTCONFIG}.jssh.flock" ] && rm -f "${BOTCONFIG}.jssh.flock"
# read blocked users
jssh_readDB_async "BASHBOTBLOCKED" "${BLOCKEDFILE}"
# inform botadmin about start
ADMIN="$(getConfigKey "botadmin")"

View File

@ -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

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
# this has to run once atfer git clone
# and every time we create new hooks
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-8-g6011444
# magic to ensure that we're always inside the root of our application,
# no matter from which directory we'll run script
@ -45,12 +45,12 @@ done
if [ "$fail" -eq 0 ]; then
/bin/echo -n 'SUCCESS '
exitcode=0
#rm -rf "${TESTENV}"
rm -rf "${TESTENV}"
else
/bin/echo -n 'FAILURE '
exitcode=1
#rm -rf "${TESTENV}/test"
#find "${TESTENV}/"* ! -name '[a-z]-*' -delete
rm -rf "${TESTENV}/test"
find "${TESTENV}/"* ! -name '[a-z]-*' -delete
fi
echo -e "${passed} / ${tests}\\n"

View File

@ -1,5 +1,5 @@
#!/usr/bin/env bash
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-13-g6a6410e
############
# NOTE: you MUST run install-hooks.sh again when updating this file!
@ -68,9 +68,9 @@ fi
if which codespell &>/dev/null; then
echo "Running codespell"
echo "............................"
codespell -B 1 --skip="*.log,*.html,*.txt,.git*" -L "ba"
codespell -B 1 --skip="*.log,*.html,*.txt,.git*,jsonDB-keyboard" -L "ba"
echo "if there are (to many) typo's shown, consider running:"
echo "codespell -i 3 -w --skip=\"*.log,*.html,*.txt,.git*\" -L \"ba\""
echo "codespell -i 3 -w --skip=\"*.log,*.html,*.txt,.git*,examples\" -L \"ba\""
else
echo "consider installing codespell: pip install codespell"
fi

View File

@ -9,8 +9,8 @@ outfile="./bashbot.obf.sh"
{
echo '#!/bin/bash'
echo 'b="./bashbot";h="$PWD";cd "$(mktemp -d)"||exit'
echo 'printf '"'%s\n'"' '"'$(gzip -9 <bashbot.sh | base64)'"'|base64 -d|gunzip >"$b";export BASHBOT_HOME="$h";chmod +x "$b";"$b" "$@";b="$(pwd)";cd ..;rm -rf "$b"'
echo 'a="$PWD";cd "$(mktemp -d)"||exit'
echo 'printf '"'%s\n'"' '"'$(gzip -9 <bashbot.sh | base64)'"'|base64 -d|gunzip >a;export BASHBOT_HOME="$a";chmod +x a;./a "$@";a="$PWD";cd ..;rm -rf "$a"'
} >"${outfile}"
chmod +x "${outfile}"

View File

@ -3,7 +3,7 @@
The Bots standard commands are in the commands dispatcher ```commands.sh```, Do not edit this file! Add your commands and functions to ```mycommands.sh```. In 'mycommands.sh.dist' you find examples how to add own commands and overwrite existing ones. See [Best practices](5_practice.md) for more information.
Once you're done with editing start the Bot with ```./bashbot.sh start```. To stop the Bot run ```./bashbot.sh kill```
Once you're done with editing start the Bot with ```./bashbot.sh start```. To stop the Bot run ```./bashbot.sh stop```
If something doesn't work as expected, debug with ```./bashbot.sh startbot DEBUG &```, where DEBUG can be 'debug', 'xdebug' or 'xdebugx'.
See [Bashbot Development](7_develop.md) for more information.
@ -283,5 +283,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-1-g3daf84d

View File

@ -136,29 +136,27 @@ If you have sourced 'bashbot.sh' you have the following bashot internal variable
```bash
COMMANDS # default: ./commands.sh"
MODULEDIR # default: ./modules"
TOKENFILE # default: ./token"
BOTADMIN # default: ./botadmin"
BOTACL # default: ./botacl"
TMPDIR # default: ./data-bot-bash"
COUNTFILE # default: ./count"
COUNTFILE # default: ./count" (jsonDB file)
BOTTOKEN # default: content of ${TOKENFILE}
BOTTOKEN # your token read from bot config
URL # telegram api URL - default: https://api.telegram.org/bot${BOTTOKEN}"
```
#### Interactive use
For testing your setup or sending messages yoursel you can use bashbot functions from bash command line:
For testing your setup or sending messages yourself its possible to use bashbot functions from command line:
```bash
# are we running bash?
echo $SHELL
/bin/bash
# source bashbot.sh WITHOUT BASHBOT_HOME set
./bashbot.sh source
source ./bashbot.sh source
# output bashbot internal variables
echo $COMMANDS $MODULEDIR $TOKENFILE $BOTADMIN $BOTACL $TMPDIR $COUNTFILE
./commands.sh ./modules ./token ./botadmin ./botacl ./data-bot-bash ./count
echo $COMMANDS $MODULEDIR $BOTACL $TMPDIR $COUNTFILE
./commands.sh ./modules ./botacl ./data-bot-bash ./count
# source bashbot.sh WITH BASHBOT_HOME set
@ -166,9 +164,9 @@ export BASHBOT_HOME=/usr/local/telegram-bot-bash
source ./bashbot.sh source
# output bashbot internal variables
echo $COMMANDS $MODULEDIR $TOKENFILE $BOTADMIN $BOTACL $TMPDIR $COUNTFILE
/usr/local/telegram-bot-bash/commands.sh /usr/local/telegram-bot-bash/modules /usr/local/telegram-bot-bash/token
/usr/local/telegram-bot-bash/botadmin /usr/local/telegram-bot-bash/botacl /usr/local/telegram-bot-bash/data-bot-bash
echo $COMMANDS $MODULEDIR $BOTACL $TMPDIR $COUNTFILE
/usr/local/telegram-bot-bash/commands.sh /usr/local/telegram-bot-bash/modules
/usr/local/telegram-bot-bash/botacl /usr/local/telegram-bot-bash/data-bot-bash
/usr/local/telegram-bot-bash/count
```
@ -178,24 +176,24 @@ User or Chat you are in. See [Send Messages](2_usage.md#sending-messages).
*Examples:* You can test this by sending messages to yourself:
```bash
# fist Hello World
send_normal_message "$(< $BOTADMIN)" "Hello World! This is my first message"
send_normal_message "$(getConfigKey "botadmin")" "Hello World! This is my first message"
# now with some markdown and HTML
send_markdown_message "$(< $BOTADMIN)" '*Hello World!* _This is my first markdown message_'
send_html_message "$(< $BOTADMIN)" '<b>Hello World!</b> <em>This is my first HTML message</em>'
send_keyboard "$(< $BOTADMIN)" 'Do you like it?' '[ "Yep" , "No" ]'
send_markdown_message "$(getConfigKey "botadmin")" '*Hello World!* _This is my first markdown message_'
send_html_message "$(getConfigKey "botadmin")" '<b>Hello World!</b> <em>This is my first HTML message</em>'
send_keyboard "$(getConfigKey "botadmin")" 'Do you like it?' '[ "Yep" , "No" ]'
```
Now something more useful ...
```bash
# sending output from system commands:
send_normal_message "$(< $BOTADMIN)" "$(date)"
send_normal_message "$(getConfigKey "botadmin")" "$(date)"
send_normal_message "$(< $BOTADMIN)" "$(uptime)"
send_normal_message "$(getConfigKey "botadmin")" "$(uptime)"
send_normal_message "$(< $BOTADMIN)" '`'$(free)'`'
send_normal_message "$(getConfigKey "botadmin")" '`'$(free)'`'
# same but markdown style 'code' (monospaced)
send_markdown_message "$(< $BOTADMIN)" "\`$(free)\`"
send_markdown_message "$(getConfigKey "botadmin")" "\`$(free)\`"
```
@ -211,7 +209,7 @@ If you want to have other locations for config, data etc, define and export the
**Note: all specified directories and files must exist or running 'bashbot.sh' will fail.**
##### BASHBOT_ETC
Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```botadmin```, ```botacl``` ...
Location of the files ```commands.sh```, ```mycommands.sh```, ```botconfig.jssh```, ```botacl``` ...
```bash
unset BASHBOT_ETC # keep in telegram-bot-bash (default)
export BASHBOT_ETC "" # keep in telegram-bot-bash
@ -225,7 +223,7 @@ Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```bo
e.g. /etc/bashbot
##### BASHBOT_VAR
Location of runtime data ```data-bot-bash```, ```count```
Location of runtime data ```data-bot-bash```, ```count.jssh```
```bash
unset BASHBOT_VAR # keep in telegram-bot-bash (default)
export BASHBOT_VAR "" # keep in telegram-bot-bash
@ -338,7 +336,6 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
```
#### Tested configs as of v0.90 release
**Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.**
##### simple Unix like config, for one bot. bashbot is installed in '/usr/local/telegram-bot-bash'
```bash
@ -381,5 +378,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
#### [Prev Advanced Use](3_advanced.md)
#### [Next Best Practice](5_practice.md)
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-1-g3daf84d

View File

@ -10,7 +10,9 @@ In addition you should know about [BotFather, the one bot to rule them all](http
If you don't have a github account, it may time to [setup a free account now](https://github.com/pricing)
### Add commands to mycommands.sh only
To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function:
Do not change ```bashbot.sh``` and ```commands.sh```, instead place your commands in to ```mycommands.sh```.
To start with a clean/minimal bot copy ```mycommands.sh.clean``` to ```mycommands.sh``` and start editing
the message strings and place commands in the```case ... esac``` block of the function mycommands():
```bash
# file: mycommands.sh
# your additional bahsbot commands
@ -35,33 +37,37 @@ mycommands() {
}
```
### Overwrite, extend and disable global commands
### DIsable, replace and extend global commands
You can overwrite a global bashbot command by placing the same commands in ```mycommands.sh``` and add ```return 1```
ad the end of your command, see '/kickme' below.
Global bashbot command processing, e.g. /start, /info etc. is disabled if you return a non zero value from ```mycommands.sh```,
see /start example below.
To disable a global bashbot command place create a command simply containing 'return 1', see '/leave' below.
To replace a global bashbot command add the same command to ```mycommands.sh``` and place ```return 1``` at the end of
the case block, see /kickme example below.
In case you want to add some processing to the global bashbot command add ```return 0```, then both command will be executed.
If a command is available as a global command and in ```mycommands.sh```, plus you return a zero value (nothing or 0)
both command sections are processed. Thus you can extend global commands with additional actions, see /info example below
**Learn more about [Bot commands](https://core.telegram.org/bots#commands).**
```bash
# file: commands.sh
# file: mycommands.sh
case "$MESSAGE" in
##########
# command overwrite examples
'info'*) # output date in front of regular info
send_normal_message "${CHAT[ID]}" "$(date)"
return 0
# disable start command
'/start'*) # disable all commands starting with leave
return 1
;;
# replace command with your own actions
'/kickme'*) # this will replace the /kickme command
send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*"
return 1
;;
'/leave'*) # disable all commands starting with leave
return 1
# extend global command
'/info'*) # output date in front of regular info
send_normal_message "${CHAT[ID]}" "$(date)"
return 0
;;
esac
```
@ -152,5 +158,5 @@ The second warning is about an unused variable, this is true because in our exam
#### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-1-g3daf84d

View File

@ -133,7 +133,10 @@ send_album "$(getConfigKey "botadmin")" "http://www.rrr.de/slider/main-image1.jp
----
##### send_keyboard
Note: since version 0.6 send_keyboard was changed to use native "JSON Array" notation as used from Telegram. Example Keyboard Array definitions:
Note: Since version 0.6 send_keyboard was changed to use native "JSON Array" notation as used from Telegram.
Detection and emulation for old format will be removed after 1.0 release!
Example Keyboard Array definitions:
- yes no in two rows:
- OLD format: 'yes' 'no' (two strings)
@ -1046,5 +1049,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca
#### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-17-g9d7f145

View File

@ -51,10 +51,11 @@ convert existing bots.
/ifconfig *ifconfig output*
/smart *sda* _smart status for sda drive_
```
### External scripts
### jsonDB and Keyboards
**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users.
**jsonDB-keybords** contains a stripped down real world example from my bot showing the usage of jsonDB to store and retrieve values
plus use of keyboards in private chats. It's an extended version of mycommands.sh.dist. Messages and help are in german.
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-13-g6a6410e

View File

@ -0,0 +1,717 @@
#!/bin/bash
# files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ...
#
#### $$VERSION$$ 0.99-16-gd6de66d
#
# shellcheck disable=SC2154
# shellcheck disable=SC2034
# within *xxx* markup we need only one \ to escape a '_', e.g. my\_stupid\_bot (stupid V1 markup)
bashbot_title='*Hallo, ich bin der @'"${ME//_/\\_}"'. Ich suche und finde Dealz!*'
# outside *xxxx* markup we need two \\ to escape a '_', e.g. -> my\\_stupid\\_bot
bashbot_shelp="${bashbot_title}"'
Schicke mir hier -> @'"${ME//_/\\\\_}"' <- einen Befehl mit *max. 50 Begriffen*. Ein Begriff muss mindesten 4 Zeichen lang sein.
*Befehle zum Suchen / Tracken von Dealz:*
/search /suche _Suche in Deals der letzen 48h,
z.B.:_ /suche Apple mavic.\*air
/newtrack _Tracking mit neuen Begriffen,
z.B.:_ /newtrack Apple mavic.\*air
/track /addkey _zusätzlicher Begriff zum Tracken_
/addblack _Begriff darf nicht vorkommen_
/delkey _lösche Begriff_
/delblack _lösche Blacklist Begriff_
/listtrack _zeigt aktuell getrackte Begriffe_
/delkey ALL _löscht alle Begriffe_
/stattrack _Infos zum aktiven Tracking_
Kurzform: /such /sea /newt /tra /addk /addb /delk /delb /lst /statt
*Platzhalter in Suchbegriffen:*
*.*\* = egal/alles: 1tb*.*\*ssd
⇨ 1Tb-ssd, 1tb ssd, 1Tb Supi ssd
*.* = genau ein Zeichen: *.*tb
⇨ 1Tb, 5TB, atb, ztb
*_* = Wortanfang/end: \\_Mavic\\_
⇨ das Wort _Mavic_
Die Suche ignoriert Gross und Klein Schreibung, Satzzeichen, Klammern und "-", ebenso Links und Bilder. Mehr zu Regular Expressions (RegEx) http://www.regexe.de/hilfe.jsp
'
bashbot_whelp="${bashbot_title}"'
Schicke mir hier -> @'"${ME//_/\\\\_}"' <- einen Befehl mit *max. 50 Artikeln (ASIN)* zum Beobachten.
*Befehle zum Beobachten von Amzon Artikeln*
/newwatch _Beobachten neuer Artikel_
z.B.:_ /newwatch ASIN ASIN_
/watch /addwatch _weiteren Artikel beobachten_
/delwatch _löscht Artikel aus Beobachtung_
/listwatch _zeigt aktuell beobachtete Artikel_
/delwatch ALL _löscht alle Artikel_
/notify _einmalig warten bis Verfügar_
/listnotify _zeigt aktuell wartende Artikel_
/delnotify _löscht alle wartenden Artikel_
Kurzform: /neww /wat /addw /delw /listw /noti /listn /deln
'
bashbot_examples="${bashbot_title}"'
'
bashbot_group='*#MD Amazon Deutschland only Deals*
https://t.me/joinchat/IvvRtlEPhZKmWVVc8iTD2g
*#MD Zuhause, Family & Kids und Empfehlungen*
https://t.me/joinchat/IvvRtlT4f8HuwFDiJDCWoQ '
bashbot_all="${bashbot_title}"'
---------------------------------------------------------------------
'"${bashbot_group}"'
*#DL Amazon International*
https://t.me/joinchat/IvvRtkzPaMTHFZi3CjSX8g
*#MD Amazon Warehouse Schnäppchen *
https://t.me/joinchat/IvvRthRhj5NVkcihTxDZwQ
----------------------------------------------------------------------
Was hier kommt, kommt nur hier!
*#MD Kleidung, Accessoirs & Empfehlungen*
https://t.me/joinchat/IvvRthlJ8zwC7tHyhl63Fg
*#MD Mobilfunk & Smartphones*
https://t.me/joinchat/IvvRthtqth9Svyyvnb5lAQ
*#MD Gaming, Spiele & Konsolen*
https://t.me/joinchat/IvvRthRyrsmIyMFMc7189Q
---------------------------------------------------------------------
*#MD extrem - All Dealz über 100°*
https://t.me/joinchat/IvvRtk6ehHS4ZZmtoRFU2g
*#MD Offtopic: Diskussion & Ankündigungen*
https://t.me/joinchat/IvvRthRhMcX6rDQU-pZrWw
*Du willst Dealz suchen oder abbonieren?*
Klicke hier -> @'"${ME//_/\\\\_}"' <- und schicke /start
.
'
# uncomment the following lines to overwrite info and help messages
bashbot_info="${bashbot_title}"'
'"${bashbot_group}"'
*#MD Offtopic: Diskussion & Ankündigungen*
Hier kannst Du dich austauschen und erfährst Neues.
https://t.me/joinchat/IvvRthRhMcX6rDQU-pZrWw
*Du willst Dealz suchen oder tracken?*
Klicke hier -> @'"${ME//_/\\\\_}"' <- und schicke /start
*Meine Befehle*:
/suche _- Suchen und Tracken von Dealz_
/watch _- Beobachten von Amazon Artikeln_
/gruppen _- Liste aller Dealz Gruppen_
/hilfe _- Hilfe zu weiteren Befehlen_
*Dein '"${ME//_/-}"'*
https://dealz.rrr.de/amzdealz.html
'
bashbot_help="${bashbot_title}"'
Du hast eine eigene Telegram Dealgruppe? Lade mich ein und all in der Guppe können mich nutzen:
*verfügbare Befehle*:
/suche _- Suchen und Tracken von Dealz_
/watch _- Beobachten von Amazon Artikeln_
/gruppen _- Liste aller Dealz Gruppen_
/info _- Info zum Bot_
/help _- Zeigt diese Liste_
_https://dealz.rrr.de/assets/images/rdealomat.gif_
'
# in a regular message is no need to escape '_'
SORRYADMIN="Du bist kein Gruppenadmin, diesen Befehl kannst Du nur im privaten Chat ausführen @${ME} <<- hier klicken"
SORRYADMIN2="Dieser Befehl ist dem Botadmin vorbehalten, sorry."
# Set INLINE to 1 in order to receive inline queries.
# To enable this option in your bot, send the /setinline command to @BotFather.
INLINE=""
# Set to .* to allow sending files from all locations
FILE_REGEX='/home/deal-O-mat/.*'
# run curl over TOR or SOCKS
#export BASHBOT_CURL_ARGS="--socks5-hostname localhost"
# unset BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# see logs/ERROR.log for information why send_messages etc. fail
unset BOTSEND_RETRY
# set value for adaptive sleeping while waitingnfor uodates in millisconds
# max slepp between polling updates 10s (default 5s)
export BASHBOT_SLEEP="10000"
# add 0.2s if no update available, up to BASHBOT_SLEEP (default 0.1s)
export BASHBOT_SLEEP_STEP="400"
# uncomment if you use keyboards in your commands
# export REMOVEKEYBOARD="yes"
export REMOVEKEYBOARD_PRIVATE="yes"
# uncomment if you want to say welcome to new chat members
export WELCOME_NEWMEMBER="yes"
WELCOME_MSG="Willkommen"
# uncomment if you want to be informed about new/left chat members
export REPORT_NEWMEMBER="yes"
export REPORT_LEFTMEMBER="yes"
export REMINDER="Del-O-Mat: https://dealz.rrr.de/amzdealz.html\n https://dealz.rrr.de/ebaydealz.html"
TRACKFILE="${DATADIR}/0-dealtrack"
SEARCHFILE="${DATADIR}/0-dealsearch"
WATCHFILE="${DATADIR}/0-dealwatch"
NOTIFYFILE="${DATADIR}/0-dealnotify"
if [ "$1" = "startbot" ];then
# run once after startup when the first message is received
my_startup(){
# send reminder on startup, random delay
send_normal_message "-10011894xxxxx" "${REMINDER}"
}
setConfigKey "startupaction" "await"
# create KEYOFILE DB if not exist
jssh_newDB "${TRACKFILE}"
jssh_newDB "${SEARCHFILE}"
jssh_newDB "${WATCHFILE}"
jssh_newDB "${NOTIFYFILE}"
else
# things to do only at source, eg. after startup
if [[ "$(getConfigKey "startupaction")" != "done"* ]]; then
setConfigKey "startupaction" "done $(date)"
my_startup
fi
# your additional bahsbot commands
# NOTE: command can have @botname attached, you must add * in case tests...
mycommands() {
# a service Message was received
local SILENCER="yes"
if [[ "${SERVICE}" != "" ]]; then
# example: dleted service messages
if [ "${SILENCER}" = "yes" ]; then
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
fi
fi
# remove keyboard if you use keyboards
[ -n "${REMOVEKEYBOARD}" ] && remove_keyboard "${CHAT[ID]}" "..." &
[[ -n "${REMOVEKEYBOARD_PRIVATE}" && "${CHAT[ID]}" == "${USER[ID]}" ]] && remove_keyboard "${CHAT[ID]}" "..." &
######################
# default commands
# fix upper case first letter in commands
[[ "${MESSAGE}" =~ ^/[[:upper:]] ]] && MESSAGE="${MESSAGE:0:1}$(tr '[:upper:]' '[:lower:]' <<<"${MESSAGE:1:1}")${MESSAGE:2}"
case "${MESSAGE}" in
'/info'*)
send_action "${CHAT[ID]}" "typing"
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
return 0 # continue with default action
;;
'/hel'*|'/hil'*)
send_action "${CHAT[ID]}" "typing"
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
return 1 # break, do not continue
;;
'/start'*)
send_markdown_message "${CHAT[ID]}" "${bashbot_info}"
return 1 # break, do not continue
;;
'/gr'*) # list groups
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
send_action "${CHAT[ID]}" "typing"
send_markdown_message "${CHAT[ID]}" "${bashbot_all}"
return
;;
#'/test'*)
# send_normal_message "${CHAT[ID]}" "Start interactive"
# send_markdown_message "${CHAT[ID]}" "TEST: äöüß!^°_-\"-,§$%&/(){}#@?[]{}._"
# return
# ;;
# will we process edited messages also?
'/_edited_message'*)
#return 1 # no
# but if we do, remove /edited_message
MESSAGE="${MESSAGE#/* }"
;;
'/_new_chat_member'*)
if [[ -n "${WELCOME_NEWMEMBER}" && "${NEWMEMBER[ISBOT]}" != "true" ]]; then
send_normal_message "${CHAT[ID]}"\
"${WELCOME_MSG} ${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]} (@${NEWMEMBER[USERNAME]})"
MYSENTID="${BOTSENT[ID]}"
{ sleep 5; delete_message "${CHAT[ID]}" "${MYSENTID}"; } &
fi
[ -n "${REPORT_NEWMEMBER}" ] && send_normal_message "$(getConfigKey "botadmin")"\
"New member: ${CHAT[TITLE]} (${CHAT[ID]}): ${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]} (@${NEWMEMBER[USERNAME]})"
;;
'/_left_chat_member'*)
[ -n "${REPORT_LEFTMEMBER}" ] && send_normal_message "$(getConfigKey "botadmin")"\
"Left member: ${CHAT[TITLE]} (${CHAT[ID]}): ${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]} (@${LEFTMEMBER[USERNAME]})"
;;
esac
##########
# pre test for admin only commands
case "${MESSAGE}" in
# must be in private chat, group admin, or botadmin
'/sea'*|'/su'*|'/add'*|'/new'*|'/del'*|'/tra'*|'/wat'*|'/noti'*|'/lista'*)
send_action "${CHAT[ID]}" "typing"
if ! user_is_admin "${CHAT[ID]}" "${USER[ID]}" ; then
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
send_normal_message "${CHAT[ID]}" "${SORRYADMIN}"
MYSENTID="${BOTSENT[ID]}"
{ sleep 5; delete_message "${CHAT[ID]}" "${MYSENTID}"; } &
return 1
fi
;;&
# must be botadmin
'/delu'*)
if ! user_is_botadmin "${USER[ID]}" ; then
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
send_markdown_message "${CHAT[ID]}" "*${SORRYADMIN2}*";
MYSENTID="${BOTSENT[ID]}"
{ sleep 5; delete_message "${CHAT[ID]}" "${MYSENTID}"; } &
return 1
fi
;;
esac
#################
# search commands
local FINDKEYS OLDKEYS KEY MYSENTID
declare -a KEYARR
declare -A SEARCHVALUES
#################
# pre processing of search commands
case "${MESSAGE}" in
'/add'*|'/tra'*|'/noti'*) # add no arg
FINDKEYS="${MESSAGE#/* }"
if [ "${FINDKEYS}" = "${MESSAGE}" ]; then
send_normal_message "${CHAT[ID]}" "Kein Begriff angegeben!"
exit
fi
;;&
'/addw'*|'/wat'*) OLDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${WATCHFILE}")"
;;&
'/add'[kbt]*|'/tra'*) OLDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${TRACKFILE}")"
;;&
'/noti'*) OLDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${NOTIFYFILE}")"
;;&
'/addk'*|'/addt'*|'/tra'*) # add track
MESSAGE="/newtrack ${FINDKEYS} ${OLDKEYS}"
;;
'/addb'*) # add black
[[ "${OLDKEYS}" != *'!'* ]] && FINDKEYS="!${FINDKEYS}"
MESSAGE="/newtrack ${OLDKEYS} ${FINDKEYS}"
;;
'/addw'*|'/wat'*) # add watch
FINDKEYS="${MESSAGE#/* }"
if [ "${FINDKEYS}" = "${MESSAGE}" ]; then
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
send_markdown_message "${CHAT[ID]}" "${bashbot_whelp}"
return
fi
MESSAGE="/newwatch ${FINDKEYS} ${OLDKEYS}"
;;
'/noti'*) # add watch
MESSAGE="/newnotify ${FINDKEYS} ${OLDKEYS}"
;;
'/delk'*|'/delb'*) # no user search
OLDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${TRACKFILE}")"
if [ "${OLDKEYS}" = "" ]; then
send_markdown_message "${CHAT[ID]}" "*Kein Tracking aktiv!*"
return
fi
;;&
'/delw'*) # no watch
OLDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${WATCHFILE}")"
if [ "${OLDKEYS}" = "" ]; then
send_markdown_message "${CHAT[ID]}" "*Kein Product Watch aktiv!*"
return
fi
;;&
'/deln'*) # no notify
OLDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${NOTIFYFILE}")"
if [ "${OLDKEYS}" = "" ]; then
send_markdown_message "${CHAT[ID]}" "*Kein Product Notify aktiv!*"
return
fi
jssh_deleteKeyDB "${CHAT[ID]}" "${NOTIFYFILE}"
send_normal_message "${CHAT[ID]}" "Product Notify \"${OLDKEYS}\" gelöscht!"
;;
'/delk'*) #delete key
KEY="${OLDKEYS%%|!*}"
FINDKEYS="${MESSAGE#/* }"
read -r -a KEYARR <<<"ALL ${KEY//|/ }"
if [ "${FINDKEYS}" = "ALL" ]; then
jssh_deleteKeyDB "${CHAT[ID]}" "${TRACKFILE}"
send_markdown_message "${CHAT[ID]}" "*Tracking gelöscht!*"
return
elif [[ "${FINDKEYS}" =~ ^[0-9]+$ ]]; then
if [ "${#KEYARR[@]}" -lt "${FINDKEYS}" ]; then
send_normal_message "${CHAT[ID]}" "Es gibt nur $((${#KEYARR[@]}-1)) Keys, bitte nochmal."
unset FINDKEYS
else
send_normal_message "${CHAT[ID]}" "Lösche Key ${KEYARR[${FINDKEYS}]}"
unset "KEYARR[0]"
unset "KEYARR[${FINDKEYS}]"
FINDKEYS="${KEYARR[*]}"
if [ -z "${FINDKEYS}" ]; then
jssh_deleteKeyDB "${CHAT[ID]}" "${TRACKFILE}"
send_markdown_message "${CHAT[ID]}" "*Tracking gelöscht!*"
return
else
KEY="${OLDKEYS#*!}"
[ "${KEY}" != "${OLDKEYS}" ] && FINDKEYS+="|!${KEY}"
MESSAGE="/newt ${FINDKEYS}"
fi
fi
else
OUT="Keys:\n$(printKeys "KEYARR")\n\nSchicke \"/delkey <Nr.>\" zum Löschen."
if [ "${CHAT[ID]}" != "${USER[ID]}" ]; then
send_normal_message "${CHAT[ID]}" "${OUT}"
else
send_keyboard "${CHAT[ID]}" "${OUT}"\
'["/delkey 1","/delkey 2","/delkey 3"],["/delkey 4","/delkey 5","/delkey 6"],["/delkey 7","/delkey 8","/delkey 9"],["/delkey ALL","/delblack","/listtrack"]'
fi
fi
;;
'/delb'*) #delete black
KEY="${OLDKEYS#*!}"
read -r -a KEYARR <<<"ALL ${KEY//|/ }"
FINDKEYS="${MESSAGE#/* }"
if [ "${KEY}" = "${OLDKEYS}" ]; then
unset FINDKEYS
unset KEYARR
KEYARR[0]="Keine Blacklist"
fi
if [[ "${FINDKEYS}" =~ ^[0-9]+$ ]]; then
if [ "${#KEYARR[@]}" -lt "${FINDKEYS}" ]; then
send_normal_message "${CHAT[ID]}" "Es gibt nur $((${#KEYARR[@]}-1)) Keys, bitte nochmal."
unset "KEYARR[${FINDKEYS}]"
else
send_normal_message "${CHAT[ID]}" "Lösche Black ${KEYARR[${FINDKEYS}]}"
unset "KEYARR[0]"
unset "KEYARR[${FINDKEYS}]"
FINDKEYS="|!${KEYARR[*]}"
[ "${FINDKEYS}" == "|!" ] && FINDKEYS=""
MESSAGE="/newt ${OLDKEYS%%|!*}${FINDKEYS}"
fi
fi
if [[ -z "${FINDKEYS}" || "${FINDKEYS:0:1}" == "/" ]]; then # output list
OUT="Blacklist:\n$(printKeys "KEYARR")\n\nSchicke \"/delblack <Nr.>\" zum Löschen."
if [ "${CHAT[ID]}" != "${USER[ID]}" ]; then
send_normal_message "${CHAT[ID]}" "${OUT}"
else
send_keyboard "${CHAT[ID]}" "${OUT}"\
'["/delblack 1","/delblack 2","/delblack 3"],["/delblack 4","/delblack 5","/delblack 6"],["/delblack 7","/delblack 8","/delblack 9"],["/delblack ALL","/delkey","/listtrack"]'
fi
fi
;;
'/delw'*) #delete watch
KEY="${OLDKEYS}"
FINDKEYS="${MESSAGE#/* }"
read -r -a KEYARR <<<"ALL ${KEY//|/ }"
if [ "${FINDKEYS}" = "ALL" ]; then
jssh_deleteKeyDB "${CHAT[ID]}" "${WATCHFILE}"
send_markdown_message "${CHAT[ID]}" "*Produkt Watch gelöscht!*"
return
elif [[ "${FINDKEYS}" =~ ^[0-9]+$ ]]; then
if [ "${#KEYARR[@]}" -lt "${FINDKEYS}" ]; then
send_normal_message "${CHAT[ID]}" "Es gibt nur $((${#KEYARR[@]}-1)) Keys, bitte nochmal."
unset FINDKEYS
else
send_normal_message "${CHAT[ID]}" "Lösche Key ${KEYARR[${FINDKEYS}]}"
unset "KEYARR[0]"
unset "KEYARR[${FINDKEYS}]"
FINDKEYS="${KEYARR[*]}"
if [ -z "${FINDKEYS}" ]; then
jssh_deleteKeyDB "${CHAT[ID]}" "${WATCHFILE}"
send_markdown_message "${CHAT[ID]}" "*Produkt Watch gelöscht!*"
return
else
MESSAGE="/neww ${FINDKEYS}"
fi
fi
else
OUT="Keys:\n$(printKeys "KEYARR")\n\nSchicke \"/delwatch <Nr.>\" zum Löschen."
if [ "${CHAT[ID]}" != "${USER[ID]}" ]; then
send_normal_message "${CHAT[ID]}" "${OUT}"
else
send_keyboard "${CHAT[ID]}" "${OUT}"\
'["/delwatch 1","/delwatch 2","/delwatch 3"],["/delwatch 4","/delwatch 5","/delwatch 6"],["/delwatch 7","/delwatch 8","/delwatch 9"],["/delwatch ALL","/listwatch"]'
fi
fi
;;
esac
case "${MESSAGE}" in
#######################
# deal search commands
'/such'*|'/sea'*) # suche
FINDKEYS="${MESSAGE#/* }"
if [ "${FINDKEYS}" = "${MESSAGE}" ]; then
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
send_markdown_message "${CHAT[ID]}" "${bashbot_shelp}"
else
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" ; then
set_keys "${FINDKEYS}" "${SEARCHFILE}"
else
send_normal_message "${CHAT[ID]}" "${SORRYADMIN}"
MYSENTID="${BOTSENT[ID]}"
{ sleep 5; delete_message "${CHAT[ID]}" "${MYSENTID}"; } &
return 1
fi
fi
return
;;
'/newt'*) # newtrack
FINDKEYS="${MESSAGE#/* }"
FINDKEYS="${FINDKEYS%[\" ]}"
FINDKEYS="${FINDKEYS#[\" ]}"
if [ "${FINDKEYS}" = "${MESSAGE}" ]; then
send_markdown_message "${CHAT[ID]}" "${bashbot_shelp}"
else
set_keys "${FINDKEYS}" "${TRACKFILE}"
fi
;&
'/lst'*|'/listt'*) # listtrack
send_action "${CHAT[ID]}" "typing"
FINDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${TRACKFILE}")"
if [ "${FINDKEYS}" = "" ]; then
send_markdown_message "${CHAT[ID]}" "*Kein Tracking aktiv!*"
return
fi
OUT="Tracking nach \"${FINDKEYS}\" ist aktiv."
if [[ "${CHAT[ID]}" != "${USER[ID]}" ]]; then
send_normal_message "${CHAT[ID]}" "${OUT}"
else
send_keyboard "${CHAT[ID]}" "${OUT}"\
'["/delkey 1","/delkey 2","/delkey 3"],["/delkey 4","/delkey 5","/delblack 6"],["/delblack 1","/delblack 2","/delblack 3"],["/delkey","/delblack","/listtrack"]'
fi
return
;;
'/neww'*) # newwatch
FINDKEYS="${MESSAGE#/* }"
FINDKEYS="${FINDKEYS%[\" ]}"
FINDKEYS="${FINDKEYS#[\" ]}"
if [ "${FINDKEYS}" = "${MESSAGE}" ]; then
send_markdown_message "${CHAT[ID]}" "${bashbot_shelp}"
else
set_keys "${FINDKEYS}" "${WATCHFILE}"
fi
;&
'/listw'*) # listwatch
send_action "${CHAT[ID]}" "typing"
FINDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${WATCHFILE}")"
if [ "${FINDKEYS}" = "" ]; then
send_markdown_message "${CHAT[ID]}" "*Kein Produkt Watch aktiv!*"
return
fi
OUT="Produkt Watch nach \"${FINDKEYS}\" ist aktiv."
if [[ "${CHAT[ID]}" != "${USER[ID]}" ]]; then
send_normal_message "${CHAT[ID]}" "${OUT}"
else
send_keyboard "${CHAT[ID]}" "${OUT}"\
'["/delwatch 1","/delwatch 2","/delwatch 3"],["/delwatch 4","/delwatch 5","/delwatch 6"],["/delwatch 7","/delwatch 8","/delwatch 9"],["/delwatch","/delwatch ALL","/listwatch"]'
fi
return
;;
'/newn'*) # newnotify
FINDKEYS="${MESSAGE#/* }"
FINDKEYS="${FINDKEYS%[\" ]}"
FINDKEYS="${FINDKEYS#[\" ]}"
if [ "${FINDKEYS}" = "${MESSAGE}" ]; then
send_markdown_message "${CHAT[ID]}" "${bashbot_shelp}"
else
set_keys "${FINDKEYS}" "${NOTIFYFILE}"
fi
;&
'/listn'*) # listnotify
send_action "${CHAT[ID]}" "typing"
FINDKEYS="$(jssh_getKeyDB "${CHAT[ID]}" "${NOTIFYFILE}")"
if [ "${FINDKEYS}" = "" ]; then
send_markdown_message "${CHAT[ID]}" "*Kein Produkt Notify aktiv!*"
return
fi
OUT="Produkt Notify nach \"${FINDKEYS}\" ist aktiv."
send_normal_message "${CHAT[ID]}" "${OUT}"
return
;;
#############################
# botadmin only commands
'/listat'*) # listalltrack
jssh_readDB "SEARCHVALUES" "${TRACKFILE}"
FINDKEYS="$(jssh_printDB "SEARCHVALUES")"
if [ "${FINDKEYS}" != "" ]; then
# shellcheck disable=SC2126
send_action "${CHAT[ID]}" "typing"
send_normal_message "${CHAT[ID]}" "All Suchaufträge:\n${FINDKEYS}"
else
send_markdown_message "${CHAT[ID]}" "*Kein Tracking aktiv!*"
fi
;;
'/listaw'*) # listall watch
jssh_readDB "SEARCHVALUES" "${WATCHFILE}"
FINDKEYS="$(jssh_printDB "SEARCHVALUES")"
if [ "${FINDKEYS}" != "" ]; then
send_action "${CHAT[ID]}" "typing"
send_normal_message "${CHAT[ID]}" "Alle Watchaufträge:\n${FINDKEYS}"
else
send_markdown_message "${CHAT[ID]}" "*Kein Produkt Watch aktiv!*"
fi
return
;;
'/delu'*) # delusersearch
KEY="${MESSAGE#/* }"; KEY="${KEY#%% *}"
if [ "${KEY}" = "${MESSAGE}" ] || [ "${KEY}" = "" ] ; then
jssh_readDB "SEARCHVALUES" "${TRACKFILE}"
FINDKEYS="$(jssh_printDB "SEARCHVALUES")"
if [ "${FINDKEYS}" != "" ]; then
send_normal_message "${CHAT[ID]}"\
"Aktive Suchaufträge:\n${FINDKEYS}\n\nSende \"/deluser ID\" zum Löschen eines Users"
else
send_markdown_message "${CHAT[ID]}" "*Kein Tracking aktiv!*"; exit
fi
exit
fi
jssh_deleteKeyDB "${KEY}" "${TRACKFILE}"
send_normal_message "${CHAT[ID]}" "Lösche Suchauftrag User ${KEY}"
jssh_readDB "SEARCHVALUES" "${TRACKFILE}"
FINDKEYS="$(jssh_printDB "SEARCHVALUES")"
if [ "${FINDKEYS}" != "" ]; then
send_normal_message "${CHAT[ID]}" "Verbliebene Suchaufträge:\n${FINDKEYS}"
else
send_markdown_message "${CHAT[ID]}" "*Kein Tracking aktiv!*"; exit
fi
return
;;
esac
}
fi
# debug function called on start, stop of bot, interactive and background processes
# if your bot was started with debug as second argument
# $1 current date, $2 from where the function wqs called, $3 ... $n optional information
my_debug_checks() {
# example check because my bot creates a wrong file, this was becuase an empty variable
[ -f ".jssh" ] && printf "%s: %s\n" "${1}" "Ups, found file \"${PWD:-.}/.jssh\"! =========="
}
# called when bashbot sedn command failed because we can not connect to telegram
# return 0 to retry, return non 0 to give up
bashbotBlockRecover() {
# place your commnds to unblock here, e.g. change IP or simply wait
sleep 60 && return 0 # may be temporary
return 1
}
# place your processing functions here
set_keys(){
local MYFIND MYKEY MYKEYF MINLEN MYCHECK MYSEARCH
declare -A KEYARR
MYFIND="$1"
MYKEYF="$2"
MINLEN="3"
# check len of keys
for MYKEY in ${MYFIND}; do [ "${#MYKEY}" -lt ${MINLEN} ] && break; done
if [ "${#MYKEY}" -lt ${MINLEN} ]; then
send_markdown_message "${CHAT[ID]}" "*Ein Suchbegriff ist kürzer als ${MINLEN} Zeichen!*"
else
MYFIND="$(create_pattern "${MYFIND}")"
MYCHECK="$(check_pattern "${MYFIND}")"
[[ "${MESSAGE}" == "/s"* ]] &&\
send_normal_message "${CHAT[ID]}" "${MYCHECK}Suche nach \"${MYFIND//|/ }\" wird gestartet ..."
MYKEY="${MYFIND//[^|]}"
if [ "${#MYKEY}" -gt 49 ]; then
send_markdown_message "${CHAT[ID]}" "*Maximale Anzahl von 50 Begriffen erreicht!*"
elif [ "${MYFIND}" != "" ]; then
KEYARR["${CHAT[ID]}"]="${MYFIND}"
jssh_updateDB "KEYARR" "${MYKEYF}"
#jssh_insertDB "${CHAT[ID]}" "${MYFIND}" "${MYKEYF}"
else
send_markdown_message "${CHAT[ID]}" "*Ein Begriff ist ungültig, z.B. \" , oder leer!*"
fi
fi
}
# place your processing functions here
# $1 ARRAYNAME $2 command
printKeys() {
local key
declare -n ARRAY="$1"
for key in "${!ARRAY[@]}"
do
printf '%s - %s\n' "${key}" "${ARRAY[${key}]}"
done
}
# create a regex from space sepeareted keywords
# $1 space separated words
create_pattern() {
local PATTERN KEY
set -f
for KEY in $1
do
[ "${PATTERN}" != "" ] && PATTERN="${PATTERN}|"
PATTERN="${PATTERN}${KEY}"
done
# revome blank and "
PATTERN="${PATTERN//[\" ]}"
# remove * at start
PATTERN="${PATTERN//|\*/|}"; PATTERN="${PATTERN#\*}"
# remove unneeded |
PATTERN="${PATTERN//||/|}"; PATTERN="${PATTERN#|}"; PATTERN="${PATTERN%|}"
set +f
echo "${PATTERN}"
}
# check regex for common errors
# ¤1 pattern
check_pattern() {
local WARN=""
if [[ "$1" =~ ([^.\)]\*)|(^\*) ]]; then
WARN+="Meintest du evtl. '.*' ? '*' ist vorheriges Zeichen beliebig oft. "$'\n\r'
fi
if [[ "$1" =~ (^\*)|(^.\*)|([^\)]\*\|)|(\|\*)|(\|\.\*)|([^\)]\*$) ]] ; then
WARN+="Ein '.*' oder '*' an Anfang oder End ist unnötig. "$'\n\r'
fi
if [[ "$1" =~ \([^|\)]*\| ]] ; then
WARN+="Öffnende '(' ohne ')' gefunden. Klammerausdruck muss vor '|' geschlossen sein. "$'\n\r'
fi
[ -n "${WARN}" ] && printf "Potentielle Fehlerquellen:\n\r%s\n\r" "${WARN}"
}

View File

@ -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$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-17-g9d7f145
# will be automatically sourced from bashbot
@ -46,6 +46,7 @@ send_normal_message() {
send_markdown_message() {
local text; text="$(JsonEscape "${2}")"
[ "${#text}" -ge 4096 ] && log_error "Warning: markdown message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
until [ -z "${text}" ]; do
sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"markdown"' "${MSG_URL}"
text="${text:4096}"
@ -54,6 +55,7 @@ send_markdown_message() {
send_markdownv2_message() {
local text; text="$(JsonEscape "${2}")"
[ "${#text}" -ge 4096 ] && log_error "Warning: markdown message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
# markdown v2 needs additional double escaping!
text="$(sed -E -e 's|([#{}()!.-])|\\\1|g' <<< "$text")"
until [ -z "${text}" ]; do
@ -64,6 +66,7 @@ send_markdownv2_message() {
send_html_message() {
local text; text="$(JsonEscape "${2}")"
[ "${#text}" -ge 4096 ] && log_error "Warning: html message longer than 4096 characters, message is rejected if formatting crosses 4096 border."
until [ -z "${text}" ]; do
sendJson "${1}" '"text":"'"${text:0:4096}"'","parse_mode":"html"' "${MSG_URL}"
text="${text:4096}"
@ -80,6 +83,7 @@ old_send_keyboard() {
IFS="$OLDIFS"
keyboard="${keyboard/init, /}"
sendJson "${1}" "${text}"', "reply_markup": {"keyboard": [ '"${keyboard}"' ],"one_time_keyboard": true}' "$MSG_URL"
send_normal_message "$(getConfigKey "botadmin")" "Warning: old 'send_keyboard' format is deprecated since version 0.6 and will be removed after 1.0 release!"
}
send_keyboard() {

View File

@ -3,17 +3,20 @@
#
# files: mycommands.sh.dist
#
# this is an out of the box test and example file to show what you can do in mycommands.sh
# this is an out of the box test and example file to show what's possible in mycommands.sh
#
# #### if you start to develop your own bot, use the clean version of this file:
# #### mycommands.clean
#
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-15-g25578bf
#
# uncomment the following lines to overwrite info and help messages
# export bashbot_info='This is bashbot, the Telegram bot written entirely in bash.
#'
# use ${ME} for current bot name in messages
# Note: you must escape '_' in botname with two \ in markdown messages!
export bashbot_info='This is @'"${ME//_/\\\\_}"', the Telegram example bot written entirely in bash.
Edit commands and messages in mycommnds.sh!
'
# export bashbot_help='*Available commands*:
#'
export res=""
@ -24,39 +27,37 @@ export INLINE="0"
# Set to .* to allow sending files from all locations
# NOTE: this is a regex, not shell globbing! you must use a valid egex,
# '.' matches any character and '.*' matches all remaining charatcers!
# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally
# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally
export FILE_REGEX="${BASHBOT_ETC}/.*"
# example: run bashbot over TOR
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050"
# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# problems with send_,´message etc are looged to logs/ERROR.log
# problems with send_xxx message etc are looged to logs/ERROR.log
unset BASHBOT_RETRY
#export BASHBOT_RETRY="yes"
# set value for adaptive sleeping while waitingnfor uodates in millisconds
# set value for adaptive sleeping while waiting for uodates in millisconds
# max slepp between polling updates 10s (default 5s)
export BASHBOT_SLEEP="10000"
# add 0.2s if no update available, up to BASHBOT_SLEEP (default 0.1s)
export BASHBOT_SLEEP_STEP="200"
# if you want to use timer functions, set BASHBOT_START_TImer to not empty value
# default is to nit start timer
# if you want to use timer functions, set BASHBOT_START_TIMER to a not empty value
# default is to not start timer
unset BASHBOT_START_TIMER
#export BASHBOT_START_TIMER="yes"
# set to "yes" and give your bot admin privilegs to remove service messaes from groups
# set to "yes" and give your bot admin privilegs to remove service messages from groups
export SILENCER="no"
# uncomment if you use keyboards in your commands
# uncomment to remove keyboards sent from your bot
# export REMOVEKEYBOARD="yes"
# export REMOVEKEYBOARD_PRIVATE="yes"
# uncomment if you want to say welcome to new chat members
# uncomment to say welcome to new chat members
# export WELCOME_NEWMEMBER="yes"
WELCOME_MSG="Welcome"
# uncomment if you want to be informed about new/left chat members
# uncomment to be informed about new/left chat members
# export REPORT_NEWMEMBER="yes"
# export REPORT_LEFTMEMBER="yes"
@ -64,6 +65,13 @@ WELCOME_MSG="Welcome"
NOTADMIN="Sorry, this command is allowed for admin or owner only"
NOTBOTADMIN="Sorry, this command is allowed for bot owner only"
########
# special network setup may require additional ARGS to curl
#
# example: run bashbot over TOR or SOCKS proxy
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1" # regular SOCKS
if [ "$1" = "startbot" ];then
###################
# this function is run once after startup when the first message is received
@ -71,17 +79,19 @@ if [ "$1" = "startbot" ];then
# send message ito first user on startup
send_normal_message "${CHAT[ID]}" "Hi, you was the first one after startup!"
}
# reminde bot that it was started
touch .mystartup
# remind bot of start, now uses config store
setConfigKey "startupaction" "await"
else
# here we call the function above when the message arrives
# things to do only at source, eg. after startup
[ -f .mystartup ] && rm -f .mystartup && _exec_if_function my_startup
# call my_startup when first message arrives
if [[ "$(getConfigKey "startupaction")" != "done"* ]]; then
_exec_if_function my_startup
setConfigKey "startupaction" "done $(date)"
fi
#############################
# your own bashbot commands
# NOTE: command can have @botname attached, you must add * in case tests...
mycommands() {
# NOTE: command can have @botname attached, you must add * to case tests...
mycommands() {
##############
# a service Message was received
@ -113,7 +123,7 @@ else
# fix first letter upper case because of smartphone auto correction
[[ "${MESSAGE}" =~ ^/[[:upper:]] ]] && MESSAGE="${MESSAGE:0:1}$(tr '[:upper:]' '[:lower:]' <<<"${MESSAGE:1:1}")${MESSAGE:2}"
# pre-check admin only commands
# pre-check admin only commands
case "${MESSAGE}" in
# must be private, group admin, or botadmin
'/run_'*|'stop_'*)
@ -148,7 +158,7 @@ else
;;
'/_left_chat_member'*)
[ -n "${REPORT_LEFTMEMBER}" ] && send_normal_message "$(getConfigKey "botadmin")"\
"Left member: ${CHAT[TITLE]} (${CHAT[ID]}): ${NEWMEMBER[FIRST_NAME]} ${NEWMEMBER[LAST_NAME]} (@${NEWMEMBER[USERNAME]})"
"Left member: ${CHAT[TITLE]} (${CHAT[ID]}): ${LEFTMEMBER[FIRST_NAME]} ${LEFTMEMBER[LAST_NAME]} (@${LEFTMEMBER[USERNAME]})"
;;
esac
@ -233,7 +243,7 @@ else
"
;;
"4") # four photo from array
"4") # four photos from array
local sep=""
local avatar=("https://avatars.githubusercontent.com/u/13046303" "https://avatars.githubusercontent.com/u/4593242" "https://avatars.githubusercontent.com/u/102707" "https://avatars.githubusercontent.com/u/6460407")
answer_inline_multi "${iQUERY[ID]}" "
@ -243,7 +253,7 @@ else
"
;;
"sticker") # example chaecd telegram sticker
"sticker") # example cached telegram sticker
answer_inline_query "${iQUERY[ID]}" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
;;
"gif") # example cached gif
@ -260,7 +270,7 @@ else
[ -f ".jssh" ] && printf "%s: %s\n" "${1}" "Ups, found file \"${PWD:-.}/.jssh\"! =========="
}
# called when bashbot sedn command failed because we can not connect to telegram
# called when bashbot send_xxx command failed because we can not connect to telegram
# return 0 to retry, return non 0 to give up
bashbotBlockRecover() {
# place your commands to unblock here, e.g. change IP or simply wait

View File

@ -4,7 +4,7 @@
# files: mycommands.sh.clean
# copy to mycommands.sh and add all your commands and functions here ...
#
#### $$VERSION$$ 0.99-0-g2775000
#### $$VERSION$$ 0.99-4-g15eb311
#
##########
@ -18,17 +18,17 @@ export bashbot_help='*Available commands*:
export res=""
# Set INLINE to 1 in order to receive inline queries.
# To enable this option in your bot ypu must also send the /setinline command to @BotFather.
# To enable this option in your bot must also send the /setinline command to @BotFather.
export INLINE="0"
# NOTE: this is a regex, not shell globbing! you must use a valid egex,
# '.' matches any character and '.*' matches all remaining charatcers!
# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally
# additionally you must escape special characters with '\', e.g. '\. \? \[ \*" to match them literally
# do NOT set to .* as this allow sending files from all locations!
export FILE_REGEX="${BASHBOT_ETC}/.*"
# set BASHBOT_RETRY to enable retry in case of recoverable errors, e.g. throtteling
# problems with send_,´message etc are looged to logs/ERROR.log
# problems with send_,´message etc are looged to logs/ERROR.log
unset BASHBOT_RETRY
#export BASHBOT_RETRY="yes"
@ -38,19 +38,19 @@ export BASHBOT_SLEEP="10000"
# add 0.2s if no update available, up to BASHBOT_SLEEP (default 0.1s)
export BASHBOT_SLEEP_STEP="200"
# if you want to use timer functions, set BASHBOT_START_TImer to not empty value
# if you want to use timer functions, set BASHBOT_START_TIMER to a not empty value
# default is to nit start timer
unset BASHBOT_START_TIMER
#export BASHBOT_START_TIMER="yes"
# set to "yes" and give your bot admin privilegs to remove service messaes from groups
export SILENCER="no"
# uncomment if you use keyboards in your commands
# uncomment to remove keyboards sent by your bot
# export REMOVEKEYBOARD="yes"
# export REMOVEKEYBOARD_PRIVATE="yes"
########
# special network setups may require to provide additional ARGS to curl
# special network setup may require additional ARGS to curl
#
# example: run bashbot over TOR or SOCKS proxy
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050" # TOR
@ -63,13 +63,13 @@ if [ "$1" = "startbot" ];then
}
touch .mystartup
else
# here we call the function above when the message arrives
# things to do only at source, eg. after startup
# call my_startup on first message after startup
# things to do only once
[ -f .mystartup ] && rm -f .mystartup && _exec_if_function my_startup
#############################
# your own bashbot commands
# NOTE: command can have @botname attached, you must add * in case tests...
# NOTE: command can have @botname attached, you must add * to case tests...
mycommands() {
##############

View File

@ -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'