move process_inline to bashbot.sh, documentation make-standalone.sh
This commit is contained in:
parent
b7df57a085
commit
d08d91205d
|
@ -78,6 +78,8 @@
|
|||
<li><a href="doc/8_custom.md">Customize bashbot environment</a></li>
|
||||
<li><a href="examples/README.md">Examples</a></li>
|
||||
</ul>
|
||||
<h3 id="i-dont-like-the-many-bashbot-files">I don’t like the many bashbot files</h3>
|
||||
<p>At the beginning bashbot was simply the file <code>bashbot.sh</code> I can copy everywhere and run the bot. Now we have ‘commands.sh’, ‘mycommands.sh’, ’modules/*.sh’ and much more. Hey no Problem, if you are finished with your cool bot simply run <code>dev/make-standalone.sh</code> to create a a stripped down Version 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>
|
||||
<h2 id="security-considerations">Security Considerations</h2>
|
||||
<p>Running a Telegram Bot means it is connected to the public and you never know whats 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>
|
||||
|
@ -103,6 +105,6 @@
|
|||
<p><span class="citation">@Gnadelwartz</span></p>
|
||||
<h2 id="thats-it">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 id="version-v0.80-dev2-1-g0b36bc5"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.80-dev2-1-g0b36bc5</h4>
|
||||
<h4 id="version-v0.80-dev2-4-gb7df57a"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.80-dev2-4-gb7df57a</h4>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
@ -57,6 +57,12 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
|||
* [Customize bashbot environment](doc/8_custom.md)
|
||||
* [Examples](examples/README.md)
|
||||
|
||||
|
||||
### I don't like the many bashbot files
|
||||
At the beginning bashbot was simply the file ```bashbot.sh``` I can copy everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh', 'modules/*.sh' and much more.
|
||||
Hey no Problem, if you are finished with your cool bot simply run ```dev/make-standalone.sh``` to create a a stripped down Version containing only
|
||||
'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped down Version of your Bot](doc/7_develop.md)
|
||||
|
||||
## Security Considerations
|
||||
Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot.
|
||||
|
||||
|
@ -98,4 +104,4 @@ Well, thats a damn good question ... may be because I'm an Unix/Linux admin from
|
|||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.80-dev2-1-g0b36bc5
|
||||
#### $$VERSION$$ v0.80-dev2-4-gb7df57a
|
||||
|
|
12
README.txt
12
README.txt
|
@ -64,6 +64,16 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
|
|||
* [Customize bashbot environment](doc/8_custom.md)
|
||||
* [Examples](examples/README.md)
|
||||
|
||||
|
||||
### I don't like the many bashbot files
|
||||
At the beginning bashbot was simply the file ```bashbot.sh``` I can copy
|
||||
everywhere and run the bot. Now we have 'commands.sh', 'mycommands.sh',
|
||||
'modules/*.sh' and much more.
|
||||
Hey no Problem, if you are finished with your cool bot simply run
|
||||
```dev/make-standalone.sh``` to create a a stripped down Version containing only
|
||||
'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped
|
||||
down Version of your Bot](doc/7_develop.md)
|
||||
|
||||
## Security Considerations
|
||||
Running a Telegram Bot means it is connected to the public and you never know
|
||||
whats send to your Bot.
|
||||
|
@ -137,4 +147,4 @@ health status
|
|||
If you feel that there's something missing or if you found a bug, feel free to
|
||||
submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.80-dev2-1-g0b36bc5
|
||||
#### $$VERSION$$ v0.80-dev2-4-gb7df57a
|
||||
|
|
15
bashbot.sh
15
bashbot.sh
|
@ -12,7 +12,7 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.80-dev2-2-g0c5e3dd
|
||||
#### $$VERSION$$ v0.80-dev2-4-gb7df57a
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
|
@ -144,8 +144,8 @@ UPD_URL=$URL'/getUpdates?offset='
|
|||
GETFILE_URL=$URL'/getFile'
|
||||
|
||||
unset USER
|
||||
declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE
|
||||
export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE
|
||||
declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY
|
||||
export BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY
|
||||
|
||||
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
||||
if [ "$1" != "source" ]; then
|
||||
|
@ -412,6 +412,15 @@ JsonGetLine() {
|
|||
JsonGetValue() {
|
||||
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p'
|
||||
}
|
||||
|
||||
process_inline() {
|
||||
local num="${1}"
|
||||
iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")"
|
||||
iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')"
|
||||
iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")"
|
||||
iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")"
|
||||
iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")"
|
||||
}
|
||||
process_message() {
|
||||
local num="$1"
|
||||
local TMP="${TMPDIR:-.}/$RANDOM$RANDOM-MESSAGE"
|
||||
|
|
|
@ -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$$ v0.80-dev2-1-g0b36bc5
|
||||
#### $$VERSION$$ v0.80-dev2-4-gb7df57a
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
|
@ -39,19 +39,16 @@ Get the code in my [GitHub](http://github.com/topkecleon/telegram-bot-bash)
|
|||
'
|
||||
|
||||
if [ "${1}" != "source" ]; then
|
||||
# load modules needed for commands.sh only
|
||||
# shellcheck source=./modules/aliases.sh
|
||||
[ -r "${MODULEDIR:-.}/aliases.sh" ] && source "${MODULEDIR:-.}/aliases.sh"
|
||||
# shellcheck source=./modules/background.sh
|
||||
[ -r "${MODULEDIR:-.}/background.sh" ] && source "${MODULEDIR:-.}/background.sh"
|
||||
# shellcheck source=./modules/background.sh
|
||||
[ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh"
|
||||
else
|
||||
# defaults to no inline and nonsense home dir
|
||||
INLINE="0"
|
||||
FILE_REGEX='/home/user/allowed/.*'
|
||||
|
||||
# load modules needed for bashbot.sh also
|
||||
# shellcheck source=./modules/background.sh
|
||||
[ -r "${MODULEDIR:-.}/inline.sh" ] && source "${MODULEDIR:-.}/inline.sh"
|
||||
fi
|
||||
|
||||
# load mycommands
|
||||
|
|
|
@ -4,7 +4,7 @@ This section is about help and best practices for new bashbot developers. The ma
|
|||
|
||||
bashbot development is done on github. If you want to provide fixes or new features [fork bashbot on githup](https://help.github.com/en/articles/fork-a-repo) and provide changes as [pull request on github](https://help.github.com/en/articles/creating-a-pull-request).
|
||||
|
||||
### Debuging Bashbot
|
||||
### Debugging Bashbot
|
||||
In normal mode of operation all bashbot output is discarded one more correct sent to TMUX console.
|
||||
To get these messages (and more) you can start bashbot in the current shell ```./bashbot.sh startbot```. Now you can see all output or erros from bashbot.
|
||||
In addition you can change the change the level of verbosity by adding a third argument after startbot.
|
||||
|
@ -16,7 +16,19 @@ In addition you can change the change the level of verbosity by adding a third a
|
|||
"xdebugterm" same as xdebug but output and errors are sent to terminal
|
||||
```
|
||||
|
||||
### Create a stripped down Version of your Bot
|
||||
Currently bashbot is more a bot development environment than a bot, containing examples, developer scripts, modules, documentation and more.
|
||||
You don't need all these files after you're finished with your cool new bot.
|
||||
|
||||
Let's create a stripped down version:
|
||||
|
||||
- delete all modules you do not need from 'modules', e.g. 'modules/inline.sh' if you don't use inline queries
|
||||
- delete not needed standard commands and messages from 'commands.sh'
|
||||
- delete not neede commands and functions from 'mycommands.sh'
|
||||
- run ```dev/make-standalone.sh``` to create a a stripped down version of your bo
|
||||
|
||||
Now have a look at the directory 'standalone', here you find the files 'bashbot.sh' and 'commands.sh' containing everything to run your bot.
|
||||
[Download make-standalone.sh](https://github.com/topkecleon/telegram-bot-bash/blob/master/dev/make-standalone.sh) from github.
|
||||
|
||||
### Setup your develop environment
|
||||
|
||||
|
@ -48,6 +60,8 @@ Usually I start with pre versions and when everything looks good I push out a re
|
|||
v0.x-devx -> v0.x-prex -> v0.x-rc -> v0.x ... 0.x+1-dev ...
|
||||
```
|
||||
|
||||
If you release a new Version run ```dev/make-distribution.sh``` to create the zip and tar.gz archives in the dist directory and attach them to the github release. Do not forget to delete directory dist afterwards.
|
||||
|
||||
### Versioning
|
||||
|
||||
Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version.
|
||||
|
@ -131,5 +145,5 @@ fi
|
|||
#### [Prev Function Reference](6_reference.md)
|
||||
#### [Next Bashbot Environment](8_custom.md)
|
||||
|
||||
#### $$VERSION$$ v0.80-dev2-1-g0b36bc5
|
||||
#### $$VERSION$$ v0.80-dev2-4-gb7df57a
|
||||
|
||||
|
|
|
@ -5,23 +5,11 @@
|
|||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.80-dev2-1-g0b36bc5
|
||||
#### $$VERSION$$ v0.80-dev2-4-gb7df57a
|
||||
|
||||
# source from commands.sh to use the inline functions
|
||||
|
||||
INLINE_QUERY=$URL'/answerInlineQuery'
|
||||
declare -A iQUERY
|
||||
export iQUERY
|
||||
|
||||
process_inline() {
|
||||
local num="${1}"
|
||||
iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")"
|
||||
iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')"
|
||||
iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")"
|
||||
iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")"
|
||||
iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")"
|
||||
}
|
||||
|
||||
|
||||
answer_inline_query() {
|
||||
answer_inline_multi "${1}" "$(shift; inline_query_compose "$RANDOM" "$@")"
|
||||
|
|
Loading…
Reference in New Issue