mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-21 15:15:09 +00:00
codespell is much better
This commit is contained in:
parent
694ee6185d
commit
d2a578a757
22
README.html
22
README.html
@ -143,7 +143,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
|
||||
<li>jsshDB Bashbot key-value storage</li>
|
||||
<li>Background and Interactive Jobs</li>
|
||||
</ul></li>
|
||||
<li><a href="doc/7_develop.md">Devloper Notes</a>
|
||||
<li><a href="doc/7_develop.md">Developer Notes</a>
|
||||
<ul>
|
||||
<li>Debug bashbot</li>
|
||||
<li>Modules, addons, events</li>
|
||||
@ -160,7 +160,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
|
||||
<p>Create a new directory and change to it: <code>mkdir tbb; cd tbb</code> and download the latest '*.tar.gz' file from <a href="https://github.com/topkecleon/telegram-bot-bash/releases">https://github.com/topkecleon/telegram-bot-bash/releases</a>. This can be done with the commands:</p>
|
||||
<div class="sourceCode" id="cb1"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb1-1" title="1"><span class="fu">wget</span> -q https://github.com/<span class="va">$(</span><span class="fu">wget</span> -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - <span class="kw">|</span> <span class="fu">egrep</span> <span class="st">'/.*/.*/.*tar.gz'</span> -o<span class="va">)</span></a></code></pre></div>
|
||||
<p>Extract the '*.tar.gz' file and change to bashbot directory: <code>tar -xzf *.tar.gz; cd telegram-bot-bash</code>, install bashbot: <code>./bashbot.sh init</code> and enter your bot token when asked. All other questions can be answered by hitting the <Return> key.</p>
|
||||
<p>Thats all, now you can start your bot with <code>./bashbot.sh start</code> and send him messages:</p>
|
||||
<p>That's all, now you can start your bot with <code>./bashbot.sh start</code> and send him messages:</p>
|
||||
<pre><code>/start
|
||||
|
||||
You are Botadmin
|
||||
@ -187,11 +187,11 @@ It features background tasks and interactive chats, and can serve as an interfac
|
||||
</code></pre>
|
||||
<hr />
|
||||
<h2>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>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 from untrusted sources (messages, files, network) you must be as carefull as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everthing. In addition delete unused scripts and examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable all not used commands.</p>
|
||||
<p>Whenever you are processing input from 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, pls 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 like bash is variable and command substitution using <code>${}</code> and <code>$()</code>, but as they are expanded in doble quotes, this can lead to RCE and information disclosing bugs in complex scripts like bashbot even bash does much to avoid this. So it's more secure to escape or remove '$' in input from user, files or network.</p>
|
||||
<p>One of the most powerful features of unix shells like bash 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 even bash does much to avoid this. 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 enshure 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>
|
||||
<p>If you're writing a script and it is taking external input (from the user as arguments, or file names from the file system...), you shouldn't use echo to display it. <a href="https://unix.stackexchange.com/a/6581">Use printf whenever possible</a></p>
|
||||
@ -212,20 +212,20 @@ It features background tasks and interactive chats, and can serve as an interfac
|
||||
<p>Using a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.</p>
|
||||
<p>If you are a BSD / MacOS user or must to use an other bash location, see <a href="doc/0_install.md">Install Bashbot</a></p>
|
||||
<h3>Run your Bot as a restricted user</h3>
|
||||
<p><strong>I recommend to run your bot as a user, with almost no access rights.</strong> All files your Bot have write access to are in danger to be overwritten/deleted if your bot is hacked. For the same reason ervery file your Bot can read is in danger to be disclosed. Restict your Bots access rigths to the absolute minimum.</p>
|
||||
<p><strong>I recommend to run your bot as a user, with almost no access rights.</strong> All files your Bot have write access to are in danger to be overwritten/deleted if your bot is hacked. For the same reason every file your Bot can read is in danger to be disclosed. Restict your Bots access rights to the absolute minimum.</p>
|
||||
<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 can act as your Bot and has access to all chats your 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 exept you must have write access to the Bot files. The Bot must 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 Token in <code>token</code> must be protected against other users. No one except you must have write access to the Bot files. The Bot must 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>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 other Bot written in any 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, pls update if you use an older version!</p>
|
||||
<h3>Why Bash and not the much better xyz?</h3>
|
||||
<p>Well, thats a damn good question ... may be because I'm an Unix/Linux admin from stone age. Nevertheless there are more reasons from my side:</p>
|
||||
<p>Well, that's a damn good question ... may be because I'm an Unix/Linux admin from stone age. Nevertheless there are more reasons from my side:</p>
|
||||
<ul>
|
||||
<li>bashbot will run everywhere where bash is available, from ebedded linux to mainframe</li>
|
||||
<li>bashbot will run everywhere where bash is available, from embedded linux to mainframe</li>
|
||||
<li>easy to integrate with other shell script, e.g. for sending system message / health status</li>
|
||||
<li>no need to install or learn a new programming language, library or framework</li>
|
||||
<li>no database, not event driven, not OO ...</li>
|
||||
@ -234,7 +234,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 messsage '/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 kill</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">"</span><span class="va">$(</span><span class="bu">pwd</span><span class="va">)</span><span class="st">"</span></a>
|
||||
@ -257,6 +257,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$$ v0.98-dev-69-gafa8d87</h4>
|
||||
<h4>$$VERSION$$ v0.98-dev-70-g694ee61</h4>
|
||||
</body>
|
||||
</html>
|
||||
|
22
README.md
22
README.md
@ -55,7 +55,7 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
||||
* Inline Queries
|
||||
* jsshDB Bashbot key-value storage
|
||||
* Background and Interactive Jobs
|
||||
* [Devloper Notes](doc/7_develop.md)
|
||||
* [Developer Notes](doc/7_develop.md)
|
||||
* Debug bashbot
|
||||
* Modules, addons, events
|
||||
* Setup your environment
|
||||
@ -85,7 +85,7 @@ Extract the '*.tar.gz' file and change to bashbot directory: ```tar -xzf *.tar.g
|
||||
install bashbot: ```./bashbot.sh init``` and enter your bot token when asked. All other questions can be answered
|
||||
by hitting the \<Return\> key.
|
||||
|
||||
Thats all, now you can start your bot with ```./bashbot.sh start``` and send him messages:
|
||||
That's all, now you can start your bot with ```./bashbot.sh start``` and send him messages:
|
||||
```
|
||||
/start
|
||||
|
||||
@ -121,17 +121,17 @@ To enable debug mode start bashbot with debug as third argument: `bashbot start
|
||||
----
|
||||
|
||||
## Security Considerations
|
||||
Running a Telegram Bot means it is connected to the public and you never know whats send to your Bot.
|
||||
Running a Telegram Bot means it is connected to the public and you never know what's send to your Bot.
|
||||
|
||||
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 [Implications of wrong quoting](https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells)
|
||||
|
||||
Whenever you are processing input from from untrusted sources (messages, files, network) you must be as carefull as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everthing. In addition delete unused scripts and examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable all not used commands.
|
||||
Whenever you are processing input from 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, pls 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 like bash is variable and command substitution using ```${}``` and ```$()```,
|
||||
but as they are expanded in doble quotes, this can lead to RCE and information disclosing bugs in complex scripts like bashbot
|
||||
but as they are expanded in double quotes, this can lead to RCE and information disclosing bugs in complex scripts like bashbot
|
||||
even bash does much to avoid this. So it's more secure to escape or remove '$' in input from user, files or network.
|
||||
|
||||
A powerful tool to improve your scripts is ```shellcheck```. You can [use it online](https://www.shellcheck.net/) or [install shellcheck locally](https://github.com/koalaman/shellcheck#installing). Shellcheck is used extensive in bashbot development to enshure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests.
|
||||
@ -169,14 +169,14 @@ If you are a BSD / MacOS user or must to use an other bash location, see [Insta
|
||||
### Run your Bot as a restricted user
|
||||
**I recommend to run your bot as a user, with almost no access rights.**
|
||||
All files your Bot have write access to are in danger to be overwritten/deleted if your bot is hacked.
|
||||
For the same reason ervery file your Bot can read is in danger to be disclosed. Restict your Bots access rigths to the absolute minimum.
|
||||
For the same reason every file your Bot can read is in danger to be disclosed. Restict your Bots access rights to the absolute minimum.
|
||||
|
||||
**Never run your Bot as root, this is the most dangerous you can do!** Usually the user 'nobody' has almost no rights on Unix/Linux systems. See [Expert use](doc/4_expert.md) on how to run your Bot as an other user.
|
||||
|
||||
### Secure your Bot installation
|
||||
**Your Bot configuration must no be readable from other users.** Everyone who can read your Bots token can act as your Bot and has access to all chats your 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 exept you must have write access to the Bot files. The Bot must 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 Token in ```token``` must be protected against other users. No one except you must have write access to the Bot files. The Bot must be restricted to have write access to ```count``` and ```tmp-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.
|
||||
|
||||
@ -188,9 +188,9 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w
|
||||
**Note:** Until v0.941 (mai/22/2020) telegram-bot-bash has a remote code execution bug, pls update if you use an older version!
|
||||
|
||||
### Why Bash and not the much better xyz?
|
||||
Well, thats a damn good question ... may be because I'm an Unix/Linux admin from stone age. Nevertheless there are more reasons from my side:
|
||||
Well, that's a damn good question ... may be because I'm an Unix/Linux admin from stone age. Nevertheless there are more reasons from my side:
|
||||
|
||||
- bashbot will run everywhere where bash is available, from ebedded linux to mainframe
|
||||
- bashbot will run everywhere where bash is available, from embedded linux to mainframe
|
||||
- easy to integrate with other shell script, e.g. for sending system message / health status
|
||||
- no need to install or learn a new programming language, library or framework
|
||||
- no database, not event driven, not OO ...
|
||||
@ -203,7 +203,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 messsage '/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 kill```.
|
||||
|
||||
Run the following commands in your bash shell or script while you are in the installation directory:
|
||||
|
||||
@ -239,4 +239,4 @@ wget -t 1 -T 10 https://api.telegram.org/bot
|
||||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
26
README.txt
26
README.txt
@ -68,7 +68,7 @@ available on www.github.com
|
||||
* Inline Queries
|
||||
* jsshDB Bashbot key-value storage
|
||||
* Background and Interactive Jobs
|
||||
* [Devloper Notes](doc/7_develop.md)
|
||||
* [Developer Notes](doc/7_develop.md)
|
||||
* Debug bashbot
|
||||
* Modules, addons, events
|
||||
* Setup your environment
|
||||
@ -111,7 +111,7 @@ install bashbot: ```./bashbot.sh init``` and enter your bot token when asked.
|
||||
All other questions can be answered
|
||||
by hitting the \<Return\> key.
|
||||
|
||||
Thats all, now you can start your bot with ```./bashbot.sh start``` and send
|
||||
That's all, now you can start your bot with ```./bashbot.sh start``` and send
|
||||
him messages:
|
||||
```
|
||||
/start
|
||||
@ -154,7 +154,7 @@ enabled)
|
||||
|
||||
## Security Considerations
|
||||
Running a Telegram Bot means it is connected to the public and you never know
|
||||
whats send to your Bot.
|
||||
what's send to your Bot.
|
||||
|
||||
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'
|
||||
@ -163,8 +163,8 @@ quoting](https://unix.stackexchange.com/questions/171346/security-implications-o
|
||||
f-forgetting-to-quote-a-variable-in-bash-posix-shells)
|
||||
|
||||
Whenever you are processing input from from untrusted sources (messages, files,
|
||||
network) you must be as carefull as possible, e.g. set IFS appropriate, disable
|
||||
globbing (set -f) and quote everthing. In addition delete unused scripts and
|
||||
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.
|
||||
|
||||
@ -174,7 +174,7 @@ see [Issue #125](https://github.com/topkecleon/telegram-bot-bash/issues/125)
|
||||
|
||||
One of the most powerful features of unix shells like bash is variable and
|
||||
command substitution using ```${}``` and ```$()```,
|
||||
but as they are expanded in doble quotes, this can lead to RCE and information
|
||||
but as they are expanded in double quotes, this can lead to RCE and information
|
||||
disclosing bugs in complex scripts like bashbot
|
||||
even bash does much to avoid this. So it's more secure to escape or remove '$'
|
||||
in input from user, files or network.
|
||||
@ -226,8 +226,8 @@ If you are a BSD / MacOS user or must to use an other bash location, see
|
||||
**I recommend to run your bot as a user, with almost no access rights.**
|
||||
All files your Bot have write access to are in danger to be overwritten/deleted
|
||||
if your bot is hacked.
|
||||
For the same reason ervery file your Bot can read is in danger to be disclosed.
|
||||
Restict your Bots access rigths to the absolute minimum.
|
||||
For the same reason every file your Bot can read is in danger to be disclosed.
|
||||
Restict your Bots access rights to the absolute minimum.
|
||||
|
||||
**Never run your Bot as root, this is the most dangerous you can do!** Usually
|
||||
the user 'nobody' has almost no rights on Unix/Linux systems. See [Expert
|
||||
@ -240,7 +240,7 @@ 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 exept you must have write access to the Bot files. The Bot must be
|
||||
No one except you must have write access to the Bot files. The Bot must be
|
||||
restricted to have write access to ```count``` and ```tmp-bot-bash``` only,
|
||||
all other files must be write protected.
|
||||
|
||||
@ -259,10 +259,10 @@ for the bot commands you wrote and you should know about the risks ...
|
||||
execution bug, pls update if you use an older version!
|
||||
|
||||
### Why Bash and not the much better xyz?
|
||||
Well, thats a damn good question ... may be because I'm an Unix/Linux admin
|
||||
Well, that's a damn good question ... may be because I'm an Unix/Linux admin
|
||||
from stone age. Nevertheless there are more reasons from my side:
|
||||
|
||||
- bashbot will run everywhere where bash is available, from ebedded linux to
|
||||
- bashbot will run everywhere where bash is available, from embedded linux to
|
||||
mainframe
|
||||
- easy to integrate with other shell script, e.g. for sending system message /
|
||||
health status
|
||||
@ -283,7 +283,7 @@ down Version of your Bot](doc/7_develop.md)
|
||||
### 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 messsage '/start' to set yourself as botadmin and stop the bot with
|
||||
send the message '/start' to set yourself as botadmin and stop the bot with
|
||||
```./bashbot.sh kill```.
|
||||
|
||||
Run the following commands in your bash shell or script while you are in the
|
||||
@ -327,4 +327,4 @@ failed: Connection timed out.
|
||||
If you feel that there's something missing or if you found a bug, feel free to
|
||||
submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
@ -4,7 +4,7 @@
|
||||
# this addon counts how many files, e.g. stickers, are sent to
|
||||
# a chat and takes actions if threshold is reached
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# used events:
|
||||
#
|
||||
@ -18,7 +18,7 @@
|
||||
# $1 event: init, startbot ...
|
||||
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||
#
|
||||
# prameters on events
|
||||
# parameters on events
|
||||
# $1 event: inline, message, ..., file
|
||||
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||
#
|
||||
|
@ -1,12 +1,12 @@
|
||||
#!/bin/bash
|
||||
# file: addons/example.sh.dist
|
||||
#
|
||||
# Addons can register to bashbot events at statup
|
||||
# Addons can register to bashbot events at startup
|
||||
# by providing their name and a callback per event
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
# If an event occours each registered event function is called.
|
||||
# If an event occurs each registered event function is called.
|
||||
#
|
||||
# Events run in the same context as the main bashbot event loop
|
||||
# so variables set here are persistent as long bashbot is running.
|
||||
@ -16,7 +16,7 @@
|
||||
# e.g. "(long running) &"
|
||||
#
|
||||
|
||||
# Availible events:
|
||||
# Available events:
|
||||
# on events startbot and init, this file is sourced
|
||||
#
|
||||
# BASHBOT_EVENT_INLINE inline query received
|
||||
@ -30,7 +30,7 @@
|
||||
# BASHBOT_EVENT_FILE file received
|
||||
#
|
||||
# BAHSBOT_EVENT_TIMER this event is a bit special as it fires every Minute
|
||||
# and has 3 meanings: oneshot, everytime, every X minutes.
|
||||
# and has 3 meanings: oneshot, every time, every X minutes.
|
||||
#
|
||||
# all global variables and functions can be used in registered functions.
|
||||
#
|
||||
@ -38,7 +38,7 @@
|
||||
# $1 event: init, startbot ...
|
||||
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||
#
|
||||
# prameters on events
|
||||
# parameters on events
|
||||
# $1 event: inline, message, ..., file
|
||||
# $2 key: key of array BASHBOT_EVENT_xxx
|
||||
# $3 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.98-dev-2-geb4fa68
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
@ -18,7 +18,7 @@
|
||||
# save default values
|
||||
TERM="" # disable bashbot clear and color output
|
||||
runas="nobody"
|
||||
runcmd="echo Dry run:" # not actived until you edit lines below
|
||||
runcmd="echo Dry run:" # not activated until you edit lines below
|
||||
|
||||
#######################
|
||||
# Configuration Section
|
||||
|
50
bashbot.sh
50
bashbot.sh
@ -11,20 +11,20 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.98-dev-67-g4fe9697
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
# - 0 success (hopefully)
|
||||
# - 1 can't change to dir
|
||||
# - 2 can't write to tmp, count or token
|
||||
# - 3 user / command / file not found
|
||||
# - 4 unkown command
|
||||
# - 4 unknown command
|
||||
# - 5 cannot connect to telegram bot
|
||||
# - 6 mandatory module not found
|
||||
# - 6 can't get bottoken
|
||||
# shellcheck disable=SC2140,SC2031,SC2120,SC1091
|
||||
|
||||
# are we runnig in a terminal?
|
||||
# are we running in a terminal?
|
||||
if [ -t 1 ] && [ -n "$TERM" ]; then
|
||||
CLEAR='clear'
|
||||
RED='\e[31m'
|
||||
@ -102,7 +102,7 @@ fi
|
||||
ADDONDIR="${BASHBOT_ETC:-.}/addons"
|
||||
RUNUSER="${USER}" # USER is overwritten by bashbot array
|
||||
|
||||
# OK everthing setup, lest start
|
||||
# OK everything setup, lest start
|
||||
if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then
|
||||
echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}"
|
||||
exit 1
|
||||
@ -132,7 +132,7 @@ DEBUGLOG="${LOGDIR}/DEBUG.log"
|
||||
ERRORLOG="${LOGDIR}/ERROR.log"
|
||||
UPDATELOG="${LOGDIR}/BASHBOT.log"
|
||||
|
||||
# we assume everthing is already set up correctly if we have TOKEN
|
||||
# we assume everything is already set up correctly if we have TOKEN
|
||||
if [ -z "${BOTTOKEN}" ]; then
|
||||
# BOTCONFIG does not exist, create
|
||||
[ ! -f "${BOTCONFIG}.jssh" ] &&
|
||||
@ -142,7 +142,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
||||
# convert old token
|
||||
if [ -r "${TOKENFILE}" ]; then
|
||||
token="$(< "${TOKENFILE}")"
|
||||
# no old token avalible ask user
|
||||
# no old token available ask user
|
||||
elif [ -z "${CLEAR}" ] && [ "$1" != "init" ]; then
|
||||
echo "Running headless, set BOTTOKEN or run ${SCRIPT} init first!"
|
||||
exit 2
|
||||
@ -304,14 +304,14 @@ procname(){
|
||||
printf '%s\n' "$2${ME}_$1"
|
||||
}
|
||||
|
||||
# $1 sting to search for proramm incl. parameters
|
||||
# retruns a list of PIDs of all current bot proceeses matching $1
|
||||
# $1 string to search for proramm incl. parameters
|
||||
# returns a list of PIDs of all current bot proceeses matching $1
|
||||
proclist() {
|
||||
# shellcheck disable=SC2009
|
||||
ps -fu "${UID}" | grep -F "$1" | grep -v ' grep'| grep -F "${ME}" | sed 's/\s\+/\t/g' | cut -f 2
|
||||
}
|
||||
|
||||
# $1 sting to search for proramm to kill
|
||||
# $1 string to search for proramm to kill
|
||||
killallproc() {
|
||||
local procid; procid="$(proclist "$1")"
|
||||
if [ -n "${procid}" ] ; then
|
||||
@ -338,7 +338,7 @@ get_file() {
|
||||
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
|
||||
}
|
||||
|
||||
# curl is preffered, but may not availible on ebedded systems
|
||||
# curl is preferred, but may not available on embedded systems
|
||||
TIMEOUT="${BASHBOT_TIMEOUT}"
|
||||
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
|
||||
|
||||
@ -433,7 +433,7 @@ sendJsonResult(){
|
||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "${1}")"
|
||||
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@:3}"
|
||||
return
|
||||
# hot path everthing OK!
|
||||
# hot path everything OK!
|
||||
else
|
||||
# oops something went wrong!
|
||||
if [ "${res}" != "" ]; then
|
||||
@ -466,7 +466,7 @@ sendJsonResult(){
|
||||
if [ "${BOTSENT[ERROR]}" == "999" ];then
|
||||
# check if default curl and args are OK
|
||||
if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then
|
||||
printf "%s: BASHBOT IP Adress is blocked!\n" "$(date)"
|
||||
printf "%s: BASHBOT IP Address is blocked!\n" "$(date)"
|
||||
# user provided function to recover or notify block
|
||||
if _exec_if_function bashbotBlockRecover; then
|
||||
BASHBOT_RETRY="2"
|
||||
@ -488,7 +488,7 @@ sendJsonResult(){
|
||||
fi
|
||||
} >>"${ERRORLOG}"
|
||||
|
||||
# escape / remove text charaters for json strings, eg. " -> \"
|
||||
# escape / remove text characters for json strings, eg. " -> \"
|
||||
# $1 string
|
||||
# output escaped string
|
||||
JsonEscape(){
|
||||
@ -512,7 +512,7 @@ getBotName() {
|
||||
getJson "$ME_URL" | "${JSONSHFILE}" -s -b -n 2>/dev/null | JsonGetString '"result","username"'
|
||||
}
|
||||
|
||||
# pure bash implementaion, done by KayM (@gnadelwartz)
|
||||
# pure bash implementation, done by KayM (@gnadelwartz)
|
||||
# see https://stackoverflow.com/a/55666449/9381171
|
||||
JsonDecode() {
|
||||
local out="$1" remain="" U=""
|
||||
@ -580,7 +580,7 @@ process_client() {
|
||||
fi
|
||||
#####
|
||||
# process inline and message events
|
||||
# first classic commnad dispatcher
|
||||
# first classic command dispatcher
|
||||
# shellcheck source=./commands.sh
|
||||
source "${COMMANDS}" "${debug}" &
|
||||
|
||||
@ -648,7 +648,7 @@ event_message() {
|
||||
# shellcheck disable=SC2153
|
||||
for key in "${!BASHBOT_EVENT_MESSAGE[@]}"
|
||||
do
|
||||
_exec_if_function "${BASHBOT_EVENT_MESSAGE[${key}]}" "messsage" "${key}" "${debug}"
|
||||
_exec_if_function "${BASHBOT_EVENT_MESSAGE[${key}]}" "message" "${key}" "${debug}"
|
||||
done
|
||||
|
||||
# ${TEXT[*]} event_text
|
||||
@ -696,7 +696,7 @@ event_message() {
|
||||
fi
|
||||
|
||||
# ${VENUE[*]} event_location
|
||||
# ${LOCALTION[*]} event_location
|
||||
# ${LOCATION[*]} event_location
|
||||
if [ -n "${LOCATION[LONGITUDE]}" ] || [ -n "${VENUE[TITLE]}" ]; then
|
||||
# shellcheck disable=SC2153
|
||||
for key in "${!BASHBOT_EVENT_LOCATION[@]}"
|
||||
@ -848,7 +848,7 @@ declare -A BASHBOTBLOCKED
|
||||
export BASHBOTDEBUG
|
||||
start_bot() {
|
||||
local ADMIN OFFSET=0
|
||||
# adaptive sleep deafults
|
||||
# adaptive sleep defaults
|
||||
local nextsleep="100" :
|
||||
local stepsleep="${BASHBOT_SLEEP_STEP:-100}"
|
||||
local maxsleep="${BASHBOT_SLEEP:-5000}"
|
||||
@ -911,7 +911,7 @@ start_bot() {
|
||||
process_updates "${BASHBOTDEBUG}"
|
||||
fi
|
||||
else
|
||||
# ups, something bad happend, wait maxsleep*10
|
||||
# ups, something bad happened, wait maxsleep*10
|
||||
(( nextsleep=nextsleep*2 , nextsleep= nextsleep>maxsleep*10 ?maxsleep*10:nextsleep ))
|
||||
[ "${OFFSET}" = "-999" ] &&\
|
||||
printf "%s: Repeated timeout/broken/no connection on telegram update, sleep %ds\n"\
|
||||
@ -963,7 +963,7 @@ bot_init() {
|
||||
}
|
||||
|
||||
if ! _is_function send_message ; then
|
||||
echo -e "${RED}ERROR: send_message is not availible, did you deactivate ${MODULEDIR}/sendMessage.sh?${NC}"
|
||||
echo -e "${RED}ERROR: send_message is not available, did you deactivate ${MODULEDIR}/sendMessage.sh?${NC}"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@ -1005,7 +1005,7 @@ if [ -z "${SOURCE}" ]; then
|
||||
[ -n "${CLEAR}" ] && printf "Bot Name: %s\n" "${ME}"
|
||||
[ "$1" = "botname" ] && exit
|
||||
;;&
|
||||
# used to send output of backgrond and interactive to chats
|
||||
# used to send output of background and interactive to chats
|
||||
"outproc") # $2 chat_id $3 identifier of job, internal use only!
|
||||
[ -z "$3" ] && echo "No job identifier" && exit 3
|
||||
[ -z "$2" ] && echo "No chat to send to" && exit 3
|
||||
@ -1112,7 +1112,7 @@ if [ -z "${SOURCE}" ]; then
|
||||
[ -n "${ADMIN}" ] && send_normal_message "${ADMIN}" "Bot ${ME} stopped ..." &
|
||||
echo -e "${GREEN}OK. Bot stopped successfully.${NC}"
|
||||
else
|
||||
echo -e "${RED}An error occured while stopping bot.${NC}"
|
||||
echo -e "${RED}An error occurred while stopping bot.${NC}"
|
||||
exit 5
|
||||
fi
|
||||
else
|
||||
@ -1120,9 +1120,9 @@ if [ -z "${SOURCE}" ]; then
|
||||
fi
|
||||
exit
|
||||
;;
|
||||
# suspend, resume or kill backgrund jobs
|
||||
# suspend, resume or kill background jobs
|
||||
"suspendb"*|"resumeb"*|"killb"*)
|
||||
_is_function job_control || { echo -e "${RED}Module background is not availible!${NC}"; exit 3; }
|
||||
_is_function job_control || { echo -e "${RED}Module background is not available!${NC}"; exit 3; }
|
||||
ME="$(getConfigKey "botname")"
|
||||
job_control "$1"
|
||||
;;
|
||||
|
@ -8,14 +8,14 @@
|
||||
# | |__/ / |_| | | | | | |_| | |__ | |____( (_| | | |__ _
|
||||
# |_____/ \___/ |_| |_|\___/ \___) |_______)____|_|\___)_|
|
||||
#
|
||||
# this file *MUST* not be edited! palce your config and commands in
|
||||
# this file *MUST* not be edited! place your config and commands in
|
||||
# the file "mycommnds.sh". a clean version is provided as "mycommands.clean"
|
||||
#
|
||||
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
|
||||
# adjust your language setting here, e.g.when run from other user or cron.
|
||||
@ -83,7 +83,7 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
|
||||
# forward iinline query to optional dispatcher
|
||||
_exec_if_function myinlines
|
||||
|
||||
# regular (gobal) commands ...
|
||||
# regular (global) commands ...
|
||||
# your commands are in mycommands()
|
||||
else
|
||||
|
||||
@ -128,7 +128,7 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
|
||||
unban_chat_member "${CHAT[ID]}" "${USER[ID]}"
|
||||
;;
|
||||
|
||||
'/'*) # discard all unkown commands
|
||||
'/'*) # discard all unknown commands
|
||||
: ;;
|
||||
*) # forward message to interactive chats
|
||||
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||
|
2
db.json
2
db.json
@ -3,7 +3,7 @@
|
||||
{
|
||||
"ok":true,
|
||||
"url":"https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/",
|
||||
"description":"Testing of JSON reponses for github.com/topkecleon/telegram-bot-bash"
|
||||
"description":"Testing of JSON responses for github.com/topkecleon/telegram-bot-bash"
|
||||
} ,
|
||||
"false":
|
||||
{
|
||||
|
@ -5,7 +5,7 @@
|
||||
# If you your bot is finished you can use make-standalone.sh to create the
|
||||
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
|
||||
#
|
||||
#### $$VERSION$$ v0.98-dev-64-gcac1ea4
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
@ -88,6 +88,6 @@ echo "Done!"
|
||||
|
||||
cd .. || exit 1
|
||||
|
||||
echo -e "\\nStandalone bashbot files are now availible in \"${DISTDIR}\":\\n"
|
||||
echo -e "\\nStandalone bashbot files are now available in \"${DISTDIR}\":\\n"
|
||||
ls -l "${DISTDIR}"
|
||||
|
||||
|
@ -24,7 +24,7 @@ As an alternative to download the zip files, you can clone the github repository
|
||||
* /usr/local if you want to run as service
|
||||
2. Run ```git clone https://github.com/topkecleon/telegram-bot-bash.git```
|
||||
3. Change into the directory ```telegram-bot-bash```
|
||||
4. Run ``` test/ALL-tests.sh``` and if everthing finish OK ...
|
||||
4. Run ``` test/ALL-tests.sh``` and if everything finish OK ...
|
||||
5. Run ```sudo ./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather.
|
||||
|
||||
### Update bashbot
|
||||
@ -67,7 +67,7 @@ Bashbot will stay with /bin/bash shebang, as using a fixed path is more secure t
|
||||
|
||||
#### removal of TMUX
|
||||
From version 0.80 on TMUX is no longer needed and the bachsbot command 'attach' is deleted. Old function 'inproc'
|
||||
is replaced by 'send_interactive'. send_interactive does checks if an interactive job is running internaly.
|
||||
is replaced by 'send_interactive'. send_interactive does checks if an interactive job is running internally.
|
||||
Pls check if you make use of inproc and remove it including the old checks, e.g.
|
||||
```bash
|
||||
if tmux ls | grep -v send | grep -q "$copname"; then inproc; fi
|
||||
@ -88,8 +88,8 @@ From version 0.70 on the tmp dir is renamed to 'data-bot-bash' to reflect the fa
|
||||
From version 0.50 on the temporary files are no more placed in '/tmp'. instead a dedicated tmp dir is used.
|
||||
|
||||
#### Changes to send_keyboard in v0.6
|
||||
From Version 0.60 on keybord format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed.
|
||||
Keybords are now defined in JSON Array notation e.g. "[ \\"yes\\" , \\"no\\" ]".
|
||||
From Version 0.60 on keyboard format for ```send_keyboard``` and ```send_message "mykeyboardstartshere ..."``` was changed.
|
||||
Keyboards are now defined in JSON Array notation e.g. "[ \\"yes\\" , \\"no\\" ]".
|
||||
This has the advantage that you can create any type of keyboard supported by Telegram.
|
||||
The old format is supported for backward compatibility, but may fail for corner cases.
|
||||
|
||||
@ -107,5 +107,5 @@ The old format is supported for backward compatibility, but may fail for corner
|
||||
|
||||
#### [Next Create Bot](1_firstbot.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-39-g35d5e05
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -19,7 +19,7 @@ Have FUN!
|
||||
.
|
||||
├── mycommands.sh # THIS is your bot, place logic and commands here!
|
||||
│
|
||||
├── mycommands.sh.clean # copy to "mycommands.sh" if you start devloping your bot
|
||||
├── mycommands.sh.clean # copy to "mycommands.sh" if you start developing your bot
|
||||
├── mycommands.sh.dist # example bot, also used for testing bashbot internally
|
||||
│
|
||||
├── count.jssh # count bashbot usage in jssh key-value store
|
||||
@ -37,12 +37,12 @@ Have FUN!
|
||||
├── modules # optional functions, sourced by commands.sh
|
||||
│ ├── aliases.sh # to disable modules rename them xxx.sh.off
|
||||
│ ├── answerInline.sh
|
||||
│ ├── jsshDB.sh # read and store JSON.sh stlye JSON, mandatory
|
||||
│ ├── jsshDB.sh # read and store JSON.sh style JSON, mandatory
|
||||
│ ├── background.sh # interactive and background functions
|
||||
│ ├── chatMember.sh
|
||||
│ └── sendMessage.sh # main send message functions, mandatory
|
||||
│
|
||||
├── addons # optional addons, disbaled by default
|
||||
├── addons # optional addons, disabled by default
|
||||
│ ├── example.sh # to enable addons change their XXX_ENABLE to true
|
||||
│ ├── antiFlood.sh # simple addon taking actions based on # files and text sent to chat
|
||||
│ └── xxxxxage.sh
|
||||
@ -120,9 +120,9 @@ These Variables are always present in regular messages:
|
||||
|
||||
The following variables are set if the message contains optional parts:
|
||||
|
||||
* ```$REPLYTO```: Original message wich was replied to
|
||||
* ```$REPLYTO```: Original message which was replied to
|
||||
* ```$REPLYTO```: This array contains the First name, last name, username and user id of the ORIGINAL sender of the message REPLIED to.
|
||||
* ```${REPLYTO[ID]}```: ID of message wich was replied to
|
||||
* ```${REPLYTO[ID]}```: ID of message which was replied to
|
||||
* ```${REPLYTO[UID]}```: Original user's id
|
||||
* ```${REPLYTO[FIRST_NAME]}```: Original user's first name
|
||||
* ```${REPLYTO[LAST_NAME]}```: Original user's' last name
|
||||
@ -166,7 +166,7 @@ client, e.g. new users.
|
||||
If a service message is received bashbot sets MESSAGE to the service message type as a command,
|
||||
e.g. if a new user joins a chat MESSAGE is set to "/new_chat_user".
|
||||
|
||||
* ```$SERVICE```: This array contains info abbout recived service messages.
|
||||
* ```$SERVICE```: This array contains info about received service messages.
|
||||
* ```${SERVICE}```: "yes" if service message is received
|
||||
* ```${SERVICE[NEWMEMBER]```: New user's id
|
||||
* ```${MESSAGE}```: /new_chat_member
|
||||
@ -194,7 +194,7 @@ e.g. if a new user joins a chat MESSAGE is set to "/new_chat_user".
|
||||
### Inline query messages
|
||||
|
||||
Inline query messages are small, non regular messages used for interaction with the user,
|
||||
they contain the following varibles only:
|
||||
they contain the following variables only:
|
||||
|
||||
* ```${iQUERY}```: Current inline query
|
||||
* ```$iQUERY```: This array contains the ID, First name, last name, username and user id of the sender of the current inline query.
|
||||
@ -260,8 +260,8 @@ send_file "${CHAT[ID]}" "/home/user/doge.jpg" "Lool"
|
||||
```
|
||||
To send custom keyboards use the ```send_keyboard``` function:
|
||||
```bash
|
||||
send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" '[ "Yep" , "No" ]' # note the simgle quotes!
|
||||
send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" "[ \\"Yep\\" , \\"No\\" ]" # within double quotes you must excape the inside double quots
|
||||
send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" '[ "Yep" , "No" ]' # note the single quotes!
|
||||
send_keyboard "${CHAT[ID]}" "Text that will appear in chat?" "[ \\"Yep\\" , \\"No\\" ]" # within double quotes you must escape the inside double quots
|
||||
```
|
||||
To send locations use the ```send_location``` function:
|
||||
```bash
|
||||
@ -281,5 +281,5 @@ send_action "${CHAT[ID]}" "action"
|
||||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -29,7 +29,7 @@ In addition you can check individual capabilities of users as you must define in
|
||||
# a user not listed here, will return false from 'user_is_allowed'
|
||||
#
|
||||
# Format:
|
||||
# user:ressource:chat
|
||||
# user:resource:chat
|
||||
|
||||
# allow user 123456789 access to all resources in all chats
|
||||
123456789:*:*
|
||||
@ -66,7 +66,7 @@ You must use the function ```user_is_allowed``` to check if a user has the capab
|
||||
### Interactive Chats
|
||||
Interactive chats are short running scripts, reading user input and echo data to the user.
|
||||
|
||||
To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewinteractive.sh', make it executeable
|
||||
To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewinteractive.sh', make it executable
|
||||
and then use 'start_proc' function from your bot, it's possible to pass two arguments. You find more examples for interactive scripts in 'examples'
|
||||
|
||||
*usage*: start_proc chat_id script arg1 arg2
|
||||
@ -82,7 +82,7 @@ and then use 'start_proc' function from your bot, it's possible to pass two argu
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to start_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to start_proc chat script arg1 arg2
|
||||
# $3 path to named pipe
|
||||
|
||||
#######################
|
||||
@ -110,7 +110,7 @@ echo "Text that will appear in chat? myfilelocationstartshere /home/user/doge.jp
|
||||
```
|
||||
And buttons:
|
||||
```bash
|
||||
echo "Text that will appear in chat. mybtextstartshere Klick me myburlstartshere https://dealz.rrr.de"
|
||||
echo "Text that will appear in chat. mybtextstartshere Click me myburlstartshere https://dealz.rrr.de"
|
||||
```
|
||||
And locations:
|
||||
```bash
|
||||
@ -144,7 +144,7 @@ echo "$out"
|
||||
A background job is similar to an interactive chat, but can be a long running job and does only output massages, user input is ignored.
|
||||
It's possible to run multiple background jobs from the same chat.
|
||||
|
||||
To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewbackground.sh', make it executeable
|
||||
To create a new interactive chat script copy 'scripts/interactive.sh.clean' to e.g. 'scripts/mynewbackground.sh', make it executable
|
||||
and then use 'start_back' function from your bot, it's possible to pass two arguments. You find more examples for background scripts in 'examples'
|
||||
|
||||
*usage*: start_back chat_id script jobname arg1 arg2
|
||||
@ -166,21 +166,21 @@ You can also suspend and resume currently running background jobs from outside b
|
||||
./bashbot.sh resumeback
|
||||
```
|
||||
|
||||
If you want to kill all background jobs permantly run:
|
||||
If you want to kill all background jobs permanently run:
|
||||
```bash
|
||||
./bashbot.sh killback
|
||||
|
||||
```
|
||||
Note: Background jobs run independent from main bot and continue running until your script exits or you stop it. Backgound jobs will continue running if your Bot is stoped and must be terminated seperatly e.g. by ```bashbot.sh killback```
|
||||
Note: Background jobs run independent from main bot and continue running until your script exits or you stop it. Background jobs will continue running if your Bot is stopped and must be terminated separately e.g. by ```bashbot.sh killback```
|
||||
|
||||
### Inline queries
|
||||
**Inline queries** allow users to send commands to your bot from every chat without going to a private chat. An inline query is started if the user type the bots name, e.g. @myBot. Everything after @myBot is immediatly send to the bot.
|
||||
**Inline queries** allow users to send commands to your bot from every chat without going to a private chat. An inline query is started if the user type the bots name, e.g. @myBot. Everything after @myBot is immediately send to the bot.
|
||||
|
||||
In order to enable **inline mode**, send `/setinline` command to [@BotFather](https://telegram.me/botfather) and provide the placeholder text that the user will see in the input field after typing your bot’s name.
|
||||
|
||||
The following commands allows you to send ansers to *inline queries*. To enable bashbot to process inline queries set ```INLINE="1"``` in 'mycommands.sh'.
|
||||
|
||||
To send messsages or links through an *inline query*:
|
||||
To send messages or links through an *inline query*:
|
||||
```bash
|
||||
answer_inline_query "${iQUERY[ID]}" "article" "Title of the result" "Content of the message to be sent"
|
||||
```
|
||||
@ -223,7 +223,7 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli
|
||||
|
||||
Our examples usually do not care about errors happening while sending a message, this is OK as long your bot does not send an
|
||||
massive aoumnt of messages. By default bashbot detects if a message is not sent and try to recover when possible,
|
||||
e.g. resend on throttling. In addtion every send error is logged in logs/ERROR.log
|
||||
e.g. resend on throttling. In addition every send error is logged in logs/ERROR.log
|
||||
|
||||
|
||||
#### Transmission results
|
||||
@ -236,7 +236,7 @@ every send action will overwrite them!
|
||||
|
||||
* ```$BOTSENT```: This array contains the parsed results from the last transmission to telegram.
|
||||
* ```${BOTSENT[OK]}```: contains the string ```true```: after a successful transmission
|
||||
* ```${BOTSENT[ERROR]}```: Error code if an error occured
|
||||
* ```${BOTSENT[ERROR]}```: Error code if an error occurred
|
||||
* ```${BOTSENT[DESC]}```: Description text for error
|
||||
* ```${BOTSENT[RETRY]}```: Seconds to wait if telegram requests throtteling.
|
||||
* ```$res```: temporary variable containing the full transmission result, may be overwritten by any bashbot function.
|
||||
@ -279,7 +279,7 @@ Note: If you disable automatic retry, se above, you disable also connection prob
|
||||
# may be we removed block, e.g. changed IP address, try again
|
||||
return 0
|
||||
fi
|
||||
# do not retry if we cant recover
|
||||
# do not retry if we can't recover
|
||||
return 1
|
||||
}
|
||||
|
||||
@ -289,5 +289,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob
|
||||
#### [Prev Getting started](2_usage.md)
|
||||
#### [Next Expert Use](4_expert.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -33,9 +33,9 @@ export 'LC_ALL=en_US.UTF-8'
|
||||
export 'LANG=de_en_US.UTF-8'
|
||||
export 'LANGUAGE=den_US.UTF-8'
|
||||
```
|
||||
3. make shure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts
|
||||
3. make sure your bot scripts use the correct settings, eg. include the lines above at the beginning of your scripts
|
||||
|
||||
To display all availible locales on your system run ```locale -a | more```. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8)
|
||||
To display all available locales on your system run ```locale -a | more```. [Gentoo Wiki](https://wiki.gentoo.org/wiki/UTF-8)
|
||||
|
||||
#### Bashbot UTF-8 Support
|
||||
Bashbot handles all messages transparently, regardless of the charset in use. The only exception is when converting from JSON data to strings.
|
||||
@ -46,11 +46,11 @@ The Emoticons ``` 😁 😘 ❤️ 😊 👍 ``` are encoded as: ``` \uD83D\uDE0
|
||||
**This "mixed" JSON encoding needs special handling and can not decoded from** ```echo -e``` or ```printf '%s\\n'```
|
||||
|
||||
Most complete support for decoding of multibyte characters can only be provided if python is installed on your system.
|
||||
**Without phyton bashbot falls back to an internal, pure bash implementation which may not work for some corner cases**.
|
||||
**Without python bashbot falls back to an internal, pure bash implementation which may not work for some corner cases**.
|
||||
|
||||
|
||||
### Run as other user or system service
|
||||
Bashbot is desingned to run manually by the user who installed it. Nevertheless it's possible to run it by an other user-ID, as a system service or scheduled from cron. This is onyl recommended for experiend linux users.
|
||||
Bashbot is desingned to run manually by the user who installed it. Nevertheless it's possible to run it by an other user-ID, as a system service or scheduled from cron. This is only recommended for experiend linux users.
|
||||
|
||||
Setup the environment for the user you want to run bashbot and enter desired username, e.g. nobody :
|
||||
```bash
|
||||
@ -82,7 +82,7 @@ sudo ./bashbot.rc start
|
||||
```
|
||||
Type ```ps -ef | grep bashbot``` to verify your Bot is running as the desired user.
|
||||
|
||||
If your Bot is started by 'bashbot.rc', you must use 'bashbot.rc' also to manage your Bot! The following commands are availible:
|
||||
If your Bot is started by 'bashbot.rc', you must use 'bashbot.rc' also to manage your Bot! The following commands are available:
|
||||
```bash
|
||||
sudo ./bashbot.rc start
|
||||
sudo ./bashbot.rc stop
|
||||
@ -93,7 +93,7 @@ sudo ./bashbot.rc killback
|
||||
```
|
||||
To change back the environment to your user-ID run ```sudo ./bashbot.sh init``` again and enter your user name.
|
||||
|
||||
To use bashbot as a system servive include a working ```bashbot.rc``` in your init system (systemd, /etc/init.d).
|
||||
To use bashbot as a system service include a working ```bashbot.rc``` in your init system (systemd, /etc/init.d).
|
||||
|
||||
### Schedule bashbot from Cron
|
||||
An example crontab is provided in ```examples/bashbot.cron```.
|
||||
@ -133,7 +133,7 @@ source /path/to/bashbot.sh source
|
||||
```
|
||||
|
||||
#### Environment variable exported from bashbot
|
||||
If you have sourced 'bashbot.sh' you have the following bashot internal variables availible:
|
||||
If you have sourced 'bashbot.sh' you have the following bashot internal variables available:
|
||||
```bash
|
||||
COMMANDS # default: ./commands.sh"
|
||||
MODULEDIR # default: ./modules"
|
||||
@ -251,7 +251,7 @@ Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.
|
||||
Set bashbot home directory, where bashot will look for additional files.
|
||||
If BASHBOT_ETC, BASHBOT_VAR or BASHBOT_JSONSH are set the have precedence over BASHBOT_HOME.
|
||||
|
||||
This is also usefull if you want to force bashbot to always use full pathnames instead of relative ones.
|
||||
This is also useful if you want to force bashbot to always use full pathnames instead of relative ones.
|
||||
```bash
|
||||
unset BASHBOT_HOME # autodetection (default)
|
||||
export BASHBOT_HOME "" # autodetection
|
||||
@ -265,7 +265,7 @@ This is also usefull if you want to force bashbot to always use full pathnames i
|
||||
#### Change config values
|
||||
|
||||
##### BASHBOT_URL
|
||||
Uses given URL instead of offical telegram API URL, useful if you have your own telegram server or for testing.
|
||||
Uses given URL instead of official telegram API URL, useful if you have your own telegram server or for testing.
|
||||
|
||||
```bash
|
||||
unset BASHBOT_URL # use Telegram URL https://api.telegram.org/bot<token> (default)
|
||||
@ -299,8 +299,8 @@ set BASHBOT_CURL to point to it.
|
||||
```
|
||||
|
||||
##### BASHBOT_WGET
|
||||
Bashbot uses ```curl``` to communicate with telegram server. if ```curl``` is not availible ```wget``` is used.
|
||||
If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used even is curl is availible.
|
||||
Bashbot uses ```curl``` to communicate with telegram server. if ```curl``` is not available ```wget``` is used.
|
||||
If 'BASHBOT_WGET' is set to any value (not undefined or not empty) wget is used even is curl is available.
|
||||
```bash
|
||||
unset BASHBOT_WGET # use curl (default)
|
||||
export BASHBOT_WGET "" # use curl
|
||||
@ -326,7 +326,7 @@ BASHBOT_TIMEOUT to a numeric value between 1 and 999. Any non numeric or negativ
|
||||
|
||||
##### BASHBOT_SLEEP
|
||||
Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling.
|
||||
If messages are received bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay
|
||||
If messages are received bashbot polls with no dealy. If no messages are available bashbot add 100ms delay
|
||||
for every poll until the maximum of BASHBOT_SLEEP ms.
|
||||
```bash
|
||||
unset BASHBOT_SLEEP # 5000ms (default)
|
||||
@ -360,7 +360,7 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
|
||||
/usr/local/bin/bashbot.sh start
|
||||
```
|
||||
|
||||
##### simple multibot config, everything is keept inside 'telegram-bot-bash' dir
|
||||
##### simple multibot config, everything is kept inside 'telegram-bot-bash' dir
|
||||
```bash
|
||||
# config for running Bot 1
|
||||
# Note: all dirs and files must exist!
|
||||
@ -382,5 +382,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
|
||||
#### [Prev Advanced Use](3_advanced.md)
|
||||
#### [Next Best Practice](5_practice.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -127,7 +127,7 @@ Line 17:
|
||||
^-- SC2116: Useless echo? Instead of 'cmd $(echo foo)', just use 'cmd foo'.
|
||||
|
||||
```
|
||||
As you can see my ```mybotcommands.inc.sh``` contains an useless echo command in 'TEXT=' assigment and can be replaced by ```TEXT="${TEXT}${WORD}"```
|
||||
As you can see my ```mybotcommands.inc.sh``` contains an useless echo command in 'TEXT=' assignment and can be replaced by ```TEXT="${TEXT}${WORD}"```
|
||||
```bash
|
||||
$ shellcheck -x examples/notify
|
||||
OK
|
||||
@ -146,11 +146,11 @@ In bashbot.sh line 490:
|
||||
CONTACT[USER_ID]="$(sed -n -e '/\["result",'$PROCESS_NUMBER',"message","contact","user_id"\]/ s/.*\][ \t]"\(.*\)"$/\1/p' <"$TMP")"
|
||||
^-- SC2034: CONTACT appears unused. Verify it or export it.
|
||||
```
|
||||
The example show two warnings in bashbots scripts. The first is a hint you may use shell substitions instead of sed, this is fixed and much faster as the "echo | sed" solution.
|
||||
The example show two warnings in bashbots scripts. The first is a hint you may use shell substitutions instead of sed, this is fixed and much faster as the "echo | sed" solution.
|
||||
The second warning is about an unused variable, this is true because in our examples CONTACT is not used but assigned in case you want to use it :-)
|
||||
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Functions Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -61,7 +61,7 @@ send_normal_message "${CHAT[ID]}" "<b>bold</b> <i>italic><i> <em>italic>/em> <a
|
||||
```
|
||||
|
||||
##### forward_message
|
||||
```forward_mesage``` forwards a messsage to the given chat.
|
||||
```forward_mesage``` forwards a message to the given chat.
|
||||
|
||||
*usage:* forward_message "chat_to" "chat_from" "${MESSAGE[ID]}"
|
||||
|
||||
@ -69,7 +69,7 @@ send_normal_message "${CHAT[ID]}" "<b>bold</b> <i>italic><i> <em>italic>/em> <a
|
||||
|
||||
*alias:* _forward "$FROMCHAT" "${MESSAGE[ID]}"
|
||||
|
||||
See also [Text formating options](https://core.telegram.org/bots/api#formatting-options)
|
||||
See also [Text formatting options](https://core.telegram.org/bots/api#formatting-options)
|
||||
|
||||
----
|
||||
|
||||
@ -103,8 +103,8 @@ Starting with version 0.80 send_file implements the following rules:
|
||||
|
||||
- file names must not contain ".."
|
||||
- file names must not start with "."
|
||||
- file names not starting wit "/" are realtive to $TMPDIR, e.g. ./data-bot-bash
|
||||
- abolute filenames must match $FILE_REGEX
|
||||
- file names not starting with "/" are relative to $TMPDIR, e.g. ./data-bot-bash
|
||||
- absolute filenames must match $FILE_REGEX
|
||||
- FILE_REGEX is a regular expression, not shell globbing, test you rexexes: http://www.softlion.com/webTools/RegExpTest/
|
||||
|
||||
*usage:* send_file "${CHAT[ID]}" "file" "caption"
|
||||
@ -175,7 +175,7 @@ This allows to place multiple inline buttons in a row. The inline buttons must s
|
||||
|
||||
```[ {"text":"text1", "url":"url1"}, ... {"text":"textN", "url":"urlN"} ]```
|
||||
|
||||
Each button consists of a pair of text and URL values, sourrounded by '{ }', multiple buttons are separated by '**,**' and everthing is wrapped in '[ ]'.
|
||||
Each button consists of a pair of text and URL values, sourrounded by '{ }', multiple buttons are separated by '**,**' and everything is wrapped in '[ ]'.
|
||||
|
||||
*usage:* send_inline_keyboard "chat-id" "message" "[ {"text":"text", "url":"url"} ...]"
|
||||
|
||||
@ -333,7 +333,7 @@ Currently the following types and arguments are implemented (optional arguments
|
||||
"document" title document_URL mime_type (caption description parse_mode)
|
||||
|
||||
"location" latitude longitude title
|
||||
"venue" latitude longitude title (adress foursquare)
|
||||
"venue" latitude longitude title (address foursquare)
|
||||
"contact" phone first (last thumb)
|
||||
|
||||
"cached_photo" file (title description caption parse_mode keyboard)
|
||||
@ -463,7 +463,7 @@ Usually a message is automatically forwarded in 'commands.sh', but you can forwa
|
||||
|
||||
### jsshDB
|
||||
Since output generated by JSON.sh is so handy to use in bash, we use the format for a simple keys/value file store.
|
||||
The file extentions is '.jssh' and for security reasons location of jssh files is restricted to BASHBOT_ETC and BASHBOT_DATA..
|
||||
The file extensions is '.jssh' and for security reasons location of jssh files is restricted to BASHBOT_ETC and BASHBOT_DATA..
|
||||
|
||||
#### fast and slow operations
|
||||
|
||||
@ -515,7 +515,7 @@ In case flock is not availibe or you don't want locking, jssh_*DB_async function
|
||||
```
|
||||
|
||||
##### jssh_newDB
|
||||
Creats new empty jsshDB file if not exist.
|
||||
Creates new empty jsshDB file if not exist.
|
||||
|
||||
*usage:* jssh_newDB "filename"
|
||||
|
||||
@ -556,7 +556,7 @@ Something wrong with data-bot-bash/../../../somevalues
|
||||
```
|
||||
|
||||
##### jssh_writeDB
|
||||
Write content of an ARRAY into jsshDB file. ARRAY name must be delared with "declare -A ARRAY" before calling writeDB.
|
||||
Write content of an ARRAY into jsshDB file. ARRAY name must be declared with "declare -A ARRAY" before calling writeDB.
|
||||
"DB" file MUST exist or nothing is written.
|
||||
|
||||
Note: Existing content is overwritten.
|
||||
@ -567,7 +567,7 @@ Note: Existing content is overwritten.
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
# Prepare array to store vaules
|
||||
# Prepare array to store values
|
||||
declare -A WRITEVALUES
|
||||
|
||||
WRITEVALUES["value1"]="example"
|
||||
@ -582,7 +582,7 @@ jssh_newDB "${DATADIR:-.}/myvalues"
|
||||
# write to file data-bot-bash/somevalues.jssh from array MYVALUES
|
||||
jssh_writeDB "WRITEVALUES" "${DATADIR:-}/myvalues"
|
||||
|
||||
# show whats written
|
||||
# show what's written
|
||||
cat "${DATADIR:-}/myvalues.jssh"
|
||||
["value1"] "example"
|
||||
["value2"] "a value"
|
||||
@ -598,7 +598,7 @@ Print content of an ARRAY to STDOUT. ARRAY name must be declared with "declare -
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
# Prepare array to store vaules
|
||||
# Prepare array to store values
|
||||
declare -A PRINTVALUES
|
||||
|
||||
# read file data-bot-bash/myvalues.jssh into array READVALUES
|
||||
@ -632,7 +632,7 @@ MYVALUES["newvalue"]="this is new"
|
||||
# update file data-bot-bash/somevalues.jssh from array MYVALUES
|
||||
jssh_updateDB "MYVALUES" "${DATADIR:-.}/myvalues"
|
||||
|
||||
# show whats written
|
||||
# show what's written
|
||||
["value1"] "value1"
|
||||
["loveit"] "value2"
|
||||
["whynot"] "value3"
|
||||
@ -642,7 +642,7 @@ jssh_updateDB "MYVALUES" "${DATADIR:-.}/myvalues"
|
||||
cat "$DBfile"
|
||||
jssh_writeDB "MYVALUES" "${DATADIR:-.}/myvalues"
|
||||
|
||||
# show whats written, ups!
|
||||
# show what's written, ups!
|
||||
cat "$DBfile"
|
||||
["newvalue"] "this is new"
|
||||
|
||||
@ -660,7 +660,7 @@ Maximum timeout for reading is 1s to not block readers.
|
||||
|
||||
*example:*
|
||||
```bash
|
||||
# Prepare array to read vaules
|
||||
# Prepare array to read values
|
||||
declare -A READVALUES
|
||||
|
||||
# read file data-bot-bash/myvalues.jssh into array READVALUES
|
||||
@ -679,7 +679,7 @@ jssh_printDB READVALUES
|
||||
["whynot","subindex1"] "whynot A"
|
||||
|
||||
|
||||
# access Arrray
|
||||
# access Array
|
||||
echo "${READVALUES[vaule2]}"
|
||||
a value
|
||||
|
||||
@ -710,7 +710,7 @@ Insert, update, append a key=value pair to a jsshDB file, key name is only allow
|
||||
|
||||
*usage:* jssh_insertKeyDB_asnyc "key" "value" "filename"
|
||||
|
||||
*deprecated:* jssh_insertDB *was renamed in verion 0.96 to* jssh_insertKeyDB
|
||||
*deprecated:* jssh_insertDB *was renamed in version 0.96 to* jssh_insertKeyDB
|
||||
|
||||
Note: inserKeytDB uses also excusive write locking, but with a maximum timeout of 2s. insertKeyDB is a "fast" operation, simply adding the value to the end of the file.
|
||||
|
||||
@ -735,7 +735,7 @@ jssh_deleteKeyDB "delkey"" "${DATADIR:-.}/myvalues"
|
||||
Increase a key=value pair from a jsshDB file by 1, key name is only allowed to contain '-a-zA-Z0-9,._'
|
||||
If value is given key is increased by value.
|
||||
|
||||
Side effect: if value is given key is updated "in place" (slower) and file is cleand up, if no value is given fast path is used
|
||||
Side effect: if value is given key is updated "in place" (slower) and file is cleaned up, if no value is given fast path is used
|
||||
and new count is added to the end of file.
|
||||
|
||||
*usage:* jssh_countKeyDB "key" "filename" ["value"]
|
||||
@ -854,7 +854,7 @@ Do not use them in bashbot.sh, modules and addons.
|
||||
### Helper functions
|
||||
|
||||
##### download
|
||||
Download the fiven URL ans returns the final filename in TMPDIR. If the given filename exists,the filename is prefixed with a
|
||||
Download the fiven URL and returns the final filename in TMPDIR. If the given filename exists,the filename is prefixed with a
|
||||
random number. Filename is not allowed to contain '/' or '..'.
|
||||
|
||||
*usage:* download URL filename
|
||||
@ -876,7 +876,7 @@ Returns true, even if the given function does not exist. Return false if functio
|
||||
```bash
|
||||
_exec_if_function "answer_inline_query" "${iQUERY[ID]}" "Answer params"
|
||||
|
||||
# fast replacment for module functions exists check:
|
||||
# fast replacement for module functions exists check:
|
||||
if _is_function "answer_inline_query"
|
||||
then
|
||||
"answer_inline_query" "${iQUERY[ID]}" "Answer params"
|
||||
@ -919,7 +919,7 @@ Returns PrefixBotname_Postfix
|
||||
```bash
|
||||
# returns botname, if already set
|
||||
procname
|
||||
# returns unique identifier for everthing related to chat
|
||||
# returns unique identifier for everything related to chat
|
||||
procname "${CHAT[ID]}"
|
||||
# returns unique identifier for job, regardless of chat
|
||||
procname "" "back-jobname-"
|
||||
@ -980,7 +980,7 @@ Reads JSON from STDIN and Outputs found String to STDOUT
|
||||
*usage:* JsonGetString `"path","to","string"`
|
||||
|
||||
##### JsonGetValue
|
||||
Reads JSON fro STDIN and Outputs found Value to STDOUT
|
||||
Reads JSON from STDIN and Outputs found Value to STDOUT
|
||||
|
||||
*usage:* JsonGetValue `"path","to","value"`
|
||||
|
||||
@ -1035,5 +1035,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$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -11,7 +11,7 @@ If you want to get error messages (and more) start bashbot ```./bashbot.sh star
|
||||
you can the change the level of verbosity of the debug argument:
|
||||
|
||||
```
|
||||
"debug" all output is redirected to "DEBUG.log", in addtion every incomming message is logged in "MESSAGE.log" and "INLINE.log"
|
||||
"debug" all output is redirected to "DEBUG.log", in addition every incoming message is logged in "MESSAGE.log" and "INLINE.log"
|
||||
"xdebug" same as debug plus set bash option '-x' to log any executed command in "DEBUG.log"
|
||||
|
||||
use the command tail to watch your bot live, e.g. "tail -f DEBUG.log", to obtain more information place set -x; set +x in your code.
|
||||
@ -28,19 +28,19 @@ you can the change the level of verbosity of the debug argument:
|
||||
|
||||
### Modules and Addons
|
||||
**Modules** resides in ```modules/*.sh``` and are colletions of optional bashbot functions grouped by functionality. Main reason for creating modules was
|
||||
to keep 'bashbot.sh' small, while extending functionality. In addition not every funtion is needed by all bots, so you can
|
||||
to keep 'bashbot.sh' small, while extending functionality. In addition not every function is needed by all bots, so you can
|
||||
disable modules, e.g. by rename the respective module file to 'module.sh.off'.
|
||||
|
||||
Modules must use only functions provided by 'bahsbot.sh' or the module itself and sould not depend on other modules or addons.
|
||||
Modules must use only functions provided by 'bahsbot.sh' or the module itself and should not depend on other modules or addons.
|
||||
The only mandatory module is 'module/sendMessage.sh'.
|
||||
|
||||
If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ```_is_function``` or
|
||||
```_execute_if_function``` is mandatory to catch absense of the module.
|
||||
```_execute_if_function``` is mandatory to catch absence of the module.
|
||||
|
||||
**Addons** resides in ```addons/*.sh.dist``` and are not endabled by default. To activate an addon rename it to end with '.sh', e.g. by
|
||||
```cp addons/example.sh.dist addons/example.sh```.
|
||||
|
||||
Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is received.
|
||||
Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function every time a message is received.
|
||||
Addons works similar as 'commands.sh' and 'mycommands.sh' but are much more flexible on when functions/commands are triggered.
|
||||
|
||||
Another major difference is: While regular command processing is done in a new sub shell for every command,
|
||||
@ -53,7 +53,7 @@ This prevents blocking or exiting bashbots event loop.
|
||||
#### Bashbot Events
|
||||
|
||||
Addons must register functions to bashbot events by providing their name, and internal identifier and a callback function.
|
||||
If an event occours each registered function for the event is called.
|
||||
If an event occurs each registered function for the event is called.
|
||||
|
||||
Registered functions run in the same process as bashbot, not as a sub process, so variables set here are persistent as long bashbot is running.
|
||||
|
||||
@ -61,7 +61,7 @@ Note: For the same reason event function MUST return immediately! Time consuming
|
||||
|
||||
##### SEND RECEIVE events
|
||||
|
||||
An RECEIVE event is executed when a Message is received, same iQuery / Message variables are avalible as in commands.sh
|
||||
An RECEIVE event is executed when a Message is received, same iQuery / Message variables are available as in commands.sh
|
||||
|
||||
* BASHBOT_EVENT_INLINE an inline query is received
|
||||
|
||||
@ -89,7 +89,7 @@ BASHBOT_EVENT_TEXT["example_1"]="example_echo"
|
||||
# function called if a text is received
|
||||
example_echo() {
|
||||
local event="$1" key="$2"
|
||||
# all availible bashbot functions and variables can be used
|
||||
# all available bashbot functions and variables can be used
|
||||
send_normal_message "${CHAT[ID]}" "Event: ${event} Key: ${key} : ${MESSAGE[0]}" & # run in background!
|
||||
|
||||
( MYTEXT="${MESSAGE[0]}"
|
||||
@ -100,9 +100,9 @@ example_echo() {
|
||||
|
||||
An SEND event is executed when a Message is send to telegram.
|
||||
|
||||
* BASHBOT_EVENT_SEND is exceuted if data is send or uploaded to Telegram server
|
||||
* BASHBOT_EVENT_SEND is executed if data is send or uploaded to Telegram server
|
||||
|
||||
In contrast to other events, BASHBOT_EVENT_SEND is excecuted in a sub shell, so there is no need to spawn
|
||||
In contrast to other events, BASHBOT_EVENT_SEND is executed in a sub shell, so there is no need to spawn
|
||||
a background process for longer running commands and changes to variables are not persistent!
|
||||
|
||||
BASHBOT_EVENT_SEND is for logging purposes, you must not send messages while processing this event.
|
||||
@ -110,7 +110,7 @@ To avoid wrong use of EVENT_SEND, e.g. fork bomb, event processing is suspended
|
||||
|
||||
*usage*: BASHBOT_EVENT_SEND[ "unique-name" ]="callback"
|
||||
|
||||
"callback" is called with paramter "send" or "upload", followed by the arguments used for 'sendJson' or 'upload' functions.
|
||||
"callback" is called with parameter "send" or "upload", followed by the arguments used for 'sendJson' or 'upload' functions.
|
||||
|
||||
*Example:*
|
||||
```bash
|
||||
@ -128,12 +128,12 @@ example_log(){
|
||||
|
||||
##### TIMER events
|
||||
|
||||
Important: Bashbot timer tick is diabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero.
|
||||
Important: Bashbot timer tick is disabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero.
|
||||
|
||||
* BAHSBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes.
|
||||
|
||||
Registering to BASHBOT_EVENT_TIMER works similar as for message events, but you must add a timing argument to the name.
|
||||
EVENT_TIMER is triggered every 60s and waits until the current running command is finished, so ist not excactly every
|
||||
EVENT_TIMER is triggered every 60s and waits until the current running command is finished, so it's not exactly every
|
||||
minute, but once a minute.
|
||||
|
||||
Every time EVENT_TIMER is triggered the variable "EVENT_TIMER" is increased. each callback is executed if ```EVENT_TIMER % time``` is '0' (true).
|
||||
@ -144,7 +144,7 @@ This means if you register an every 5 minutes callback first execution may < 5 M
|
||||
* 0 ignored
|
||||
* 1 execute once every minute
|
||||
* x execute every x minutes
|
||||
* -x execute once WHITHIN the next x Minutes (next 10 Minutes since start "event")
|
||||
* -x execute once WITHIN the next x Minutes (next 10 Minutes since start "event")
|
||||
|
||||
Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: ```-(EVENT_TIMER + x)```
|
||||
|
||||
@ -199,25 +199,25 @@ Now have a look at the directory 'standalone', here you find the files 'bashbot.
|
||||
A typical bashbot develop loop looks as follow:
|
||||
|
||||
1. start developing - *change, copy, edit bashbot files ...*
|
||||
2. after changing a bash sript: ```shellcheck -x scipt.sh```
|
||||
2. after changing a bash sript: ```shellcheck -x script.sh```
|
||||
3. ```dev/all-tests.sh``` - *in case if errors back to 2.*
|
||||
4. ```dev/git-add.sh``` - *check for changed files, update version string, run git add*
|
||||
5. ```git commit -m "COMMIT MESSAGE"; git push```
|
||||
|
||||
|
||||
**If you setup your dev environment with hooks and use the scripts above, versioning, addding and testing is done automatically.**
|
||||
**If you setup your dev environment with hooks and use the scripts above, versioning, adding and testing is done automatically.**
|
||||
|
||||
#### common commands
|
||||
We state bashbot is a bash only bot, but this is not true. bashbot is a bash script using bash features PLUS external commands.
|
||||
Usually bash is used in a unix/linux environment where many (GNU) commands are availible, but if commands are missing, bashbot may not work.
|
||||
Usually bash is used in a unix/linux environment where many (GNU) commands are available, but if commands are missing, bashbot may not work.
|
||||
|
||||
To avoid this and make bashbot working on as many platforms as possible - from embedded linux to mainframe - I recommed to restrict
|
||||
To avoid this and make bashbot working on as many platforms as possible - from embedded linux to mainframe - I recommend to restrict
|
||||
ourself to the common commands provided by bash and coreutils/busybox/toybox.
|
||||
See [Bash Builtins](https://www.gnu.org/software/bash/manual/html_node/Shell-Builtin-Commands.html),
|
||||
[coreutils](https://en.wikipedia.org/wiki/List_of_GNU_Core_Utilities_commands),
|
||||
[busybox](https://en.wikipedia.org/wiki/BusyBox#Commands) and [toybox](https://landley.net/toybox/help.html)
|
||||
|
||||
Availible commands in bash, coreutils, busybox and toybox. Do you find curl on the list?
|
||||
Available commands in bash, coreutils, busybox and toybox. Do you find curl on the list?
|
||||
```bash
|
||||
.*, [*, [[*, basename, break, builtin*, bzcat, caller*, cat, cd*, chattr,
|
||||
chgrp, chmod, chown, clear, command*, continue *, cp, cut, date, declare*,
|
||||
@ -230,7 +230,7 @@ Availible commands in bash, coreutils, busybox and toybox. Do you find curl on t
|
||||
time, times*, timeout, touch, tr, trap*, true, umask*, usleep, uudecode,
|
||||
uuencode, wc, wget, which, who, whoami, xargs, yes
|
||||
```
|
||||
commands marked with \* are bash builtins, all others are external programms. Calling an external programm is more expensive then using bulitins
|
||||
commands marked with \* are bash builtins, all others are external programs. Calling an external program is more expensive then using bulitins
|
||||
or using an internal replacement. Here are some tipps for using builtins.:
|
||||
```bash
|
||||
HOST="$(hostname)" -> HOST="$HOSTNAME"
|
||||
@ -347,5 +347,5 @@ fi
|
||||
|
||||
#### [Prev Function Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.98-dev-69-gafa8d87
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
@ -17,10 +17,10 @@ Two examples for interactive scripts are provided as **calc.sh** and **question.
|
||||
Background jobs are an easy way to provide sceduled messages or alerts if something happens.
|
||||
**notify.sh** is a simple example on how to send a message every x seonds, e.g. current time.
|
||||
|
||||
**background-scripts** contains a more useful example on how to start and stop different scripts plus some example backgound scripts.
|
||||
**background-scripts** contains a more useful example on how to start and stop different scripts plus some example background scripts.
|
||||
|
||||
```
|
||||
mycommands.sh - /run_xxx and /kill-xxx wil start any script named run_xxx.sh
|
||||
mycommands.sh - /run_xxx and /kill-xxx will start any script named run_xxx.sh
|
||||
|
||||
run_diskusage.sh - shows disk usage every 100 seconds
|
||||
run_filename.sh - shown the name of new files in a named dir
|
||||
@ -40,7 +40,7 @@ convert existing bots.
|
||||
mycommands.sh - commands to show system status
|
||||
botacl - controls who can show system status
|
||||
|
||||
*Availiable commands*:
|
||||
*Available commands*:
|
||||
/se *sensors*
|
||||
/smb *smbstatus*
|
||||
/free *memory status*
|
||||
@ -55,6 +55,6 @@ convert existing bots.
|
||||
|
||||
**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users.
|
||||
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
||||
|
@ -70,7 +70,7 @@ output_telegram() {
|
||||
sed <<< "${1}" -e ':a;N;$!ba;s/\n/ mynewlinestartshere /g'
|
||||
} # 2>>"$0.log"
|
||||
|
||||
# name and localtion of the tml file
|
||||
# name and location of the tml file
|
||||
|
||||
# $1 string to output
|
||||
# $2 file to add file to
|
||||
|
@ -4,11 +4,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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
# file: run_filename
|
||||
# background job to display content of all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ unset IFS
|
||||
# discard STDIN for background jobs!
|
||||
cat >/dev/null &
|
||||
|
||||
# watch for new files created by a trusted programm
|
||||
# watch for new files created by a trusted program
|
||||
WATCHDIR="/my_trusted/dir_to_watch"
|
||||
source "./mycommands.sh"
|
||||
|
||||
|
@ -2,11 +2,11 @@
|
||||
# file: run_filename
|
||||
# background job to display all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
|
@ -4,11 +4,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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file. multibot.sh
|
||||
# description: run multiple telegram bots from one installation
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||
echo "Usage: $0 botname command"
|
||||
@ -10,10 +10,10 @@ if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||
fi
|
||||
|
||||
BOT="${1}"
|
||||
[ "${#BOT}" -lt 5 ] && echo "Botname must have a minumum lenth of 5 characters" && exit 1
|
||||
[ "${#BOT}" -lt 5 ] && echo "Botname must have a minimum length of 5 characters" && exit 1
|
||||
|
||||
# where should the bots live?
|
||||
# true in one dir, false in seperate dirs
|
||||
# true in one dir, false in separate dirs
|
||||
if true; then
|
||||
# example for all in one bashbot dir
|
||||
BINDIR="/usr/local/telegram-bot-bash"
|
||||
@ -21,7 +21,7 @@ if true; then
|
||||
VAR="${BINDIR}"
|
||||
|
||||
else
|
||||
# alternative linux like localtions
|
||||
# alternative linux like locations
|
||||
BINDIR="/usr/local/bin"
|
||||
ETC="/etc/bahsbot"
|
||||
VAR="/var/bahsbot"
|
||||
@ -37,7 +37,7 @@ export BASHBOT_VAR="${VAR}/${BOT}"
|
||||
[ ! -d "${BINDIR}" ] && echo "Dir ${BINDIR} does not exist" && exit 1
|
||||
[ ! -d "${BASHBOT_ETC}" ] && echo "Dir ${BASHBOT_ETC} does not exist" && exit 1
|
||||
[ ! -d "${BASHBOT_VAR}" ] && echo "Dir ${BASHBOT_VAR} does not exist" && exit 1
|
||||
[ ! -x "${BINDIR}/bashbot.sh" ] && echo "${BINDIR}/bashbot.sh not executeable or does not exist" && exit 1
|
||||
[ ! -x "${BINDIR}/bashbot.sh" ] && echo "${BINDIR}/bashbot.sh not executable or does not exist" && exit 1
|
||||
[ ! -r "${BASHBOT_ETC}/commands.sh" ] && echo "${BASHBOT_ETC}/commands.sh not readable or does not exist" && exit 1
|
||||
[ ! -r "${BASHBOT_ETC}/mycommands.sh" ] && echo "${BASHBOT_ETC}/mycommands.sh not readable or does not exist" && exit 1
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#
|
||||
# this is an exmaple crontab file for telegram-bot-bash
|
||||
# this is an example crontab file for telegram-bot-bash
|
||||
# copy it to /etc/cron.d/bashbot
|
||||
#
|
||||
# (c) https://github.com/gnadelwartz
|
||||
@ -7,7 +7,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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
|
||||
SHELL=/bin/sh
|
||||
|
@ -5,11 +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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
INPUT="${3:-/dev/stdin}"
|
||||
|
@ -4,11 +4,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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe/log
|
||||
|
||||
|
||||
|
@ -5,11 +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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe
|
||||
|
||||
INPUT="${3:-/dev/stdin}"
|
||||
|
@ -1,9 +1,9 @@
|
||||
# file: botacl
|
||||
# a user not listed here, will return false from 'user_is_allowed'
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
# Format:
|
||||
# user:ressource:chat
|
||||
# user:resource:chat
|
||||
|
||||
# allow user 123456789 access to all resources in all chats
|
||||
123456789:*:*
|
||||
@ -12,7 +12,7 @@
|
||||
12131415:systemstatus:*
|
||||
|
||||
# * are only allowed on the right hand side and not for user!
|
||||
# the following exaples are NOT valid!
|
||||
# the following examples are NOT valid!
|
||||
*:*:*
|
||||
*:start:*
|
||||
*:*:98979695
|
||||
|
@ -5,7 +5,7 @@
|
||||
# to show how you can customize bashbot by only editing mycommands.sh
|
||||
# NOTE: this is not tested, simply copied from original source and reworked!
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
@ -19,7 +19,7 @@
|
||||
bashbot_info='This bot allows you to request status of your system.
|
||||
To begin using the bot, try with the /help command.
|
||||
'
|
||||
bashbot_help='*Availiable commands*:
|
||||
bashbot_help='*Available commands*:
|
||||
/se *sensors*
|
||||
/smb *smbstatus*
|
||||
/free *memory status*
|
||||
|
@ -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.98-dev-17-gdda5b6d
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
@ -32,7 +32,7 @@ inline_query_compose(){
|
||||
# title2Json title caption description markup inlinekeyboard
|
||||
case "${2}" in
|
||||
# user provided media
|
||||
"article"|"message") # article ID title message (markup decription)
|
||||
"article"|"message") # article ID title message (markup description)
|
||||
JSON='{"type":"article","id":"'$ID'","input_message_content": {"message_text":"'$4'"} '$(title2Json "$3" "" "$5" "$6" "$7")'}'
|
||||
;;
|
||||
"photo") # photo ID photoURL (thumbURL title description caption)
|
||||
@ -62,7 +62,7 @@ inline_query_compose(){
|
||||
"location") # location ID lat long title
|
||||
JSON='{"type":"location","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'"}'
|
||||
;;
|
||||
"venue") # venue ID lat long title (adress forsquare)
|
||||
"venue") # venue ID lat long title (address forsquare)
|
||||
[ -z "$6" ] && addr="$5"
|
||||
[ -n "$7" ] && fours=',"foursquare_id":"'$7'"'
|
||||
JSON='{"type":"venue","id":"'$ID'","latitude":"'$3'","longitude":"'$4'","title":"'$5'","address":"'$6${addr}'"'${fours}'}'
|
||||
|
@ -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.98-dev-67-g4fe9697
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
@ -35,7 +35,7 @@ killproc() {
|
||||
kill_proc "${CHAT[ID]}" "$1"
|
||||
}
|
||||
|
||||
# inline and backgound functions
|
||||
# inline and background functions
|
||||
# $1 chatid
|
||||
# $2 program
|
||||
# $3 jobname
|
||||
@ -117,7 +117,7 @@ inproc() {
|
||||
send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||
}
|
||||
|
||||
# start stopp all jobs
|
||||
# start stop all jobs
|
||||
# $1 command
|
||||
# killb*
|
||||
# suspendb*
|
||||
|
@ -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.98-dev-65-g25cc9a5
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
# source from commands.sh to use jsonDB functions
|
||||
#
|
||||
@ -13,7 +13,7 @@
|
||||
# from to file in JSON.sh output format, its a simple key/value storage.
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
# but can be used independed from bashbot also
|
||||
# but can be used independent from bashbot also
|
||||
# e.g. to create scrupts to manage jssh files
|
||||
|
||||
# source once magic, function named like file
|
||||
@ -21,7 +21,7 @@ eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
||||
# new feature: serialize / atomic operations:
|
||||
# updates will be done atomic with flock
|
||||
# flock should flock should be availible on all system as its part of busybox
|
||||
# flock should flock should be available on all system as its part of busybox
|
||||
# tinybox
|
||||
|
||||
# lockfile filename.flock is persistent and will be testet with flock for active lock (file open)
|
||||
@ -35,7 +35,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
# use flock for atomic operations
|
||||
|
||||
# read content of a file in JSON.sh format into given ARRAY
|
||||
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||
# $1 ARRAY name, must be declared with "declare -A ARRAY" upfront
|
||||
# $2 filename, must be relative to BASHBOT_ETC, and not contain '..'
|
||||
jssh_readDB() {
|
||||
local DB; DB="$(jssh_checkDB "$2")"
|
||||
@ -47,7 +47,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
|
||||
# write ARRAY content to a file in JSON.sh format
|
||||
# Warning: old content is overwritten
|
||||
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||
# $1 ARRAY name, must be declared with "declare -A ARRAY" upfront
|
||||
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
jssh_writeDB() {
|
||||
local DB; DB="$(jssh_checkDB "$2")"
|
||||
@ -58,11 +58,11 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
}
|
||||
|
||||
# update/write ARRAY content in file without deleting keys not in ARRAY
|
||||
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||
# $1 ARRAY name, must be declared with "declare -A ARRAY" upfront
|
||||
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
# complex slow, warpper async
|
||||
jssh_updateDB() {
|
||||
# for atomic update we cant use read/writeDB
|
||||
# for atomic update we can't use read/writeDB
|
||||
[ -z "${2}" ] && return 1
|
||||
local DB="${2}.jssh" # check in async
|
||||
[ ! -f "${DB}" ] && return 2
|
||||
@ -70,7 +70,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
}
|
||||
|
||||
# insert, update, apped key/value to jsshDB
|
||||
# $1 key name, can onyl contain -a-zA-Z0-9,._
|
||||
# $1 key name, can only contain -a-zA-Z0-9,._
|
||||
# $2 key value
|
||||
# $3 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
alias jssh_insertDB=jssh_insertKeyDB # backward compatibility
|
||||
@ -89,7 +89,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
}
|
||||
|
||||
# delete key/value from jsshDB
|
||||
# $1 key name, can onyl contain -a-zA-Z0-9,._
|
||||
# $1 key name, can only contain -a-zA-Z0-9,._
|
||||
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
# medium complex slow, wrapper async
|
||||
jssh_deleteKeyDB() {
|
||||
@ -101,7 +101,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
}
|
||||
|
||||
# get key/value from jsshDB
|
||||
# $1 key name, can onyl contain -a-zA-Z0-9,._
|
||||
# $1 key name, can only contain -a-zA-Z0-9,._
|
||||
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
alias jssh_getDB=jssh_getKeyDB
|
||||
jssh_getKeyDB() {
|
||||
@ -116,7 +116,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
|
||||
|
||||
# add a value to key, used for conters
|
||||
# $1 key name, can onyl contain -a-zA-Z0-9,._
|
||||
# $1 key name, can only contain -a-zA-Z0-9,._
|
||||
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
# $3 optional count, value added to counter, add 1 if empty
|
||||
# side effect: if $3 is not given, we add to end of file to be as fast as possible
|
||||
@ -130,7 +130,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
}
|
||||
|
||||
# update key/value in place to jsshDB
|
||||
# $1 key name, can onyl contain -a-zA-Z0-9,._
|
||||
# $1 key name, can only contain -a-zA-Z0-9,._
|
||||
# $2 key value
|
||||
# $3 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
#no own locking, so async is the same as updatekeyDB
|
||||
@ -154,7 +154,7 @@ if [ "$(LC_ALL=C type -t "flock")" = "file" ]; then
|
||||
# $1 name of array to update
|
||||
# $2 database
|
||||
# $3 id used to identify caller
|
||||
# medium comlex, wrapper async
|
||||
# medium complex, wrapper async
|
||||
jssh_updateArray() {
|
||||
[ -z "${2}" ] && return 1
|
||||
local DB="${2}.jssh" # name check in async
|
||||
@ -183,7 +183,7 @@ fi
|
||||
# no need for atomic
|
||||
|
||||
# print ARRAY content to stdout instead of file
|
||||
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||
# $1 ARRAY name, must be declared with "declare -A ARRAY" upfront
|
||||
jssh_printDB_async() { jssh_printDB "$@"; }
|
||||
jssh_printDB() {
|
||||
Array2Json "$1"
|
||||
@ -216,7 +216,7 @@ jssh_checkDB(){
|
||||
|
||||
######################
|
||||
# implementations as non atomic functions
|
||||
# can be used explictitly or as fallback if flock is not availible
|
||||
# can be used explictitly or as fallback if flock is not available
|
||||
jssh_readDB_async() {
|
||||
local DB; DB="$(jssh_checkDB "$2")"
|
||||
[ -z "${DB}" ] && return 1
|
||||
@ -297,7 +297,7 @@ jssh_countKeyDB_async() {
|
||||
}
|
||||
|
||||
# updatie key/value in place to jsshDB
|
||||
# $1 key name, can onyl contain -a-zA-Z0-9,._
|
||||
# $1 key name, can only contain -a-zA-Z0-9,._
|
||||
# $2 key value
|
||||
# $3 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
#no own locking, so async is the same as updatekeyDB
|
||||
@ -325,7 +325,7 @@ function jssh_updateArray_async() {
|
||||
}
|
||||
|
||||
##############
|
||||
# these 2 fuctions does all key/value store "magic"
|
||||
# these 2 functions does all key/value store "magic"
|
||||
# and convert from/to bash array
|
||||
|
||||
# read JSON.sh style data and asssign to an ARRAY
|
||||
|
@ -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.98-dev-68-g80a6dbb
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# will be automatically sourced from bashbot
|
||||
|
||||
@ -125,7 +125,7 @@ upload_file(){
|
||||
[[ "$file" = *'..'* ]] && return # no directory traversal
|
||||
[[ "$file" = '.'* ]] && return # no hidden or relative files
|
||||
if [[ "$file" = '/'* ]] ; then
|
||||
[[ ! "$file" =~ $FILE_REGEX ]] && return # absulute must match REGEX
|
||||
[[ ! "$file" =~ $FILE_REGEX ]] && return # absolute must match REGEX
|
||||
else
|
||||
file="${UPLOADDIR:-NOUPLOADDIR}/${file}" # othiers must be in UPLOADDIR
|
||||
fi
|
||||
|
@ -8,7 +8,7 @@
|
||||
# #### if you start to develop your own bot, use the clean version of this file:
|
||||
# #### mycommands.clean
|
||||
#
|
||||
#### $$VERSION$$ v0.98-dev-60-gfa6ad3e
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
|
||||
# uncomment the following lines to overwrite info and help messages
|
||||
@ -23,8 +23,8 @@ export res=""
|
||||
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 charater and '.*' matches all remaining charatcers!
|
||||
# additionally you must escape special charaters with '\', e.g. '\. \? \[ \*" to match them literally
|
||||
# '.' matches any character and '.*' matches all remaining charatcers!
|
||||
# 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"
|
||||
@ -37,7 +37,7 @@ unset BASHBOT_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 availble, up to BASHBOT_SLEEP (default 0.1s)
|
||||
# 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
|
||||
@ -62,8 +62,8 @@ if [ "$1" = "startbot" ];then
|
||||
# reminde bot that it was started
|
||||
touch .mystartup
|
||||
else
|
||||
# here we call the function above when the mesage arrives
|
||||
# things to do only at soure, eg. after startup
|
||||
# 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
|
||||
|
||||
#############################
|
||||
@ -82,7 +82,7 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# exmaple for actions based on chat or sender
|
||||
# example for actions based on chat or sender
|
||||
case "${USER[ID]}+${CHAT[ID]}" in
|
||||
'USERID+'*) # do something for all messages from USER
|
||||
printf "%s: U=%s C=%s M=%s\n" "$(date)" "${USER[ID]}" "${CHAT[ID]}" "${MESSAGE}" >>"${DATADIR}/${USER[ID]}.log"
|
||||
@ -172,7 +172,7 @@ else
|
||||
|
||||
myinlines() {
|
||||
#######################
|
||||
# Inline query examples, do not use them in production (exept image search ;-)
|
||||
# Inline query examples, do not use them in production (except image search ;-)
|
||||
# shellcheck disable=SC2128
|
||||
iQUERY="${iQUERY,,}" # all lowercase
|
||||
case "${iQUERY}" in
|
||||
@ -214,7 +214,7 @@ else
|
||||
"sticker") # example chaecd telegram sticker
|
||||
answer_inline_query "${iQUERY[ID]}" "cached_sticker" "BQADBAAD_QEAAiSFLwABWSYyiuj-g4AC"
|
||||
;;
|
||||
"gif") # exmaple chaehed gif
|
||||
"gif") # example chaehed gif
|
||||
answer_inline_query "${iQUERY[ID]}" "cached_gif" "BQADBAADIwYAAmwsDAABlIia56QGP0YC"
|
||||
;;
|
||||
esac
|
||||
|
@ -4,7 +4,7 @@
|
||||
# files: mycommands.sh.clean
|
||||
# copy to mycommands.sh and add all your commands and functions here ...
|
||||
#
|
||||
#### $$VERSION$$ v0.98-dev-33-g18f0ace
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
#
|
||||
|
||||
##########
|
||||
@ -22,8 +22,8 @@ export res=""
|
||||
export INLINE="0"
|
||||
|
||||
# NOTE: this is a regex, not shell globbing! you must use a valid egex,
|
||||
# '.' matches any charater and '.*' matches all remaining charatcers!
|
||||
# additionally you must escape special charaters with '\', e.g. '\. \? \[ \*" to match them literally
|
||||
# '.' matches any character and '.*' matches all remaining charatcers!
|
||||
# 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}/.*"
|
||||
|
||||
@ -35,7 +35,7 @@ unset BASHBOT_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 availble, up to BASHBOT_SLEEP (default 0.1s)
|
||||
# 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
|
||||
@ -59,8 +59,8 @@ if [ "$1" = "startbot" ];then
|
||||
}
|
||||
touch .mystartup
|
||||
else
|
||||
# here we call the function above when the mesage arrives
|
||||
# things to do only at soure, eg. after startup
|
||||
# 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
|
||||
|
||||
#############################
|
||||
|
@ -6,11 +6,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.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
######
|
||||
# parameters
|
||||
# $1 $2 args as given to starct_proc chat srcipt arg1 arg2
|
||||
# $1 $2 args as given to starct_proc chat script arg1 arg2
|
||||
# $3 path to named pipe
|
||||
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
#
|
||||
# ADD a new test skeleton to test dir, but does not activate test
|
||||
#
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
@ -27,7 +27,7 @@ read -r PASS
|
||||
# pass to lower, default pass d
|
||||
PASS="${PASS,,}"
|
||||
[ "${PASS}" = "" ] && PASS="d"
|
||||
[ "${#PASS}" != '1' ] && echo "Sorry, PASS must exactly one charater from a to z, aborting ..." && exit 1
|
||||
[ "${#PASS}" != '1' ] && echo "Sorry, PASS must exactly one character from a to z, aborting ..." && exit 1
|
||||
|
||||
TEST="${PASS}-${NAME}-test"
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -17,7 +17,7 @@ botadmin
|
||||
EOF
|
||||
echo "${SUCCESS}"
|
||||
|
||||
# compare files with refrence files
|
||||
# compare files with reference files
|
||||
echo "Check new files after init ..."
|
||||
export FAIL="0"
|
||||
for file in ${TESTFILES}
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -25,12 +25,12 @@ UPDATE="$(cat "${INPUTFILE}")"
|
||||
declare -A UPD
|
||||
source <( printf 'UPD=( %s )' "$(sed <<<"${UPDATE}" -E -e 's/\t/=/g' -e 's/=(true|false)/="\1"/')" )
|
||||
|
||||
# run process_message with and without phyton
|
||||
# run process_message with and without python
|
||||
echo "Check process_inline ..."
|
||||
for i in 1 2
|
||||
do
|
||||
[ "${i}" = "1" ] && ! command -v python >/dev/null 2>&1 && continue
|
||||
[ "${i}" = "1" ] && echo " ... with JsonDecode Phyton" && unset BASHBOT_DECODE
|
||||
[ "${i}" = "1" ] && echo " ... with JsonDecode Python" && unset BASHBOT_DECODE
|
||||
[ "${i}" = "2" ] && echo " ... with JsonDecode Bash" && export BASHBOT_DECODE="yes"
|
||||
set -x
|
||||
{ process_inline "0"; set +x; } >>"${LOGFILE}" 2>&1;
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.96-0-g3871ca9
|
||||
#### $$VERSION$$ v0.98-dev-70-g694ee61
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
@ -26,7 +26,7 @@ mkdir -p "${BASHBOT_ETC}" || exit 1
|
||||
mkdir -p "${BASHBOT_VAR}" || exit 1
|
||||
mkdir -p "${BASHBOT_BIN}" || exit 1
|
||||
|
||||
# cp bashbot files to new localtions
|
||||
# cp bashbot files to new locations
|
||||
set +f
|
||||
# shellcheck disable=SC2086
|
||||
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
|
||||
@ -64,7 +64,7 @@ echo " ... BASHBOT_VAR seems to work!"
|
||||
echo "${SUCCESS}"
|
||||
|
||||
|
||||
# compare files with refrence files
|
||||
# compare files with reference files
|
||||
export FAIL="0"
|
||||
for file in ${TESTFILES}
|
||||
do
|
||||
|
Loading…
Reference in New Issue
Block a user