mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-22 07:25:10 +00:00
commit
93b49141e8
4
.gitignore
vendored
4
.gitignore
vendored
@ -6,5 +6,5 @@
|
|||||||
*.log
|
*.log
|
||||||
/JSON.sh/
|
/JSON.sh/
|
||||||
/data-bot-bash/
|
/data-bot-bash/
|
||||||
/dist/
|
/DIST/
|
||||||
/standalone/
|
/STANDALONE/
|
||||||
|
42
README.html
42
README.html
@ -60,11 +60,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
|
|||||||
<p>Bashbot <a href="https://github.com/topkecleon/telegram-bot-bash">Documentation</a> and <a href="https://github.com/topkecleon/telegram-bot-bash/releases">Downloads</a> are availible on www.github.com</p>
|
<p>Bashbot <a href="https://github.com/topkecleon/telegram-bot-bash">Documentation</a> and <a href="https://github.com/topkecleon/telegram-bot-bash/releases">Downloads</a> are availible on www.github.com</p>
|
||||||
<h2 id="documentation">Documentation</h2>
|
<h2 id="documentation">Documentation</h2>
|
||||||
<ul>
|
<ul>
|
||||||
<li><a href="https://core.telegram.org/bots">Introdution to Telegram Bots</a>
|
<li><a href="https://core.telegram.org/bots">Introdution to Telegram Bots</a></li>
|
||||||
<ul>
|
|
||||||
<li><a href="https://core.telegram.org/bots#3-how-do-i-create-a-bot">One Bot to rule them all</a></li>
|
|
||||||
<li><a href="https://core.telegram.org/bots#commands">Bot commands</a></li>
|
|
||||||
</ul></li>
|
|
||||||
<li><a href="doc/0_install.md">Install Bashbot</a>
|
<li><a href="doc/0_install.md">Install Bashbot</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Install release</li>
|
<li>Install release</li>
|
||||||
@ -72,7 +68,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
|
|||||||
<li>Update Bashbot</li>
|
<li>Update Bashbot</li>
|
||||||
<li>Notes on Updates</li>
|
<li>Notes on Updates</li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li><a href="doc/1_firstbot.md">Create a new Telegram Bot with botfather</a></li>
|
<li><a href="doc/1_firstbot.md">Get Bottoken from Botfather</a></li>
|
||||||
<li><a href="doc/2_usage.md">Getting Started</a>
|
<li><a href="doc/2_usage.md">Getting Started</a>
|
||||||
<ul>
|
<ul>
|
||||||
<li>Managing your Bot</li>
|
<li>Managing your Bot</li>
|
||||||
@ -92,6 +88,8 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
|
|||||||
<li>Handling UTF-8 character sets</li>
|
<li>Handling UTF-8 character sets</li>
|
||||||
<li>Run as other user or system service</li>
|
<li>Run as other user or system service</li>
|
||||||
<li>Scedule bashbot from Cron</li>
|
<li>Scedule bashbot from Cron</li>
|
||||||
|
<li>Use from CLI and Scripts</li>
|
||||||
|
<li>Customize Bashbot Environment</li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li><a href="doc/5_practice.md">Best Practices</a>
|
<li><a href="doc/5_practice.md">Best Practices</a>
|
||||||
<ul>
|
<ul>
|
||||||
@ -106,15 +104,14 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
|
|||||||
<li>Inline Queries</li>
|
<li>Inline Queries</li>
|
||||||
<li>Background and Interactive Jobs</li>
|
<li>Background and Interactive Jobs</li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li><a href="doc/7_develop.md">Deveoper Notess</a>
|
<li><a href="doc/7_develop.md">Deveoper Notes</a>
|
||||||
<ul>
|
<ul>
|
||||||
|
<li>Debug bashbot</li>
|
||||||
|
<li>Modules, addons, events</li>
|
||||||
<li>Setup your environment</li>
|
<li>Setup your environment</li>
|
||||||
<li>Test, Add, Push changes</li>
|
|
||||||
<li>Prepare a new version</li>
|
|
||||||
<li>Bashbot testsuite</li>
|
<li>Bashbot testsuite</li>
|
||||||
</ul></li>
|
</ul></li>
|
||||||
<li><a href="doc/8_custom.md">Customize bashbot environment</a></li>
|
<li><a href="examples/README.md">Examples Dir</a></li>
|
||||||
<li><a href="examples/README.md">Examples</a></li>
|
|
||||||
</ul>
|
</ul>
|
||||||
<h3 id="your-really-first-bashbot-in-a-nutshell">Your really first bashbot in a nutshell</h3>
|
<h3 id="your-really-first-bashbot-in-a-nutshell">Your really first bashbot in a nutshell</h3>
|
||||||
<p>To install and run bashbot you need acess to a linux/unix/bsd command line. If you don’t know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(</p>
|
<p>To install and run bashbot you need acess to a linux/unix/bsd command line. If you don’t know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(</p>
|
||||||
@ -165,9 +162,30 @@ It features background tasks and interactive chats, and can serve as an interfac
|
|||||||
<h3 id="can-i-have-the-single-bashbot.sh-file-back">Can I have the single bashbot.sh file back?</h3>
|
<h3 id="can-i-have-the-single-bashbot.sh-file-back">Can I have the single bashbot.sh file back?</h3>
|
||||||
<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>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>
|
<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 id="can-i-send-messages-from-cli-and-scripts">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>Run the following commands in your bash shell or script while you are in the installation directory:</p>
|
||||||
|
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="co"># prepare bash / script to send commands</span>
|
||||||
|
<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>
|
||||||
|
<span class="bu">source</span> ./bashbot.sh source
|
||||||
|
|
||||||
|
<span class="co"># send me a test message</span>
|
||||||
|
<span class="ex">send_message</span> <span class="st">"</span><span class="va">$(</span><span class="fu">cat</span> <span class="st">"</span><span class="va">$BOTADMIN</span><span class="st">"</span><span class="va">)</span><span class="st">"</span> <span class="st">"test"</span>
|
||||||
|
|
||||||
|
<span class="co"># send me output of a system command</span>
|
||||||
|
<span class="ex">send_message</span> <span class="st">"</span><span class="op">$(<</span><span class="st">"</span><span class="va">$BOTADMIN</span><span class="st">"</span><span class="op">)</span><span class="st">"</span> <span class="st">"</span><span class="va">$(</span><span class="fu">df</span> -h<span class="va">)</span><span class="st">"</span></code></pre></div>
|
||||||
|
<p>For more information see <a href="doc/8_custom.md">Expert Use</a></p>
|
||||||
|
<h3 id="why-do-i-get-expected-value-got-eof-on-start">Why do I get “EXPECTED value GOT EOF” on start?</h3>
|
||||||
|
<p>May be your IP is blocked by telegram. You can test this by running curl or wget manually:</p>
|
||||||
|
<div class="sourceCode"><pre class="sourceCode bash"><code class="sourceCode bash"><span class="ex">curl</span> -m 10 https://api.telegram.org/bot
|
||||||
|
<span class="co">#curl: (28) Connection timed out after 10001 milliseconds</span>
|
||||||
|
|
||||||
|
<span class="fu">wget</span> -t 1 -T 10 https://api.telegram.org/bot
|
||||||
|
<span class="co">#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.</span></code></pre></div>
|
||||||
|
<p>This may happen if to many wrong requests are sent to api.telegram.org, e.g. using a wrong token or not existing API calls. If you have a fixed IP you can ask telegram service to unblock your ip or change your IP. If you are running a tor proxy on your server you may uncomment the <code>BASHBOT_CURL_ARGS</code> line in ‘mycommands.sh’</p>
|
||||||
<p><span class="citation">@Gnadelwartz</span></p>
|
<p><span class="citation">@Gnadelwartz</span></p>
|
||||||
<h2 id="thats-it">That’s it!</h2>
|
<h2 id="thats-it">That’s it!</h2>
|
||||||
<p>If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!</p>
|
<p>If you feel that there’s something missing or if you found a bug, feel free to submit a pull request!</p>
|
||||||
<h4 id="version-v0.80-8-g5296820"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.80-8-g5296820</h4>
|
<h4 id="version-v0.90-rc1-0-ge80b98a"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.90-rc1-0-ge80b98a</h4>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
48
README.md
48
README.md
@ -19,14 +19,12 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
|
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
|
||||||
* [One Bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
|
|
||||||
* [Bot commands](https://core.telegram.org/bots#commands)
|
|
||||||
* [Install Bashbot](doc/0_install.md)
|
* [Install Bashbot](doc/0_install.md)
|
||||||
* Install release
|
* Install release
|
||||||
* Install from githup
|
* Install from githup
|
||||||
* Update Bashbot
|
* Update Bashbot
|
||||||
* Notes on Updates
|
* Notes on Updates
|
||||||
* [Create a new Telegram Bot with botfather](doc/1_firstbot.md)
|
* [Get Bottoken from Botfather](doc/1_firstbot.md)
|
||||||
* [Getting Started](doc/2_usage.md)
|
* [Getting Started](doc/2_usage.md)
|
||||||
* Managing your Bot
|
* Managing your Bot
|
||||||
* Recieve data
|
* Recieve data
|
||||||
@ -41,6 +39,8 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
|||||||
* Handling UTF-8 character sets
|
* Handling UTF-8 character sets
|
||||||
* Run as other user or system service
|
* Run as other user or system service
|
||||||
* Scedule bashbot from Cron
|
* Scedule bashbot from Cron
|
||||||
|
* Use from CLI and Scripts
|
||||||
|
* Customize Bashbot Environment
|
||||||
* [Best Practices](doc/5_practice.md)
|
* [Best Practices](doc/5_practice.md)
|
||||||
* Customize commands.sh
|
* Customize commands.sh
|
||||||
* Seperate logic from commands
|
* Seperate logic from commands
|
||||||
@ -50,13 +50,12 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
|||||||
* User Access Control
|
* User Access Control
|
||||||
* Inline Queries
|
* Inline Queries
|
||||||
* Background and Interactive Jobs
|
* Background and Interactive Jobs
|
||||||
* [Deveoper Notess](doc/7_develop.md)
|
* [Deveoper Notes](doc/7_develop.md)
|
||||||
|
* Debug bashbot
|
||||||
|
* Modules, addons, events
|
||||||
* Setup your environment
|
* Setup your environment
|
||||||
* Test, Add, Push changes
|
|
||||||
* Prepare a new version
|
|
||||||
* Bashbot testsuite
|
* Bashbot testsuite
|
||||||
* [Customize bashbot environment](doc/8_custom.md)
|
* [Examples Dir](examples/README.md)
|
||||||
* [Examples](examples/README.md)
|
|
||||||
|
|
||||||
### Your really first bashbot in a nutshell
|
### Your really first bashbot in a nutshell
|
||||||
To install and run bashbot you need acess to a linux/unix/bsd command line. If you don't know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(
|
To install and run bashbot you need acess to a linux/unix/bsd command line. If you don't know how to get accces to a linux/unix/bsd like command line you should stop reading here :-(
|
||||||
@ -142,6 +141,37 @@ At the beginning bashbot was simply the file ```bashbot.sh``` you can copy every
|
|||||||
Hey no Problem, if you are finished with your cool bot run ```dev/make-standalone.sh``` to create a stripped down Version of your bot containing only
|
Hey no Problem, if you are finished with your cool bot run ```dev/make-standalone.sh``` to create a stripped down Version of your bot containing only
|
||||||
'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped down Version of your Bot](doc/7_develop.md)
|
'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped 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 ```./bashbot.sh kill```.
|
||||||
|
|
||||||
|
Run the following commands in your bash shell or script while you are in the installation directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# prepare bash / script to send commands
|
||||||
|
export BASHBOT_HOME="$(pwd)"
|
||||||
|
source ./bashbot.sh source
|
||||||
|
|
||||||
|
# send me a test message
|
||||||
|
send_message "$(cat "$BOTADMIN")" "test"
|
||||||
|
|
||||||
|
# send me output of a system command
|
||||||
|
send_message "$(<"$BOTADMIN")" "$(df -h)"
|
||||||
|
```
|
||||||
|
For more information see [Expert Use](doc/8_custom.md)
|
||||||
|
|
||||||
|
|
||||||
|
### Why do I get "EXPECTED value GOT EOF" on start?
|
||||||
|
May be your IP is blocked by telegram. You can test this by running curl or wget manually:
|
||||||
|
```bash
|
||||||
|
curl -m 10 https://api.telegram.org/bot
|
||||||
|
#curl: (28) Connection timed out after 10001 milliseconds
|
||||||
|
|
||||||
|
wget -t 1 -T 10 https://api.telegram.org/bot
|
||||||
|
#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.
|
||||||
|
```
|
||||||
|
This may happen if to many wrong requests are sent to api.telegram.org, e.g. using a wrong token or not existing API calls. If you have a fixed IP you can ask telegram service to unblock your ip or change your IP. If you are running a tor proxy on your server you may uncomment the ```BASHBOT_CURL_ARGS``` line in 'mycommands.sh'
|
||||||
|
|
||||||
|
|
||||||
@Gnadelwartz
|
@Gnadelwartz
|
||||||
|
|
||||||
@ -149,4 +179,4 @@ Hey no Problem, if you are finished with your cool bot run ```dev/make-standalon
|
|||||||
|
|
||||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-8-g5296820
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
58
README.txt
58
README.txt
@ -30,15 +30,12 @@ availible on www.github.com
|
|||||||
|
|
||||||
## Documentation
|
## Documentation
|
||||||
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
|
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
|
||||||
* [One Bot to rule them
|
|
||||||
all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
|
|
||||||
* [Bot commands](https://core.telegram.org/bots#commands)
|
|
||||||
* [Install Bashbot](doc/0_install.md)
|
* [Install Bashbot](doc/0_install.md)
|
||||||
* Install release
|
* Install release
|
||||||
* Install from githup
|
* Install from githup
|
||||||
* Update Bashbot
|
* Update Bashbot
|
||||||
* Notes on Updates
|
* Notes on Updates
|
||||||
* [Create a new Telegram Bot with botfather](doc/1_firstbot.md)
|
* [Get Bottoken from Botfather](doc/1_firstbot.md)
|
||||||
* [Getting Started](doc/2_usage.md)
|
* [Getting Started](doc/2_usage.md)
|
||||||
* Managing your Bot
|
* Managing your Bot
|
||||||
* Recieve data
|
* Recieve data
|
||||||
@ -53,6 +50,8 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
|
|||||||
* Handling UTF-8 character sets
|
* Handling UTF-8 character sets
|
||||||
* Run as other user or system service
|
* Run as other user or system service
|
||||||
* Scedule bashbot from Cron
|
* Scedule bashbot from Cron
|
||||||
|
* Use from CLI and Scripts
|
||||||
|
* Customize Bashbot Environment
|
||||||
* [Best Practices](doc/5_practice.md)
|
* [Best Practices](doc/5_practice.md)
|
||||||
* Customize commands.sh
|
* Customize commands.sh
|
||||||
* Seperate logic from commands
|
* Seperate logic from commands
|
||||||
@ -62,13 +61,12 @@ all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
|
|||||||
* User Access Control
|
* User Access Control
|
||||||
* Inline Queries
|
* Inline Queries
|
||||||
* Background and Interactive Jobs
|
* Background and Interactive Jobs
|
||||||
* [Deveoper Notess](doc/7_develop.md)
|
* [Deveoper Notes](doc/7_develop.md)
|
||||||
|
* Debug bashbot
|
||||||
|
* Modules, addons, events
|
||||||
* Setup your environment
|
* Setup your environment
|
||||||
* Test, Add, Push changes
|
|
||||||
* Prepare a new version
|
|
||||||
* Bashbot testsuite
|
* Bashbot testsuite
|
||||||
* [Customize bashbot environment](doc/8_custom.md)
|
* [Examples Dir](examples/README.md)
|
||||||
* [Examples](examples/README.md)
|
|
||||||
|
|
||||||
### Your really first bashbot in a nutshell
|
### Your really first bashbot in a nutshell
|
||||||
To install and run bashbot you need acess to a linux/unix/bsd command line. If
|
To install and run bashbot you need acess to a linux/unix/bsd command line. If
|
||||||
@ -206,6 +204,46 @@ containing only
|
|||||||
'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped
|
'bashbot.sh' and 'commands.sh'! For more information see [Create a stripped
|
||||||
down Version of your Bot](doc/7_develop.md)
|
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
|
||||||
|
```./bashbot.sh kill```.
|
||||||
|
|
||||||
|
Run the following commands in your bash shell or script while you are in the
|
||||||
|
installation directory:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# prepare bash / script to send commands
|
||||||
|
export BASHBOT_HOME="$(pwd)"
|
||||||
|
source ./bashbot.sh source
|
||||||
|
|
||||||
|
# send me a test message
|
||||||
|
send_message "$(cat "$BOTADMIN")" "test"
|
||||||
|
|
||||||
|
# send me output of a system command
|
||||||
|
send_message "$(<"$BOTADMIN")" "$(df -h)"
|
||||||
|
```
|
||||||
|
For more information see [Expert Use](doc/8_custom.md)
|
||||||
|
|
||||||
|
|
||||||
|
### Why do I get "EXPECTED value GOT EOF" on start?
|
||||||
|
May be your IP is blocked by telegram. You can test this by running curl or
|
||||||
|
wget manually:
|
||||||
|
```bash
|
||||||
|
curl -m 10 https://api.telegram.org/bot
|
||||||
|
#curl: (28) Connection timed out after 10001 milliseconds
|
||||||
|
|
||||||
|
wget -t 1 -T 10 https://api.telegram.org/bot
|
||||||
|
#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443...
|
||||||
|
failed: Connection timed out.
|
||||||
|
```
|
||||||
|
This may happen if to many wrong requests are sent to api.telegram.org, e.g.
|
||||||
|
using a wrong token or not existing API calls. If you have a fixed IP you can
|
||||||
|
ask telegram service to unblock your ip or change your IP. If you are running a
|
||||||
|
tor proxy on your server you may uncomment the ```BASHBOT_CURL_ARGS``` line in
|
||||||
|
'mycommands.sh'
|
||||||
|
|
||||||
|
|
||||||
@Gnadelwartz
|
@Gnadelwartz
|
||||||
|
|
||||||
@ -214,4 +252,4 @@ down Version of your Bot](doc/7_develop.md)
|
|||||||
If you feel that there's something missing or if you found a bug, feel free to
|
If you feel that there's something missing or if you found a bug, feel free to
|
||||||
submit a pull request!
|
submit a pull request!
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-8-g5296820
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
121
addons/antiFlood.sh
Normal file
121
addons/antiFlood.sh
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# file: addons/antiFlood.sh.dist
|
||||||
|
#
|
||||||
|
# this addon counts how many files, e.g. stickers, are sent to
|
||||||
|
# a chat and takes actions if threshold is reached
|
||||||
|
#
|
||||||
|
|
||||||
|
# used events:
|
||||||
|
#
|
||||||
|
# BASHBOT_EVENT_TEXT message containing message text received
|
||||||
|
# BASHBOT_EVENT_CMD a command is recieved
|
||||||
|
# BASHBOT_EVENT_FILE file received
|
||||||
|
#
|
||||||
|
# all global variables and functions can be used in registered functions.
|
||||||
|
#
|
||||||
|
# parameters when loaded
|
||||||
|
# $1 event: init, startbot ...
|
||||||
|
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||||
|
#
|
||||||
|
# prameters on events
|
||||||
|
# $1 event: inline, message, ..., file
|
||||||
|
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||||
|
#
|
||||||
|
# shellcheck disable=SC2140
|
||||||
|
|
||||||
|
# export used events
|
||||||
|
export BASHBOT_EVENT_TEXT BASHBOT_EVENT_CMD BASHBOT_EVENT_FILE BASHBOT_EVENT_TIMER
|
||||||
|
|
||||||
|
# any global variable defined by addons MUST be prefixed by addon name
|
||||||
|
ANTIFL_ME="antiFlood"
|
||||||
|
|
||||||
|
declare -Ax ANTIFL_CHATS ANTIFL_ACTUALS
|
||||||
|
|
||||||
|
ANTIFL_DEFAULT="5" # 5 files per minute
|
||||||
|
ANTIFL_BAN="5" # 5 minutes
|
||||||
|
|
||||||
|
# initialize after installation or update
|
||||||
|
if [[ "$1" = "init"* ]]; then
|
||||||
|
jssh_newDB "addons/$ANTIFL_ME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
# register on startbot
|
||||||
|
if [[ "$1" = "start"* ]]; then
|
||||||
|
ANTIFL_ADMIN="$(< "${BOTADMIN}")"
|
||||||
|
#load existing chat settings on start
|
||||||
|
jssh_readDB "ANTIFL_CHATS" "addons/$ANTIFL_ME"
|
||||||
|
|
||||||
|
# register to CMD
|
||||||
|
BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd"
|
||||||
|
|
||||||
|
antiFlood_cmd(){
|
||||||
|
case "${CMD[0]}" in
|
||||||
|
# command /afstart starts detection, $1 floodlevel
|
||||||
|
"/afstart")
|
||||||
|
ANTIFL_CHATS["${CHAT[ID]}","level"]="${ANTIFL_DEFAULT}"
|
||||||
|
ANTIFL_CHATS["${CHAT[ID]}","ban"]="${ANTIFL_BAN}"
|
||||||
|
[[ "${CMD[1]}" =~ ^[0-9]+$ ]] && ANTIFL_CHATS["${CHAT[ID]}","level"]="${CMD[1]}"
|
||||||
|
antiFlood_timer
|
||||||
|
;;
|
||||||
|
# command /afactive starts counter meausares
|
||||||
|
"/afdo")
|
||||||
|
ANTIFL_CHATS["${CHAT[ID]}","active"]="yes"
|
||||||
|
;;
|
||||||
|
# command /afactive starts counter meausares
|
||||||
|
"/afstop")
|
||||||
|
ANTIFL_CHATS["${CHAT[ID]}","active"]="no"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
|
# register to timer
|
||||||
|
BASHBOT_EVENT_TIMER["${ANTIFL_ME}","${ANTIFL_BAN}"]="antiFlood_timer"
|
||||||
|
|
||||||
|
# save settings and reset flood level every BAN Min
|
||||||
|
antiFlood_timer(){
|
||||||
|
ANTIFL_ACTUALS=( )
|
||||||
|
jssh_writeDB "ANTIFL_CHATS" "addons/$ANTIFL_ME" &
|
||||||
|
}
|
||||||
|
|
||||||
|
# register to inline and command
|
||||||
|
BASHBOT_EVENT_TEXT["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
|
||||||
|
BASHBOT_EVENT_FILE["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
|
||||||
|
|
||||||
|
antiFlood_multievent(){
|
||||||
|
# not started
|
||||||
|
[ "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" = "" ] && return
|
||||||
|
# check user flood text
|
||||||
|
if [ "$1" = "text" ]; then
|
||||||
|
if [ "${#MESSAGE[0]}" -gt "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" ]; then
|
||||||
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]-- ))
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]-- ))
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]++ ))
|
||||||
|
fi
|
||||||
|
# check user flood picture
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
if [ "$1" = "file" ]; then
|
||||||
|
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]++ ))
|
||||||
|
antiFlood_action & # do actions in subshell
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# check and handle actions
|
||||||
|
antiFlood_action() {
|
||||||
|
# check flood level of user
|
||||||
|
if [ "$(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"] +1))" -gt "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" ]; then
|
||||||
|
if [ "${ANTIFL_CHATS["${CHAT[ID]}","active"]}" = "yes" ]; then
|
||||||
|
# remove message
|
||||||
|
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
|
||||||
|
else
|
||||||
|
# inform admin
|
||||||
|
send_markdown_message "${ANTIFL_ADMIN}" "User ${USER[USERNAME]} reached flood level in chat ${CHAT[USERNAME]}!"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
fi
|
97
addons/example.sh
Normal file
97
addons/example.sh
Normal file
@ -0,0 +1,97 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# file: addons/example.sh.dist
|
||||||
|
#
|
||||||
|
# Addons can register to bashbot events at statup
|
||||||
|
# by providing their name and a callback per event
|
||||||
|
#
|
||||||
|
# If an event occours 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.
|
||||||
|
#
|
||||||
|
# Note: For the same reason event function MUST return imideatly!
|
||||||
|
# compute intensive tasks must be run in a nonblocking subshell,
|
||||||
|
# e.g. "(long running) &"
|
||||||
|
#
|
||||||
|
|
||||||
|
# Availible events:
|
||||||
|
# on events startbot and init, this file is sourced
|
||||||
|
#
|
||||||
|
# BASHBOT_EVENT_INLINE inline query received
|
||||||
|
# BASHBOT_EVENT_MESSAGE any type of message received
|
||||||
|
# BASHBOT_EVENT_TEXT message containing message text received
|
||||||
|
# BASHBOT_EVENT_CMD a command is recieved
|
||||||
|
# BASHBOT_EVENT_REPLYTO reply to message received
|
||||||
|
# BASHBOT_EVENT_FORWARD forwarded message received
|
||||||
|
# BASHBOT_EVENT_CONTACT contact received
|
||||||
|
# BASHBOT_EVENT_LOCATION location or venue received
|
||||||
|
# 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.
|
||||||
|
#
|
||||||
|
# all global variables and functions can be used in registered functions.
|
||||||
|
#
|
||||||
|
# parameters when loaded
|
||||||
|
# $1 event: init, startbot ...
|
||||||
|
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||||
|
#
|
||||||
|
# prameters on events
|
||||||
|
# $1 event: inline, message, ..., file
|
||||||
|
# $2 debug: use "[[ "$2" = *"debug"* ]]" if you want to output extra diagnostic
|
||||||
|
#
|
||||||
|
|
||||||
|
# export used events
|
||||||
|
export BASHBOT_EVENT_INLINE BASHBOT_EVENT_CMD BASHBOT_EVENT_REPLY BASHBOT_EVENT_TIMER
|
||||||
|
|
||||||
|
# any global variable defined by addons MUST be prefixed by addon name
|
||||||
|
EXAMPLE_ME="example"
|
||||||
|
|
||||||
|
# initialize after installation or update
|
||||||
|
if [[ "$1" = "init"* ]]; then
|
||||||
|
: # nothing to do
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# register on startbot
|
||||||
|
if [[ "$1" = "start"* ]]; then
|
||||||
|
# register to reply
|
||||||
|
BASHBOT_EVENT_REPLY["${EXAMPLE_ME}"]="${EXAMPLE_ME}_reply"
|
||||||
|
|
||||||
|
# any function defined by addons MUST be prefixed by addon name
|
||||||
|
# function local variables can have any name, but must be LOCAL
|
||||||
|
example_reply(){
|
||||||
|
local msg="message"
|
||||||
|
send_markdown_message "${CHAT[ID]}" "User *${USER[USERNAME]}* replied to ${msg} from *${REPLYTO[USERNAME]}*" &
|
||||||
|
}
|
||||||
|
|
||||||
|
# register to inline and command
|
||||||
|
BASHBOT_EVENT_INLINE["${EXAMPLE_ME}"]="${EXAMPLE_ME}_multievent"
|
||||||
|
BASHBOT_EVENT_CMD["${EXAMPLE_ME}"]="${EXAMPLE_ME}_multievent"
|
||||||
|
|
||||||
|
# any function defined by addons MUST be prefixed by addon name
|
||||||
|
# function local variables can have any name, but must be LOCAL
|
||||||
|
example_multievent(){
|
||||||
|
local type="$1"
|
||||||
|
local msg="${MESSAGE[0]}"
|
||||||
|
# shellcheck disable=SC2154
|
||||||
|
[ "${type}" = "inline" ] && msg="${iQUERY[0]}"
|
||||||
|
send_normal_message "${CHAT[ID]}" "${type} received: ${msg}" &
|
||||||
|
}
|
||||||
|
|
||||||
|
BASHBOT_EVENT_TIMER["${EXAMPLE_ME}after5min","-5"]="${EXAMPLE_ME}_after5min"
|
||||||
|
|
||||||
|
# any function defined by addons MUST be prefixed by addon name
|
||||||
|
# function local variables can have any name, but must be LOCAL
|
||||||
|
example_after5min(){
|
||||||
|
send_markdown_message "$(< "${BOTADMIN}")" "This is a one time event after 5 Minutes!" &
|
||||||
|
}
|
||||||
|
|
||||||
|
BASHBOT_EVENT_TIMER["${EXAMPLE_ME}every2min","2"]="${EXAMPLE_ME}_every2min"
|
||||||
|
|
||||||
|
# any function defined by addons MUST be prefixed by addon name
|
||||||
|
# function local variables can have any name, but must be LOCAL
|
||||||
|
example_every2min(){
|
||||||
|
send_markdown_message "$(< "${BOTADMIN}")" "This a a every 2 minute event ..." &
|
||||||
|
}
|
||||||
|
fi
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# description: Start or stop telegram-bash-bot
|
# description: Start or stop telegram-bash-bot
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
# shellcheck disable=SC2009
|
# shellcheck disable=SC2009
|
||||||
# shellcheck disable=SC2181
|
# shellcheck disable=SC2181
|
||||||
|
|
||||||
|
420
bashbot.sh
420
bashbot.sh
@ -11,7 +11,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-10-g48022e4
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 sucess (hopefully)
|
# - 0 sucess (hopefully)
|
||||||
@ -20,6 +20,7 @@
|
|||||||
# - 3 user / command / file not found
|
# - 3 user / command / file not found
|
||||||
# - 4 unkown command
|
# - 4 unkown command
|
||||||
# - 5 cannot connect to telegram bot
|
# - 5 cannot connect to telegram bot
|
||||||
|
# shellcheck disable=SC2140
|
||||||
|
|
||||||
# are we runnig in a terminal?
|
# are we runnig in a terminal?
|
||||||
if [ -t 1 ] && [ "$TERM" != "" ]; then
|
if [ -t 1 ] && [ "$TERM" != "" ]; then
|
||||||
@ -31,17 +32,31 @@ if [ -t 1 ] && [ "$TERM" != "" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
# get location and name of bashbot.sh
|
# get location and name of bashbot.sh
|
||||||
export SCRIPT SCRIPTDIR MODULEDIR RUNDIR RUNUSER
|
|
||||||
SCRIPT="$0"
|
SCRIPT="$0"
|
||||||
SCRIPTDIR="$(dirname "$0")"
|
REALME="${BASH_SOURCE[0]}"
|
||||||
|
SCRIPTDIR="$(dirname "${REALME}")"
|
||||||
|
RUNDIR="$(dirname "$0")"
|
||||||
|
|
||||||
MODULEDIR="${SCRIPTDIR}/modules"
|
MODULEDIR="${SCRIPTDIR}/modules"
|
||||||
|
|
||||||
RUNDIR="${SCRIPTDIR}"
|
|
||||||
[ "${RUNDIR}" = "${SCRIPTDIR}" ] && SCRIPT="./$(basename "${SCRIPT}")"
|
if [ "${SCRIPT}" != "${REALME}" ] || [ "$1" = "source" ]; then
|
||||||
|
SOURCE="yes"
|
||||||
|
else
|
||||||
|
SCRIPT="./$(basename "${SCRIPT}")"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$BASHBOT_HOME" != "" ]; then
|
||||||
|
SCRIPTDIR="$BASHBOT_HOME"
|
||||||
|
[ "${BASHBOT_ETC}" = "" ] && BASHBOT_ETC="$BASHBOT_HOME"
|
||||||
|
[ "${BASHBOT_VAR}" = "" ] && BASHBOT_VAR="$BASHBOT_HOME"
|
||||||
|
fi
|
||||||
|
|
||||||
|
ADDONDIR="${BASHBOT_ETC:-./addons}"
|
||||||
|
|
||||||
RUNUSER="${USER}" # USER is overwritten by bashbot array
|
RUNUSER="${USER}" # USER is overwritten by bashbot array
|
||||||
|
|
||||||
if [ "$1" != "source" ] && ! cd "${RUNDIR}" ; then
|
if [ "${SOURCE}" != "yes" ] && [ "$BASHBOT_HOME" = "" ] && ! cd "${RUNDIR}" ; then
|
||||||
echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}"
|
echo -e "${RED}ERROR: Can't change to ${RUNDIR} ...${NC}"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@ -51,6 +66,7 @@ if [ ! -w "." ]; then
|
|||||||
ls -ld .
|
ls -ld .
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
TOKENFILE="${BASHBOT_ETC:-.}/token"
|
TOKENFILE="${BASHBOT_ETC:-.}/token"
|
||||||
if [ ! -f "${TOKENFILE}" ]; then
|
if [ ! -f "${TOKENFILE}" ]; then
|
||||||
if [ "${CLEAR}" = "" ] && [ "$1" != "init" ]; then
|
if [ "${CLEAR}" = "" ] && [ "$1" != "init" ]; then
|
||||||
@ -76,8 +92,8 @@ if [ ! -f "${BOTADMIN}" ]; then
|
|||||||
echo -e "${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR ENTER '?'${NC}"
|
echo -e "${ORANGE}PLEASE WRITE YOUR TELEGRAM ID HERE OR ENTER '?'${NC}"
|
||||||
echo -e "${ORANGE}TO MAKE FIRST USER TYPING '/start' TO BOTADMIN${NC}"
|
echo -e "${ORANGE}TO MAKE FIRST USER TYPING '/start' TO BOTADMIN${NC}"
|
||||||
read -r admin
|
read -r admin
|
||||||
|
[ "${admin}" = "" ] && admin='?'
|
||||||
printf '%s\n' "${admin}" > "${BOTADMIN}"
|
printf '%s\n' "${admin}" > "${BOTADMIN}"
|
||||||
[ "${admin}" = "" ] && printf '%s\n' '?' > "${BOTADMIN}"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -87,12 +103,12 @@ if [ ! -f "${BOTACL}" ]; then
|
|||||||
printf '\n' >"${BOTACL}"
|
printf '\n' >"${BOTACL}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
TMPDIR="${BASHBOT_VAR:-.}/data-bot-bash"
|
DATADIR="${BASHBOT_VAR:-.}/data-bot-bash"
|
||||||
if [ ! -d "${TMPDIR}" ]; then
|
if [ ! -d "${DATADIR}" ]; then
|
||||||
mkdir "${TMPDIR}"
|
mkdir "${DATADIR}"
|
||||||
elif [ ! -w "${TMPDIR}" ]; then
|
elif [ ! -w "${DATADIR}" ]; then
|
||||||
echo -e "${RED}ERROR: Can't write to ${TMPDIR}!.${NC}"
|
echo -e "${RED}ERROR: Can't write to ${DATADIR}!.${NC}"
|
||||||
ls -ld "${TMPDIR}"
|
ls -ld "${DATADIR}"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -105,7 +121,6 @@ elif [ ! -w "${COUNTFILE}" ]; then
|
|||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
BOTTOKEN="$(< "${TOKENFILE}")"
|
BOTTOKEN="$(< "${TOKENFILE}")"
|
||||||
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
|
URL="${BASHBOT_URL:-https://api.telegram.org/bot}${BOTTOKEN}"
|
||||||
|
|
||||||
@ -114,12 +129,21 @@ ME_URL=$URL'/getMe'
|
|||||||
UPD_URL=$URL'/getUpdates?offset='
|
UPD_URL=$URL'/getUpdates?offset='
|
||||||
GETFILE_URL=$URL'/getFile'
|
GETFILE_URL=$URL'/getFile'
|
||||||
|
|
||||||
unset USER
|
declare -rx SCRIPT SCRIPTDIR MODULEDIR RUNDIR ADDONDIR TOKENFILE BOTADMIN BOTACL DATADIR COUNTFILE
|
||||||
declare -A BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY
|
declare -rx BOTTOKEN URL ME_URL UPD_URL GETFILE_URL
|
||||||
export res BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY CAPTION
|
|
||||||
|
declare -ax CMD
|
||||||
|
declare -Ax UPD BOTSENT USER MESSAGE URLS CONTACT LOCATION CHAT FORWARD REPLYTO VENUE iQUERY
|
||||||
|
export res CAPTION
|
||||||
|
|
||||||
|
|
||||||
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
||||||
if [ "$1" != "source" ]; then
|
if [ "${SOURCE}" = "yes" ]; then
|
||||||
|
for modules in ${MODULEDIR:-.}/*.sh ; do
|
||||||
|
# shellcheck source=./modules/aliases.sh
|
||||||
|
[ -r "${modules}" ] && source "${modules}" "source"
|
||||||
|
done
|
||||||
|
else
|
||||||
if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then
|
if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then
|
||||||
echo -e "${RED}ERROR: ${COMMANDS} does not exist or is not readable!.${NC}"
|
echo -e "${RED}ERROR: ${COMMANDS} does not exist or is not readable!.${NC}"
|
||||||
ls -l "${COMMANDS}"
|
ls -l "${COMMANDS}"
|
||||||
@ -130,15 +154,16 @@ if [ "$1" != "source" ]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
# internal functions
|
#################
|
||||||
# $1 URL, $2 filename in TMPDIR
|
# BASHBOT INTERNAL functions
|
||||||
|
# $1 URL, $2 filename in DATADIR
|
||||||
# outputs final filename
|
# outputs final filename
|
||||||
download() {
|
download() {
|
||||||
local empty="no.file" file="${2:-${empty}}"
|
local empty="no.file" file="${2:-${empty}}"
|
||||||
if [[ "$file" = *"/"* ]] || [[ "$file" = "."* ]]; then file="${empty}"; fi
|
if [[ "$file" = *"/"* ]] || [[ "$file" = "."* ]]; then file="${empty}"; fi
|
||||||
while [ -f "${TMPDIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done
|
while [ -f "${DATADIR:-.}/${file}" ] ; do file="$RAMDOM-${file}"; done
|
||||||
getJson "$1" >"${TMPDIR:-.}/${file}" || return
|
getJson "$1" >"${DATADIR:-.}/${file}" || return
|
||||||
printf '%s\n' "${TMPDIR:-.}/${file}"
|
printf '%s\n' "${DATADIR:-.}/${file}"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 postfix, e.g. chatid
|
# $1 postfix, e.g. chatid
|
||||||
@ -174,34 +199,43 @@ _exists()
|
|||||||
[ "$(LC_ALL=C type -t "$1")" = "file" ]
|
[ "$(LC_ALL=C type -t "$1")" = "file" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# execute function if exists
|
||||||
|
_exec_if_function() {
|
||||||
|
[ "$(LC_ALL=C type -t "${1}")" != "function" ] || "$@"
|
||||||
|
}
|
||||||
# returns true if function exist
|
# returns true if function exist
|
||||||
_is_function()
|
_is_function()
|
||||||
{
|
{
|
||||||
[ "$(LC_ALL=C type -t "$1")" = "function" ]
|
[ "$(LC_ALL=C type -t "$1")" = "function" ]
|
||||||
}
|
}
|
||||||
|
|
||||||
DELETE_URL=$URL'/deleteMessage'
|
declare -xr DELETE_URL=$URL'/deleteMessage'
|
||||||
delete_message() {
|
delete_message() {
|
||||||
sendJson "${1}" 'message_id: '"${2}"'' "${DELETE_URL}"
|
sendJson "${1}" 'message_id: '"${2}"'' "${DELETE_URL}"
|
||||||
}
|
}
|
||||||
|
|
||||||
get_file() {
|
get_file() {
|
||||||
[ "$1" = "" ] && return
|
[ "$1" = "" ] && return
|
||||||
sendJson "" '"file_id": '"${1}""${GETFILE_URL}"
|
sendJson "" '"file_id": "'"${1}"'"' "${GETFILE_URL}"
|
||||||
printf '%s\n' "${URL}"/"$(jsonGetString <<< "${res}" '"result","file_path"')"
|
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
|
||||||
}
|
}
|
||||||
|
|
||||||
# curl is preffered, but may not availible on ebedded systems
|
# curl is preffered, but may not availible on ebedded systems
|
||||||
|
TIMEOUT="${BASHBOT_TIMEOUT}"
|
||||||
|
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
|
||||||
|
|
||||||
if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
|
if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
|
||||||
# simple curl or wget call, output to stdout
|
# simple curl or wget call, output to stdout
|
||||||
getJson(){
|
getJson(){
|
||||||
curl -sL "$1"
|
# shellcheck disable=SC2086
|
||||||
|
curl -sL ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" "$1"
|
||||||
}
|
}
|
||||||
# usage: sendJson "chat" "JSON" "URL"
|
# usage: sendJson "chat" "JSON" "URL"
|
||||||
sendJson(){
|
sendJson(){
|
||||||
local chat="";
|
local chat="";
|
||||||
[ "${1}" != "" ] && chat='"chat_id":'"${1}"','
|
[ "${1}" != "" ] && chat='"chat_id":'"${1}"','
|
||||||
res="$(curl -s -d '{'"${chat} $2"'}' -X POST "${3}" \
|
# shellcheck disable=SC2086
|
||||||
|
res="$(curl -s ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}" -d '{'"${chat} $2"'}' -X POST "${3}" \
|
||||||
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )"
|
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n )"
|
||||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
||||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")"
|
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")"
|
||||||
@ -210,22 +244,26 @@ if [ "${BASHBOT_WGET}" = "" ] && _exists curl ; then
|
|||||||
sendUpload() {
|
sendUpload() {
|
||||||
[ "$#" -lt 4 ] && return
|
[ "$#" -lt 4 ] && return
|
||||||
if [ "$5" != "" ]; then
|
if [ "$5" != "" ]; then
|
||||||
res="$(curl -s "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n )"
|
# shellcheck disable=SC2086
|
||||||
|
res="$(curl -s ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n )"
|
||||||
else
|
else
|
||||||
res="$(curl -s "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -s -b -n )"
|
# shellcheck disable=SC2086
|
||||||
|
res="$(curl -s ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1" -F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -s -b -n )"
|
||||||
fi
|
fi
|
||||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
# simple curl or wget call outputs result to stdout
|
# simple curl or wget call outputs result to stdout
|
||||||
getJson(){
|
getJson(){
|
||||||
wget -qO - "$1"
|
# shellcheck disable=SC2086
|
||||||
|
wget -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - "$1"
|
||||||
}
|
}
|
||||||
# usage: sendJson "chat" "JSON" "URL"
|
# usage: sendJson "chat" "JSON" "URL"
|
||||||
sendJson(){
|
sendJson(){
|
||||||
local chat="";
|
local chat="";
|
||||||
[ "${1}" != "" ] && chat='"chat_id":'"${1}"','
|
[ "${1}" != "" ] && chat='"chat_id":'"${1}"','
|
||||||
res="$(wget -qO - --post-data='{'"${chat} $2"'}' \
|
# shellcheck disable=SC2086
|
||||||
|
res="$(wget -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $2"'}' \
|
||||||
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )"
|
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n )"
|
||||||
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
BOTSENT[OK]="$(JsonGetLine '"ok"' <<< "$res")"
|
||||||
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")"
|
BOTSENT[ID]="$(JsonGetValue '"result","message_id"' <<< "$res")"
|
||||||
@ -275,122 +313,276 @@ JsonGetLine() {
|
|||||||
JsonGetValue() {
|
JsonGetValue() {
|
||||||
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p'
|
sed -n -e '0,/\['"$1"'\]/ s/\['"$1"'\][ \t]\([0-9.,]*\).*/\1/p'
|
||||||
}
|
}
|
||||||
|
# read JSON.sh style data and asssign to an ARRAY
|
||||||
|
# $1 ARRAY name, must be declared with "declare -A ARRAY" before calling
|
||||||
|
Json2Array() {
|
||||||
|
# shellcheck source=./commands.sh
|
||||||
|
[ "$1" = "" ] || source <( printf "$1"'=( %s )' "$(sed -E -e 's/\t/=/g' -e 's/=(true|false)/="\1"/')" )
|
||||||
|
}
|
||||||
|
# output ARRAY as JSON.sh style data
|
||||||
|
# $1 ARRAY name, must be declared with "declare -A ARRAY" before calling
|
||||||
|
Array2Json() {
|
||||||
|
local key
|
||||||
|
declare -n ARRAY="$1"
|
||||||
|
for key in "${!ARRAY[@]}"
|
||||||
|
do
|
||||||
|
printf '["%s"]\t"%s"\n' "${key//,/\",\"}" "${ARRAY[${key}]//\"/\\\"}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
################
|
################
|
||||||
# processing of updates starts here
|
# processing of updates starts here
|
||||||
process_updates() {
|
process_updates() {
|
||||||
local max num debug="$1"
|
local max num debug="$1"
|
||||||
max="$(sed <<< "${UPDATE}" '/\["result",[0-9]*\]/!d' | tail -1 | sed 's/\["result",//g;s/\].*//g')"
|
max="$(sed <<< "${UPDATE}" '/\["result",[0-9]*\]/!d' | tail -1 | sed 's/\["result",//g;s/\].*//g')"
|
||||||
|
Json2Array 'UPD' <<<"${UPDATE}"
|
||||||
for ((num=0; num<=max; num++)); do
|
for ((num=0; num<=max; num++)); do
|
||||||
process_client "$num" "${debug}"
|
process_client "$num" "${debug}"
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
process_client() {
|
process_client() {
|
||||||
local num="$1" debug="$2"
|
local num="$1" debug="$2"
|
||||||
iQUERY[ID]="$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","id"')"
|
CMD=( ); iQUERY=( )
|
||||||
|
iQUERY[ID]="${UPD["result",${num},"inline_query","id"]}"
|
||||||
if [ "${iQUERY[ID]}" = "" ]; then
|
if [ "${iQUERY[ID]}" = "" ]; then
|
||||||
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log"
|
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"MESSAGE.log"
|
||||||
process_message "${num}" "${debug}"
|
process_message "${num}" "${debug}"
|
||||||
else
|
else
|
||||||
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"INLINE.log"
|
[[ "${debug}" = *"debug"* ]] && cat <<< "$UPDATE" >>"INLINE.log"
|
||||||
[ "$INLINE" != "0" ] && _is_function process_inline && process_inline "${num}" "${debug}"
|
process_inline "${num}" "${debug}"
|
||||||
fi
|
fi
|
||||||
|
#####
|
||||||
|
# process inline and message events
|
||||||
|
# first classic commnad dispatcher
|
||||||
# shellcheck source=./commands.sh
|
# shellcheck source=./commands.sh
|
||||||
source "${COMMANDS}" "${debug}"
|
source "${COMMANDS}" "${debug}" &
|
||||||
|
|
||||||
|
# then all registered addons
|
||||||
|
if [ "${iQUERY[ID]}" = "" ]; then
|
||||||
|
event_message "${debug}"
|
||||||
|
else
|
||||||
|
event_inline "${debug}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
# last count users
|
||||||
tmpcount="COUNT${CHAT[ID]}"
|
tmpcount="COUNT${CHAT[ID]}"
|
||||||
grep -q "$tmpcount" <"${COUNTFILE}" &>/dev/null || cat <<< "$tmpcount" >>"${COUNTFILE}"
|
grep -q "$tmpcount" <"${COUNTFILE}" &>/dev/null || cat <<< "$tmpcount" >>"${COUNTFILE}"
|
||||||
# To get user count execute bash bashbot.sh count
|
}
|
||||||
|
|
||||||
|
declare -Ax BASBOT_EVENT_INLINE BASBOT_EVENT_MESSAGE BASHBOT_EVENT_CMD BASBOT_EVENT_REPLY BASBOT_EVENT_FORWARD
|
||||||
|
declare -Ax BASBOT_EVENT_CONTACT BASBOT_EVENT_LOCATION BASBOT_EVENT_FILE BASHBOT_EVENT_TEXT BASHBOT_EVENT_TIMER
|
||||||
|
|
||||||
|
start_timer(){
|
||||||
|
# send alarm every ~60 s
|
||||||
|
while :; do
|
||||||
|
sleep 59.5
|
||||||
|
kill -ALRM $$
|
||||||
|
done;
|
||||||
|
}
|
||||||
|
|
||||||
|
EVENT_TIMER="0"
|
||||||
|
event_timer() {
|
||||||
|
local event timer debug="$1"
|
||||||
|
(( EVENT_TIMER += 1 ))
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_TIMER[@]}"
|
||||||
|
do
|
||||||
|
timer="${event##*,}"
|
||||||
|
[[ ! "$timer" =~ ^-*[0-9]+$ ]] && continue
|
||||||
|
[[ "$timer" =~ ^-*0+$ ]] && continue
|
||||||
|
if [ "$(( EVENT_TIMER % timer ))" = "0" ]; then
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_TIMER[${event}]}" "timer" "${debug}"
|
||||||
|
[ "$(( EVENT_TIMER % timer ))" -lt "0" ] && \
|
||||||
|
unset BASHBOT_EVENT_TIMER["${event}"]
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
event_inline() {
|
||||||
|
local event debug="$1"
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_INLINE[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_INLINE[${event}]}" "inline" "${debug}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
event_message() {
|
||||||
|
echo "${MESSAGE[0]}"
|
||||||
|
local event debug="$1"
|
||||||
|
# ${MESSAEG[*]} event_message
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_MESSAGE[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_MESSAGE[${event}]}" "messsage" "${debug}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ${TEXT[*]} event_text
|
||||||
|
if [ "${MESSAGE[0]}" != "" ]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_TEXT[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_TEXT[${event}]}" "text" "${debug}"
|
||||||
|
done
|
||||||
|
|
||||||
|
# ${CMD[*]} event_cmd
|
||||||
|
if [ "${CMD[0]}" != "" ]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_CMD[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_CMD[${event}]}" "command" "${debug}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# ${REPLYTO[*]} event_replyto
|
||||||
|
if [ "${REPLYTO[UID]}" != "" ]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_REPLYTO[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_REPLYTO[${event}]}" "replyto" "${debug}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ${FORWARD[*]} event_forward
|
||||||
|
if [ "${FORWARD[UID]}" != "" ]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_FORWARD[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function && "${BASHBOT_EVENT_FORWARD[${event}]}" "forward" "${debug}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ${CONTACT[*]} event_contact
|
||||||
|
if [ "${CONTACT[FIRST_NAME]}" != "" ]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_CONTACT[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_CONTACT[${event}]}" "contact" "${debug}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ${VENUE[*]} event_location
|
||||||
|
# ${LOCALTION[*]} event_location
|
||||||
|
if [ "${LOCATION[LONGITUDE]}" != "" ] || [ "${VENUE[TITLE]}" != "" ]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_LOCATION[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_LOCATION[${event}]}" "location" "${debug}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
|
# ${URLS[*]} event_file
|
||||||
|
# NOTE: compare again #URLS -1 blanks!
|
||||||
|
if [[ "${URLS[*]}" != " " ]]; then
|
||||||
|
# shellcheck disable=SC2153
|
||||||
|
for event in "${!BASHBOT_EVENT_FILE[@]}"
|
||||||
|
do
|
||||||
|
_exec_if_function "${BASHBOT_EVENT_FILE[${event}]}" "file" "${debug}"
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
|
||||||
}
|
}
|
||||||
process_inline() {
|
process_inline() {
|
||||||
local num="${1}"
|
local num="${1}"
|
||||||
iQUERY[0]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",0,"inline_query","query"')")"
|
iQUERY[0]="$(JsonDecode "${UPD["result",${num},"inline_query","query"]}")"
|
||||||
iQUERY[USER_ID]="$(JsonGetValue <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","id"')"
|
iQUERY[USER_ID]="${UPD["result",${num},"inline_query","from","id"]}"
|
||||||
iQUERY[FIRST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","first_name"')")"
|
iQUERY[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","first_name"]}")"
|
||||||
iQUERY[LAST_NAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","last_name"')")"
|
iQUERY[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","last_name"]}")"
|
||||||
iQUERY[USERNAME]="$(JsonDecode "$(JsonGetString <<<"${UPDATE}" '"result",'"${num}"',"inline_query","from","username"')")"
|
iQUERY[USERNAME]="$(JsonDecode "${UPD["result",${num},"inline_query","from","username"]}")"
|
||||||
|
# event_inline &
|
||||||
}
|
}
|
||||||
process_message() {
|
process_message() {
|
||||||
local num="$1"
|
local num="$1"
|
||||||
local TMP="${TMPDIR:-.}/$RANDOM$RANDOM-MESSAGE"
|
|
||||||
cat <<< "$UPDATE" >"$TMP"
|
|
||||||
# Message
|
# Message
|
||||||
MESSAGE[0]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","text"' <"$TMP")" | sed 's#\\/#/#g')"
|
MESSAGE[0]="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's#\\/#/#g')"
|
||||||
MESSAGE[ID]="$(JsonGetValue '"result",'"${num}"',"message","message_id"' <"$TMP" )"
|
MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}"
|
||||||
|
|
||||||
# Chat
|
# Chat
|
||||||
CHAT[ID]="$(JsonGetValue '"result",'"${num}"',"message","chat","id"' <"$TMP" )"
|
CHAT[ID]="${UPD["result",${num},"message","chat","id"]}"
|
||||||
CHAT[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","chat","first_name"' <"$TMP")")"
|
CHAT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","last_name"]}")"
|
||||||
CHAT[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","chat","last_name"' <"$TMP")")"
|
CHAT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","first_name"]}")"
|
||||||
CHAT[USERNAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","chat","username"' <"$TMP")")"
|
CHAT[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","chat","username"]}")"
|
||||||
CHAT[TITLE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","chat","title"' <"$TMP")")"
|
CHAT[TITLE]="$(JsonDecode "${UPD["result",${num},"message","chat","title"]}")"
|
||||||
CHAT[TYPE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","chat","type"' <"$TMP")")"
|
CHAT[TYPE]="$(JsonDecode "${UPD["result",${num},"message","chat","type"]}")"
|
||||||
CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","chat","all_members_are_administrators"' <"$TMP")")"
|
CHAT[ALL_ADMIN]="${UPD["result",${num},"message","chat","all_members_are_administrators"]}"
|
||||||
|
CHAT[ALL_MEMBERS_ARE_ADMINISTRATORS]="${CHAT[ALL_ADMIN]}" # backward compatibility
|
||||||
|
|
||||||
# User
|
# User
|
||||||
USER[ID]="$(JsonGetValue '"result",'"${num}"',"message","from","id"' <"$TMP" )"
|
USER[ID]="${UPD["result",${num},"message","from","id"]}"
|
||||||
USER[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","from","first_name"' <"$TMP")")"
|
USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")"
|
||||||
USER[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","from","last_name"' <"$TMP")")"
|
USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")"
|
||||||
USER[USERNAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","from","username"' <"$TMP")")"
|
USER[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","from","username"]}")"
|
||||||
|
|
||||||
# in reply to message from
|
# in reply to message from
|
||||||
REPLYTO[UID]="$(JsonGetValue '"result",'"${num}"',"message","reply_to_message","from","id"' <"$TMP" )"
|
REPLYTO=( )
|
||||||
|
REPLYTO[UID]="${UPD["result",${num},"message","reply_to_message","from","id"]}"
|
||||||
if [ "${REPLYTO[UID]}" != "" ]; then
|
if [ "${REPLYTO[UID]}" != "" ]; then
|
||||||
REPLYTO[0]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","reply_to_message","text"' <"$TMP")")"
|
REPLYTO[0]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","text"]}")"
|
||||||
REPLYTO[ID]="$(JsonGetValue '"result",'"${num}"',"message","reply_to_message","message_id"' <"$TMP")"
|
REPLYTO[ID]="${UPD["result",${num},"message","reply_to_message","message_id"]}"
|
||||||
REPLYTO[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","reply_to_message","from","first_name"' <"$TMP")")"
|
REPLYTO[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","from","first_name"]}")"
|
||||||
REPLYTO[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","reply_to_message","from","last_name"' <"$TMP")")"
|
REPLYTO[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","from","last_name"]}")"
|
||||||
REPLYTO[USERNAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","reply_to_message","from","username"' <"$TMP")")"
|
REPLYTO[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","reply_to_message","from","username"]}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# forwarded message from
|
# forwarded message from
|
||||||
FORWARD[UID]="$(JsonGetValue '"result",'"${num}"',"message","forward_from","id"' <"$TMP" )"
|
FORWARD=( )
|
||||||
|
FORWARD[UID]="${UPD["result",${num},"message","forward_from","id"]}"
|
||||||
if [ "${FORWARD[UID]}" != "" ]; then
|
if [ "${FORWARD[UID]}" != "" ]; then
|
||||||
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
FORWARD[ID]="${MESSAGE[ID]}" # same as message ID
|
||||||
FORWARD[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","forward_from","first_name"' <"$TMP")")"
|
FORWARD[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","first_name"]}")"
|
||||||
FORWARD[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","forward_from","last_name"' <"$TMP")")"
|
FORWARD[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","last_name"]}")"
|
||||||
FORWARD[USERNAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","forward_from","username"' <"$TMP")")"
|
FORWARD[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","forward_from","username"]}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Audio
|
# Audio
|
||||||
URLS[AUDIO]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","audio","file_id"' <"$TMP")")"
|
URLS=( )
|
||||||
|
URLS[AUDIO]="$(get_file "${UPD["result",${num},"message","audio","file_id"]}")"
|
||||||
# Document
|
# Document
|
||||||
URLS[DOCUMENT]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","document","file_id"' <"$TMP")")"
|
URLS[DOCUMENT]="$(get_file "${UPD["result",${num},"message","document","file_id"]}")"
|
||||||
# Photo
|
# Photo
|
||||||
URLS[PHOTO]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","photo",0,"file_id"' <"$TMP")")"
|
URLS[PHOTO]="$(get_file "${UPD["result",${num},"message","photo",0,"file_id"]}")"
|
||||||
# Sticker
|
# Sticker
|
||||||
URLS[STICKER]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","sticker","file_id"' <"$TMP")")"
|
URLS[STICKER]="$(get_file "${UPD["result",${num},"message","sticker","file_id"]}")"
|
||||||
# Video
|
# Video
|
||||||
URLS[VIDEO]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","video","file_id"' <"$TMP")")"
|
URLS[VIDEO]="$(get_file "${UPD["result",${num},"message","video","file_id"]}")"
|
||||||
# Voice
|
# Voice
|
||||||
URLS[VOICE]="$(get_file "$(JsonGetString '"result",'"${num}"',"message","voice","file_id"' <"$TMP")")"
|
URLS[VOICE]="$(get_file "${UPD["result",${num},"message","voice","file_id"]}")"
|
||||||
|
|
||||||
# Contact
|
# Contact
|
||||||
CONTACT[FIRST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","first_name"' <"$TMP")")"
|
CONTACT=( )
|
||||||
|
CONTACT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","first_name"]}")"
|
||||||
if [ "${CONTACT[FIRST_NAME]}" != "" ]; then
|
if [ "${CONTACT[FIRST_NAME]}" != "" ]; then
|
||||||
CONTACT[USER_ID]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","user_id"' <"$TMP")")"
|
CONTACT[USER_ID]="$(JsonDecode "${UPD["result",${num},"message","contact","user_id"]}")"
|
||||||
CONTACT[LAST_NAME]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","contact","last_name"' <"$TMP")")"
|
CONTACT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","contact","last_name"]}")"
|
||||||
CONTACT[NUMBER]="$(JsonGetString '"result",'"${num}"',"message","contact","phone_number"' <"$TMP")"
|
CONTACT[NUMBER]="${UPD["result",${num},"message","contact","phone_number"]}"
|
||||||
CONTACT[VCARD]="$(JsonGetString '"result",'"${num}"',"message","contact","vcard"' <"$TMP")"
|
CONTACT[VCARD]="$(JsonGetString '"result",'"${num}"',"message","contact","vcard"' <<<"${UPDATE}")"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# vunue
|
# vunue
|
||||||
VENUE[TITLE]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","venue","title"' <"$TMP")")"
|
VENUE=( )
|
||||||
|
VENUE[TITLE]="$(JsonDecode "${UPD["result",${num},"message","venue","title"]}")"
|
||||||
if [ "${VENUE[TITLE]}" != "" ]; then
|
if [ "${VENUE[TITLE]}" != "" ]; then
|
||||||
VENUE[ADDRESS]="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","venue","address"' <"$TMP")")"
|
VENUE[ADDRESS]="$(JsonDecode "${UPD["result",${num},"message","venue","address"]}")"
|
||||||
VENUE[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","venue","location","longitude"' <"$TMP")"
|
VENUE[LONGITUDE]="${UPD["result",${num},"message","venue","location","longitude"]}"
|
||||||
VENUE[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","venue","location","latitude"' <"$TMP")"
|
VENUE[LATITUDE]="${UPD["result",${num},"message","venue","location","latitude"]}"
|
||||||
VENUE[FOURSQUARE]="$(JsonGetString '"result",'"${num}"',"message","venue","foursquare_id"' <"$TMP")"
|
VENUE[FOURSQUARE]="${UPD["result",${num},"message","venue","foursquare_id"]}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Caption
|
# Caption
|
||||||
CAPTION="$(JsonDecode "$(JsonGetString '"result",'"${num}"',"message","caption"' <"$TMP")")"
|
CAPTION="$(JsonDecode "${UPD["result",${num},"message","caption"]}")"
|
||||||
|
|
||||||
# Location
|
# Location
|
||||||
LOCATION[LONGITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","longitude"' <"$TMP")"
|
LOCATION=( )
|
||||||
LOCATION[LATITUDE]="$(JsonGetValue '"result",'"${num}"',"message","location","latitude"' <"$TMP")"
|
LOCATION[LONGITUDE]="${UPD["result",${num},"message","location","longitude"]}"
|
||||||
rm "$TMP"
|
LOCATION[LATITUDE]="${UPD["result",${num},"message","location","latitude"]}"
|
||||||
}
|
|
||||||
|
|
||||||
|
# split message in command and args
|
||||||
|
if [[ "${MESSAGE[0]}" = "/"* ]]; then
|
||||||
|
set -f; unset IFS
|
||||||
|
# shellcheck disable=SC2206
|
||||||
|
CMD=( ${MESSAGE[0]} )
|
||||||
|
set +f
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
# main get updates loop, should never terminate
|
# main get updates loop, should never terminate
|
||||||
@ -404,9 +596,21 @@ start_bot() {
|
|||||||
[ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\""
|
[ "${DEBUG}" != "" ] && date && echo "Start BASHBOT in Mode \"${DEBUG}\""
|
||||||
[[ "${DEBUG}" = "xdebug"* ]] && set -x
|
[[ "${DEBUG}" = "xdebug"* ]] && set -x
|
||||||
#cleaup old pipes and empty logfiles
|
#cleaup old pipes and empty logfiles
|
||||||
find "${TMPDIR}" -type p -delete
|
find "${DATADIR}" -type p -delete
|
||||||
find "${TMPDIR}" -size 0 -name "*.log" -delete
|
find "${DATADIR}" -size 0 -name "*.log" -delete
|
||||||
|
# load addons on startup
|
||||||
|
for addons in ${ADDONDIR:-.}/*.sh ; do
|
||||||
|
# shellcheck source=./modules/aliases.sh
|
||||||
|
[ -r "${addons}" ] && source "${addons}" "startbot" "${DEBUG}"
|
||||||
|
done
|
||||||
|
# start timer events
|
||||||
|
if _is_function start_timer ; then
|
||||||
|
# shellcheck disable=SC2064
|
||||||
|
trap "event_timer $DEBUG" ALRM
|
||||||
|
start_timer &
|
||||||
|
# shellcheck disable=SC2064
|
||||||
|
trap "kill -9 $!; exit" EXIT INT HUP TERM QUIT
|
||||||
|
fi
|
||||||
while true; do
|
while true; do
|
||||||
UPDATE="$(getJson "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)"
|
UPDATE="$(getJson "$UPD_URL$OFFSET" | "${JSONSHFILE}" -s -b -n)"
|
||||||
|
|
||||||
@ -416,7 +620,7 @@ start_bot() {
|
|||||||
|
|
||||||
if [ "$OFFSET" != "1" ]; then
|
if [ "$OFFSET" != "1" ]; then
|
||||||
mysleep="100"
|
mysleep="100"
|
||||||
process_updates "${DEBUG}" &
|
process_updates "${DEBUG}"
|
||||||
fi
|
fi
|
||||||
# adaptive sleep in ms rounded to next lower second
|
# adaptive sleep in ms rounded to next lower second
|
||||||
[ "${mysleep}" -gt "999" ] && sleep "${mysleep%???}"
|
[ "${mysleep}" -gt "999" ] && sleep "${mysleep%???}"
|
||||||
@ -427,10 +631,16 @@ start_bot() {
|
|||||||
|
|
||||||
# initialize bot environment, user and permissions
|
# initialize bot environment, user and permissions
|
||||||
bot_init() {
|
bot_init() {
|
||||||
|
local DEBUG="$1"
|
||||||
# upgrade from old version
|
# upgrade from old version
|
||||||
local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash"
|
local OLDTMP="${BASHBOT_VAR:-.}/tmp-bot-bash"
|
||||||
[ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${TMPDIR}"; rmdir "${OLDTMP}"; }
|
[ -d "${OLDTMP}" ] && { mv -n "${OLDTMP}/"* "${DATADIR}"; rmdir "${OLDTMP}"; }
|
||||||
[ -f "modules/inline.sh" ] && rm -f "modules/inline.sh"
|
[ -f "modules/inline.sh" ] && rm -f "modules/inline.sh"
|
||||||
|
# load addons on startup
|
||||||
|
for addons in ${ADDONDIR:-.}/*.sh ; do
|
||||||
|
# shellcheck source=./modules/aliases.sh
|
||||||
|
[ -r "${addons}" ] && source "${addons}" "init" "${DEBUG}"
|
||||||
|
done
|
||||||
#setup bashbot
|
#setup bashbot
|
||||||
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
|
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
|
||||||
echo -n "Enter User to run basbot [$RUNUSER]: "
|
echo -n "Enter User to run basbot [$RUNUSER]: "
|
||||||
@ -449,12 +659,17 @@ bot_init() {
|
|||||||
chown -R "$TOUSER" . ./*
|
chown -R "$TOUSER" . ./*
|
||||||
chmod 711 .
|
chmod 711 .
|
||||||
chmod -R a-w ./*
|
chmod -R a-w ./*
|
||||||
chmod -R u+w "${COUNTFILE}" "${TMPDIR}" "${BOTADMIN}" ./*.log 2>/dev/null
|
chmod -R u+w "${COUNTFILE}" "${DATADIR}" "${BOTADMIN}" ./*.log 2>/dev/null
|
||||||
chmod -R o-r,o-w "${COUNTFILE}" "${TMPDIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null
|
chmod -R o-r,o-w "${COUNTFILE}" "${DATADIR}" "${TOKENFILE}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null
|
||||||
ls -la
|
ls -la
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ! _is_function send_message ; then
|
||||||
|
echo -e "${RED}ERROR: send_message is not availible, did you deactivate ${MODULEDIR}/sendMessage.sh?${NC}"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}/JSON.sh/JSON.sh}"
|
JSONSHFILE="${BASHBOT_JSONSH:-${RUNDIR}/JSON.sh/JSON.sh}"
|
||||||
[[ "${JSONSHFILE}" != *"/JSON.sh" ]] && echo -e "${RED}ERROR: \"${JSONSHFILE}\" ends not with \"JSONS.sh\".${NC}" && exit 3
|
[[ "${JSONSHFILE}" != *"/JSON.sh" ]] && echo -e "${RED}ERROR: \"${JSONSHFILE}\" ends not with \"JSONS.sh\".${NC}" && exit 3
|
||||||
|
|
||||||
@ -476,7 +691,7 @@ fi
|
|||||||
# source the script with source as param to use functions in other scripts
|
# source the script with source as param to use functions in other scripts
|
||||||
# do not execute if read from other scripts
|
# do not execute if read from other scripts
|
||||||
|
|
||||||
if [ "$1" != "source" ]; then
|
if [ "${SOURCE}" != "yes" ]; then
|
||||||
|
|
||||||
##############
|
##############
|
||||||
# internal options only for use from bashbot and developers
|
# internal options only for use from bashbot and developers
|
||||||
@ -487,19 +702,16 @@ if [ "$1" != "source" ]; then
|
|||||||
while read -r line ;do
|
while read -r line ;do
|
||||||
[ "$line" != "" ] && send_message "$2" "$line"
|
[ "$line" != "" ] && send_message "$2" "$line"
|
||||||
done
|
done
|
||||||
rm -f -r "${TMPDIR:-.}/$3"
|
rm -f -r "${DATADIR:-.}/$3"
|
||||||
[ -s "${TMPDIR:-.}/$3.log" ] || rm -f "${TMPDIR:-.}/$3.log"
|
[ -s "${DATADIR:-.}/$3.log" ] || rm -f "${DATADIR:-.}/$3.log"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
"startbot" )
|
"startbot" )
|
||||||
start_bot "$2"
|
start_bot "$2"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
"source") # this should never arrive here
|
|
||||||
exit
|
|
||||||
;;
|
|
||||||
"init") # adjust users and permissions
|
"init") # adjust users and permissions
|
||||||
bot_init
|
bot_init "$2"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
@ -507,7 +719,7 @@ if [ "$1" != "source" ]; then
|
|||||||
|
|
||||||
###############
|
###############
|
||||||
# "official" arguments as shown to users
|
# "official" arguments as shown to users
|
||||||
SESSION="$ME-startbot"
|
SESSION="${ME:-unknown}-startbot"
|
||||||
BOTPID="$(proclist "${SESSION}")"
|
BOTPID="$(proclist "${SESSION}")"
|
||||||
|
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -565,7 +777,7 @@ if [ "$1" != "source" ]; then
|
|||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "${RED}${ME}: BAD REQUEST${NC}"
|
echo -e "${RED}${REALME}: BAD REQUEST${NC}"
|
||||||
echo -e "${RED}Available arguments: start, stop, kill, status, count, broadcast, help, suspendback, resumeback, killback${NC}"
|
echo -e "${RED}Available arguments: start, stop, kill, status, count, broadcast, help, suspendback, resumeback, killback${NC}"
|
||||||
exit 4
|
exit 4
|
||||||
;;
|
;;
|
||||||
@ -574,6 +786,6 @@ if [ "$1" != "source" ]; then
|
|||||||
# warn if root
|
# warn if root
|
||||||
if [[ "${UID}" -eq "0" ]] ; then
|
if [[ "${UID}" -eq "0" ]] ; then
|
||||||
echo -e "\\n${ORANGE}WARNING: ${SCRIPT} was started as ROOT (UID 0)!${NC}"
|
echo -e "\\n${ORANGE}WARNING: ${SCRIPT} was started as ROOT (UID 0)!${NC}"
|
||||||
echo -e "${ORANGE}You are at HIGH RISK when processing user input with root privilegs!${NC}"
|
echo -e "${ORANGE}You are at HIGH RISK when running a Telegram BOT with root privilegs!${NC}"
|
||||||
fi
|
fi
|
||||||
fi # end source
|
fi # end source
|
||||||
|
25
commands.sh
25
commands.sh
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
#
|
#
|
||||||
|
|
||||||
# adjust your language setting here, e.g.when run from other user or cron.
|
# adjust your language setting here, e.g.when run from other user or cron.
|
||||||
@ -59,16 +59,21 @@ if [ "${1}" != "source" ];then
|
|||||||
# detect inline commands....
|
# detect inline commands....
|
||||||
# no default commands, all processing is done in myinlines()
|
# no default commands, all processing is done in myinlines()
|
||||||
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
|
if [ "$INLINE" != "0" ] && [ "${iQUERY[ID]}" != "" ]; then
|
||||||
if _is_function process_inline; then
|
# forward iinline query to optional dispatcher
|
||||||
# forward iinline query to optional dispatcher
|
_exec_if_function myinlines
|
||||||
_is_function myinlines && myinlines
|
|
||||||
fi
|
|
||||||
|
|
||||||
# regular (gobal) commands ...
|
# regular (gobal) commands ...
|
||||||
# your commands are in mycommands()
|
# your commands are in mycommands()
|
||||||
else
|
else
|
||||||
|
|
||||||
case "${MESSAGE}" in
|
###################
|
||||||
|
# user defined commands must placed in mycommands
|
||||||
|
_exec_if_function mycommands
|
||||||
|
|
||||||
|
# run commands if true (0) is returned or if mycommands dose not exist
|
||||||
|
# shellcheck disable=SC2181
|
||||||
|
if [ "$?" = "0" ]; then
|
||||||
|
case "${MESSAGE}" in
|
||||||
################################################
|
################################################
|
||||||
# GLOBAL commands start here, edit messages only
|
# GLOBAL commands start here, edit messages only
|
||||||
'/info'*)
|
'/info'*)
|
||||||
@ -104,9 +109,9 @@ if [ "${1}" != "source" ];then
|
|||||||
if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
|
if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
|
||||||
;;
|
;;
|
||||||
*) # forward messages to optional dispatcher
|
*) # forward messages to optional dispatcher
|
||||||
_is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
_exec_if_function send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
||||||
_is_function mycommands && mycommands
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# and every time we create new hooks
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
#
|
#
|
||||||
# works together with git pre-push.sh and ADD all changed files since last push
|
# works together with git pre-push.sh and ADD all changed files since last push
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
############
|
############
|
||||||
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||||
@ -30,7 +30,7 @@ fi
|
|||||||
|
|
||||||
# run shellcheck before commit
|
# run shellcheck before commit
|
||||||
set +f
|
set +f
|
||||||
FILES="$(find ./* -name '*.sh' | grep -v 'dist\/' )"
|
FILES="$(find ./* -name '*.sh' | grep -v 'DIST\/' )"
|
||||||
set -f
|
set -f
|
||||||
FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")"
|
FILES="${FILES} $(sed '/^#/d' <"dev/shellcheck.files")"
|
||||||
if [ "$FILES" != "" ]; then
|
if [ "$FILES" != "" ]; then
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
############
|
############
|
||||||
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# this has to run once atfer git clone
|
# this has to run once atfer git clone
|
||||||
# and every time we create new hooks
|
# and every time we create new hooks
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# file: make-distribution.sh
|
# file: make-distribution.sh
|
||||||
# creates files and arcchives to dirtribute bashbot
|
# creates files and arcchives to dirtribute bashbot
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
@ -16,8 +16,8 @@ fi
|
|||||||
VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')"
|
VERSION="$(git describe --tags | sed -e 's/-[0-9].*//' -e 's/v//')"
|
||||||
|
|
||||||
DISTNAME="telegram-bot-bash"
|
DISTNAME="telegram-bot-bash"
|
||||||
DISTDIR="./dist/${DISTNAME}"
|
DISTDIR="./DIST/${DISTNAME}"
|
||||||
DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modules LICENSE README.md README.txt README.html"
|
DISTFILES="bashbot.rc bashbot.sh commands.sh mycommands.sh doc examples modules addons LICENSE README.md README.txt README.html"
|
||||||
|
|
||||||
# run tests first!
|
# run tests first!
|
||||||
|
|
||||||
@ -36,11 +36,14 @@ mkdir -p "${DISTDIR}" 2>/dev/null
|
|||||||
cp -r ${DISTFILES} "${DISTDIR}"
|
cp -r ${DISTFILES} "${DISTDIR}"
|
||||||
cd "${DISTDIR}" || exit 1
|
cd "${DISTDIR}" || exit 1
|
||||||
|
|
||||||
# additional stuff
|
# do not overwrite on update
|
||||||
mv "bashbot.rc" "bashbot.rc.dist"
|
for file in mycommands.sh bashbot.rc addons/*.sh
|
||||||
# mv "commands.sh" "commands.sh.dist" # will be overwritten from v0.80 on
|
do
|
||||||
mv "mycommands.sh" "mycommands.sh.dist"
|
[ "${file}" = "addons/*.sh" ] && continue
|
||||||
|
mv "${file}" "${file}.dist"
|
||||||
|
done
|
||||||
|
|
||||||
|
# dwonload JSON.sh
|
||||||
JSONSHFILE="JSON.sh/JSON.sh"
|
JSONSHFILE="JSON.sh/JSON.sh"
|
||||||
if [ ! -f "${JSONSHFILE}" ]; then
|
if [ ! -f "${JSONSHFILE}" ]; then
|
||||||
mkdir "JSON.sh" 2>/dev/null
|
mkdir "JSON.sh" 2>/dev/null
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# If you your bot is finished you can use make-standalone.sh to create the
|
# 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!
|
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
@ -17,7 +17,7 @@ else
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
#DISTNAME="telegram-bot-bash"
|
#DISTNAME="telegram-bot-bash"
|
||||||
DISTDIR="./standalone/${DISTNAME}"
|
DISTDIR="./STANDALONE/${DISTNAME}"
|
||||||
DISTFILES="bashbot.sh commands.sh mycommands.sh modules LICENSE README.txt token count botacl botadmin"
|
DISTFILES="bashbot.sh commands.sh mycommands.sh modules LICENSE README.txt token count botacl botadmin"
|
||||||
|
|
||||||
# run tests first!
|
# run tests first!
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
# list of additional files to check from shellcheck
|
# list of additional files to check from shellcheck
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
bashbot.rc
|
bashbot.rc
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
# shellcheck disable=SC2016
|
# shellcheck disable=SC2016
|
||||||
#
|
#
|
||||||
# Easy Versioning in git:
|
# Easy Versioning in git:
|
||||||
|
@ -7,9 +7,10 @@
|
|||||||
* /usr/local if you want to run as service
|
* /usr/local if you want to run as service
|
||||||
2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files.
|
2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files.
|
||||||
3. Change into the directory ```telegram-bot-bash```
|
3. Change into the directory ```telegram-bot-bash```
|
||||||
4. Create default commands with ```cp commands.sh.dist commands.sh; cp mycommands.sh.dist mycommands.sh```
|
4. Acticate the bot example commands ``cp mycommands.sh.dist mycommands.sh```
|
||||||
5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather.
|
5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather.
|
||||||
|
|
||||||
|
Edit 'mycommands.sh to your needs.
|
||||||
Now your Bot is ready to start ...
|
Now your Bot is ready to start ...
|
||||||
|
|
||||||
**If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)**
|
**If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)**
|
||||||
@ -38,8 +39,7 @@ As an alternative to download the zip files, you can clone the github repository
|
|||||||
4. Extract all files to your existing bashbot dir
|
4. Extract all files to your existing bashbot dir
|
||||||
5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update
|
5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update
|
||||||
|
|
||||||
If you modified 'commands.sh' re apply all changes to the new 'commands.sh'. To avoid this all your modifications
|
If you modified 'commands.sh' move your changes to 'mycommands.sh', this avoids overwrrite of you changes on updates.
|
||||||
must be done in 'mycommands.sh' only.
|
|
||||||
|
|
||||||
Now you can restart your bashbot instances.
|
Now you can restart your bashbot instances.
|
||||||
|
|
||||||
@ -87,5 +87,5 @@ The old format is supported for backward compatibility, but may fail for corner
|
|||||||
|
|
||||||
#### [Next Create Bot](1_firstbot.md)
|
#### [Next Create Bot](1_firstbot.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
@ -65,5 +65,5 @@ group. This step is up to you actually.
|
|||||||
#### [Prev Installation](0_install.md)
|
#### [Prev Installation](0_install.md)
|
||||||
#### [Next Getting started](2_usage.md)
|
#### [Next Getting started](2_usage.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
@ -1,19 +1,58 @@
|
|||||||
#### [Home](../README.md)
|
#### [Home](../README.md)
|
||||||
## Gettting Started
|
## Gettting Started
|
||||||
|
|
||||||
The Bots standard commands are in ```commands.sh``` file. You must not add your commands to 'commands.sh', instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. See [Best practices](5_practice.md) for more information.
|
The Bots standard commands are in the commands dispatcher ```commands.sh```, Do not edit this file! Add your commands and functions to ```mycommands.sh```. In 'mycommands.sh.dist' you find examples how to add own commands and overwrite existing ones. See [Best practices](5_practice.md) for more information.
|
||||||
|
|
||||||
Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```.
|
Once you're done with editing start the Bot with ```./bashbot.sh start```. To stop the Bot run ```./bashbot.sh kill```
|
||||||
To stop the Bot run ```./bashbot.sh kill```
|
|
||||||
|
|
||||||
If some thing doesn't work as it should, you can debug with ```./bashbot.sh startbot DEBUG``` where DEBUG can be 'debug', 'xdebug' or 'xdebugx'.
|
If something doesn't work as expected, debug with ```./bashbot.sh startbot DEBUG &```, where DEBUG can be 'debug', 'xdebug' or 'xdebugx'.
|
||||||
See [Bashbot Development](7_develop.md) for more information.
|
See [Bashbot Development](7_develop.md) for more information.
|
||||||
|
|
||||||
To use the functions provided in this script in other scripts simply source bashbot: ```source bashbot.sh```
|
To use the functions provided in this script in other scripts simply source bashbot: ```source bashbot.sh source```. see [Expert Use](8_expert.md#Expert-use)
|
||||||
|
|
||||||
Have FUN!
|
Have FUN!
|
||||||
|
|
||||||
## Managing your own Bot
|
----
|
||||||
|
|
||||||
|
### Files
|
||||||
|
```
|
||||||
|
.
|
||||||
|
├── bashbot.sh # main bashbot script - do not edit
|
||||||
|
├── commands.sh # command dispatcher - do not edit
|
||||||
|
├── mycommands.sh # place your functions and commands here!
|
||||||
|
├── JSON.sh # bashbots JSON parser, see https://github.com/dominictarr/JSON.sh
|
||||||
|
│
|
||||||
|
├── 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
|
||||||
|
│ ├── background.sh # interactive and background functions
|
||||||
|
│ ├── chatMember.sh
|
||||||
|
│ └── sendMessage.sh # main send message functions, do not disable
|
||||||
|
│
|
||||||
|
├── addons # optional addons, disbaled 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
|
||||||
|
│
|
||||||
|
├── bashbot.rc # start/stop script if you run basbot as service
|
||||||
|
│
|
||||||
|
├── examples # example scripts and configs for bashbot
|
||||||
|
│ ├── README.md # description of files and examples
|
||||||
|
│ └── bashbot.cron # example crontab
|
||||||
|
│
|
||||||
|
├── doc # Documentation and License
|
||||||
|
├── html
|
||||||
|
├── LICENSE
|
||||||
|
├── README.html
|
||||||
|
├── README.md
|
||||||
|
└── README.txt
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
## Managing your Bot
|
||||||
#### Note: running bashbot as root is highly danger and not recommended. See Expert use.
|
#### Note: running bashbot as root is highly danger and not recommended. See Expert use.
|
||||||
|
|
||||||
### Start / Stop
|
### Start / Stop
|
||||||
@ -37,6 +76,8 @@ To send a broadcast to all of users that ever used the bot run the following com
|
|||||||
./bashbot.sh broadcast "Hey! I just wanted to let you know that the bot's been updated!"
|
./bashbot.sh broadcast "Hey! I just wanted to let you know that the bot's been updated!"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
## Recieve data
|
## Recieve data
|
||||||
Evertime a Message is recieved, you can read incoming data using the following variables:
|
Evertime a Message is recieved, you can read incoming data using the following variables:
|
||||||
|
|
||||||
@ -182,5 +223,5 @@ send_action "${CHAT[ID]}" "action"
|
|||||||
#### [Prev Create Bot](1_firstbot.md)
|
#### [Prev Create Bot](1_firstbot.md)
|
||||||
#### [Next Advanced Usage](3_advanced.md)
|
#### [Next Advanced Usage](3_advanced.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli
|
|||||||
#### [Prev Getting started](2_usage.md)
|
#### [Prev Getting started](2_usage.md)
|
||||||
#### [Next Expert Use](4_expert.md)
|
#### [Next Expert Use](4_expert.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
248
doc/4_expert.md
248
doc/4_expert.md
@ -101,8 +101,252 @@ An example crontab is provided in ```examples/bashbot.cron```.
|
|||||||
- If you are running bashbot with your user-ID, copy the examples lines to your crontab and remove username ```nobody```.
|
- If you are running bashbot with your user-ID, copy the examples lines to your crontab and remove username ```nobody```.
|
||||||
- if you run bashbot as an other user or a system service edit ```examples/bashbot.cron``` to fit your needs and replace username```nobody``` with the username you want to run bashbot. copy the modified file to ```/etc/cron.d/bashbot```
|
- if you run bashbot as an other user or a system service edit ```examples/bashbot.cron``` to fit your needs and replace username```nobody``` with the username you want to run bashbot. copy the modified file to ```/etc/cron.d/bashbot```
|
||||||
|
|
||||||
#### [Prev Expert Use](4_expert.md)
|
|
||||||
|
### Use bashbot from CLI and scripts
|
||||||
|
You can use bashbot to send *messages*, *locations*, *venues*, *pictures* etc. from command line and scripts
|
||||||
|
by sourcing it:
|
||||||
|
|
||||||
|
*usage:* . bashbot.sh source
|
||||||
|
|
||||||
|
Before sourcing 'bahsbot.sh' for interactive and script use, you should export and set BASHBOT_HOME to bashbots installation dir,
|
||||||
|
e.g. '/usr/local/telegram-bot-bash'. see [Bashbot Environemt](#Bashbot-environment)
|
||||||
|
|
||||||
|
**Note:** *If you don't set BASHBOT_HOME bashbot will use the actual directory as NEW home directory
|
||||||
|
which means it will create all needed files and ask for bot token and botadmin if you are not in the real bot home!*
|
||||||
|
|
||||||
|
*Examples:*
|
||||||
|
```bash
|
||||||
|
# if you are in the bashbot directory
|
||||||
|
. bashbot.sh source
|
||||||
|
|
||||||
|
# same, but more readable in scripts
|
||||||
|
source ./bashbot.sh source
|
||||||
|
|
||||||
|
# use bashbot config in BASHBOT_HOME from any directory
|
||||||
|
export BASHBOT_HOME=/usr/local/telegram-bot-bash
|
||||||
|
source ${BASHBOT_HOME}/bashbot.sh source
|
||||||
|
|
||||||
|
# use / create new config in current directory
|
||||||
|
unset BASHBOT_HOME
|
||||||
|
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:
|
||||||
|
```bash
|
||||||
|
COMMANDS # default: ./commands.sh"
|
||||||
|
MODULEDIR # default: ./modules"
|
||||||
|
TOKENFILE # default: ./token"
|
||||||
|
BOTADMIN # default: ./botadmin"
|
||||||
|
BOTACL # default: ./botacl"
|
||||||
|
TMPDIR # default: ./data-bot-bash"
|
||||||
|
COUNTFILE # default: ./count"
|
||||||
|
|
||||||
|
BOTTOKEN # default: content of ${TOKENFILE}
|
||||||
|
URL # telegram api URL - default: https://api.telegram.org/bot${BOTTOKEN}"
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Interacctive use
|
||||||
|
For testing your setup or sending messages yoursel you can use bashbot functions from bash command line:
|
||||||
|
```bash
|
||||||
|
# are we running bash?
|
||||||
|
echo $SHELL
|
||||||
|
/bin/bash
|
||||||
|
|
||||||
|
# source bashbot.sh WITHOUT BASHBOT_HOME set
|
||||||
|
./bashbot.sh source
|
||||||
|
|
||||||
|
# output bashbot internal variables
|
||||||
|
echo $COMMANDS $MODULEDIR $TOKENFILE $BOTADMIN $BOTACL $TMPDIR $COUNTFILE
|
||||||
|
./commands.sh ./modules ./token ./botadmin ./botacl ./data-bot-bash ./count
|
||||||
|
|
||||||
|
|
||||||
|
# source bashbot.sh WITH BASHBOT_HOME set
|
||||||
|
export BASHBOT_HOME=/usr/local/telegram-bot-bash
|
||||||
|
source ./bashbot.sh source
|
||||||
|
|
||||||
|
# output bashbot internal variables
|
||||||
|
echo $COMMANDS $MODULEDIR $TOKENFILE $BOTADMIN $BOTACL $TMPDIR $COUNTFILE
|
||||||
|
/usr/local/telegram-bot-bash/commands.sh /usr/local/telegram-bot-bash/modules /usr/local/telegram-bot-bash/token
|
||||||
|
/usr/local/telegram-bot-bash/botadmin /usr/local/telegram-bot-bash/botacl /usr/local/telegram-bot-bash/data-bot-bash
|
||||||
|
/usr/local/telegram-bot-bash/count
|
||||||
|
|
||||||
|
```
|
||||||
|
After sourcing you can use bashbot functions to send Messages, Locations, Pictures etc. to any Telegram
|
||||||
|
User or Chat you are in. See [Send Messages](2_usage.md#sending-messages).
|
||||||
|
|
||||||
|
*Examples:* You can test this by sending messages to yourself:
|
||||||
|
```bash
|
||||||
|
# fist Hello World
|
||||||
|
send_normal_message "$(< $BOTADMIN)" "Hello World! This is my first message"
|
||||||
|
|
||||||
|
# now with some markdown and HTML
|
||||||
|
send_markdown_message "$(< $BOTADMIN)" '*Hello World!* _This is my first markdown message_'
|
||||||
|
send_html_message "$(< $BOTADMIN)" '<b>Hello World!</b> <em>This is my first HTML message</em>'
|
||||||
|
send_keyboard "$(< $BOTADMIN)" 'Do you like it?' '[ "Yep" , "No" ]'
|
||||||
|
```
|
||||||
|
Now something more useful ...
|
||||||
|
```bash
|
||||||
|
# sending output from system commands:
|
||||||
|
send_normal_message "$(< $BOTADMIN)" "$(date)"
|
||||||
|
|
||||||
|
send_normal_message "$(< $BOTADMIN)" "$(uptime)"
|
||||||
|
|
||||||
|
send_normal_message "$(< $BOTADMIN)" '`'$(free)'`'
|
||||||
|
|
||||||
|
# same but markdown style 'code' (monospaced)
|
||||||
|
send_markdown_message "$(< $BOTADMIN)" "\`$(free)\`"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### Bashbot environment
|
||||||
|
This section describe how you can customize bashbot to your needs by setting environment variables.
|
||||||
|
|
||||||
|
|
||||||
|
#### Change file locations
|
||||||
|
In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' any location
|
||||||
|
and run it from there. All files - programm, config, data etc - will reside in 'telegram-bot-bash'.
|
||||||
|
|
||||||
|
If you want to have other locations for config, data etc, define and export the following environment variables.
|
||||||
|
**Note: all specified directories and files must exist or running 'bashbot.sh' will fail.**
|
||||||
|
|
||||||
|
##### BASHBOT_ETC
|
||||||
|
Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```botadmin```, ```botacl``` ...
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_ETC # keep in telegram-bot-bash (default)
|
||||||
|
export BASHBOT_ETC "" # keep in telegram-bot-bash
|
||||||
|
|
||||||
|
export BASHBOT_ETC "/etc/bashbot" # unix like config location
|
||||||
|
|
||||||
|
export BASHBOT_ETC "/etc/bashbot/bot1" # multibot configuration bot 1
|
||||||
|
export BASHBOT_ETC "/etc/bashbot/bot2" # multibot configuration bot 2
|
||||||
|
```
|
||||||
|
|
||||||
|
e.g. /etc/bashbot
|
||||||
|
|
||||||
|
##### BASHBOT_VAR
|
||||||
|
Location of runtime data ```data-bot-bash```, ```count```
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_VAR # keep in telegram-bot-bash (default)
|
||||||
|
export BASHBOT_VAR "" # keep in telegram-bot-bash
|
||||||
|
|
||||||
|
export BASHBOT_VAR "/var/spool/bashbot" # unix like config location
|
||||||
|
|
||||||
|
export BASHBOT_VAR "/var/spool/bashbot/bot1" # multibot configuration bot 1
|
||||||
|
export BASHBOT_VAR "/var/spool/bashbot/bot2" # multibot configuration bot 2
|
||||||
|
```
|
||||||
|
|
||||||
|
##### BASHBOT_JSONSH
|
||||||
|
Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.sh'.
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_JSONSH # telegram-bot-bash/JSON.sh/JSON.sh (default)
|
||||||
|
export BASHBOT_JSONSH "" # telegram-bot-bash/JSON.sh/JSON.sh
|
||||||
|
|
||||||
|
export BASHBOT_JSONSH "/usr/local/bin/JSON.sh" # installed in /usr/local/bin
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### BASHBOT_HOME
|
||||||
|
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.
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_HOME # autodetection (default)
|
||||||
|
export BASHBOT_HOME "" # autodetection
|
||||||
|
|
||||||
|
export BASHBOT_HOME "/usr/local/telegram-bot-bash" # unix like location
|
||||||
|
export BASHBOT_HOME "/usr/local/bin" # Note: you MUST set ETC, VAR and JSONSH to other locations to make this work!
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
#### 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.
|
||||||
|
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_URL # use Telegram URL https://api.telegram.org/bot<token> (default)
|
||||||
|
|
||||||
|
export BASHBOT_URL "" # use use Telegram https://api.telegram.org/bot<token>
|
||||||
|
|
||||||
|
export BASHBOT_URL "https://my.url.com/bot" # use your URL https://my.url.com/bot<token>
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### BASHBOT_TOKEN
|
||||||
|
|
||||||
|
##### 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.
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_WGET # use curl (default)
|
||||||
|
export BASHBOT_WGET "" # use curl
|
||||||
|
|
||||||
|
export BASHBOT_WGET "yes" # use wget
|
||||||
|
export BASHBOT_WGET "no" # use wget!
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
##### BASHBOT_SLEEP
|
||||||
|
Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling.
|
||||||
|
If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay
|
||||||
|
for every poll until the maximum of BASHBOT_SLEEP ms.
|
||||||
|
```bash
|
||||||
|
unset BASHBOT_SLEEP # 5000ms (default)
|
||||||
|
export BASHBOT_SLEEP "" # 5000ms
|
||||||
|
|
||||||
|
export BASHBOT_SLEEP "1000" # 1s maximum sleep
|
||||||
|
export BASHBOT_SLEEP "10000" # 10s maximum sleep
|
||||||
|
export BASHBOT_SLEEP "1" # values < 1000 disables sleep (not recommended)
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Testet configs as of v0.90 release
|
||||||
|
**Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.**
|
||||||
|
|
||||||
|
##### simple Unix like config, for one bot. bashbot is installed in '/usr/local/telegram-bot-bash'
|
||||||
|
```bash
|
||||||
|
# Note: all dirs and files must exist!
|
||||||
|
export BASHBOT_ETC "/etc/bashbot"
|
||||||
|
export BASHBOT_VAR "/var/spool/bashbot"
|
||||||
|
|
||||||
|
/usr/local/telegram-bot-bash/bashbot.sh start
|
||||||
|
```
|
||||||
|
|
||||||
|
##### Unix like config for one bot. bashbot.sh is installed in '/usr/bin'
|
||||||
|
```bash
|
||||||
|
# Note: all dirs and files must exist!
|
||||||
|
export BASHBOT_ETC "/etc/bashbot"
|
||||||
|
export BASHBOT_VAR "/var/spool/bashbot"
|
||||||
|
export BASHBOT_JSONSH "/var/spool/bashbot"
|
||||||
|
|
||||||
|
/usr/local/bin/bashbot.sh start
|
||||||
|
```
|
||||||
|
|
||||||
|
##### simple multibot config, everything is keept inside 'telegram-bot-bash' dir
|
||||||
|
```bash
|
||||||
|
# config for running Bot 1
|
||||||
|
# Note: all dirs and files must exist!
|
||||||
|
export BASHBOT_ETC "./mybot1"
|
||||||
|
export BASHBOT_VAR "./mybot1"
|
||||||
|
|
||||||
|
/usr/local/telegram-bot-bash/bashbot.sh start
|
||||||
|
```
|
||||||
|
|
||||||
|
```bash
|
||||||
|
# config for running Bot 2
|
||||||
|
# Note: all dirs and files must exist!
|
||||||
|
export BASHBOT_ETC "./mybot2"
|
||||||
|
export BASHBOT_VAR "./mybot2"
|
||||||
|
|
||||||
|
/usr/local/telegram-bot-bash/bashbot.sh start
|
||||||
|
```
|
||||||
|
|
||||||
|
#### [Prev Advanced Use](3_advanced.md)
|
||||||
#### [Next Best Practice](5_practice.md)
|
#### [Next Best Practice](5_practice.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
@ -35,34 +35,33 @@ mycommands() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Reuse or disable global commands
|
### Overwrite, extend and disable global commands
|
||||||
|
|
||||||
If you want to disable or reuse a global bashbot command comment it out in 'commands.sh' by placing a '#' in front of
|
You can overwrite a global bashbot command by placing the same commands in ```mycommands.sh``` and add ```return 1```
|
||||||
every line from ```'/command')``` to ```;;```.
|
ad the end of your command, see '/kickme' below.
|
||||||
|
|
||||||
|
To disable a global bashbot command place create a command simply containing 'return 1', see '/leave' below.
|
||||||
|
|
||||||
|
In case you want to add some processing to the global bashbot command add ```return 0```, then both command will be executed.
|
||||||
|
|
||||||
**Learn more about [Bot commands](https://core.telegram.org/bots#commands).**
|
**Learn more about [Bot commands](https://core.telegram.org/bots#commands).**
|
||||||
|
|
||||||
**Note: Never disable the catchall command ```*)``` in 'commands.sh'!!**
|
|
||||||
```bash
|
```bash
|
||||||
# file: commands.sh
|
# file: commands.sh
|
||||||
|
|
||||||
case "$MESSAGE" in
|
case "$MESSAGE" in
|
||||||
################################################
|
##########
|
||||||
# GLOBAL commands start here, edit messages only
|
# command overwrite examples
|
||||||
|
'info'*) # output date in front of regular info
|
||||||
#'/start'*)
|
send_normal_message "${CHAT[ID]}" "$(date)"
|
||||||
# send_action "${CHAT[ID]}" "typing"
|
return 0
|
||||||
# _is_botadmin && _markdown_message "You are *BOTADMIN*."
|
;;
|
||||||
# if _is_allowed "start" ; then
|
'/kickme'*) # this will replace the /kickme command
|
||||||
# _markdown_message "${bot_help}"
|
send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*"
|
||||||
# else
|
return 1
|
||||||
# _message "You are not allowed to start Bot."
|
;;
|
||||||
# fi
|
'/leave'*) # disable all commands starting with leave
|
||||||
# ;;
|
return 1
|
||||||
|
|
||||||
*) # forward other messages to optional dispatcher
|
|
||||||
_is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}"
|
|
||||||
_is_function mycommands && mycommands
|
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
```
|
```
|
||||||
@ -153,5 +152,5 @@ The second warning is about an unused variable, this is true because in our exam
|
|||||||
#### [Prev Best Practice](5_practice.md)
|
#### [Prev Best Practice](5_practice.md)
|
||||||
#### [Next Functions Reference](6_reference.md)
|
#### [Next Functions Reference](6_reference.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
@ -453,6 +453,66 @@ Usually message is automatically forwarded in 'commands.sh', but you can forwar
|
|||||||
|
|
||||||
*replaces:*' incproc
|
*replaces:*' incproc
|
||||||
|
|
||||||
|
### JSON.sh DB
|
||||||
|
Since output of JSON.sh is so handy to use in bash, we provide a simple wrapper to read and write JSON.sh style data from and to files.
|
||||||
|
File name is prefixed with BASHBOT_ETC and the suffix '.jssh' is added to file name! File names must not contain '..'
|
||||||
|
|
||||||
|
*Example:* for file name:
|
||||||
|
```bash
|
||||||
|
# bashbot is installed in /usr/local/telegram-bot-bash, no BASHBOT_ETC set.
|
||||||
|
"myfile" -> /usr/local/telegram-bot-bash/myfile.jssh
|
||||||
|
"addons/myfile" -> /usr/local/telegram-bot-bash/addons/myfile.jssh
|
||||||
|
"${DATADIR}/myfile usr/local/telegram-bot-bash/data-bot-bash/myfile.jssh
|
||||||
|
```
|
||||||
|
|
||||||
|
You must include ```source modules/jsshDB.sh``` in 'commands.sh' to have the following functions availible.
|
||||||
|
|
||||||
|
##### jssh_newDB
|
||||||
|
Creats new empty "DB" file if not exist.
|
||||||
|
|
||||||
|
*usage:* jssh_newDB "filename"
|
||||||
|
|
||||||
|
##### jssh_readDB
|
||||||
|
Read content of a file in JSON.sh format into given ARRAY. ARRAY name must be delared with "declare -A ARRAY" upfront,
|
||||||
|
|
||||||
|
*usage:* jssh_readDB "ARRAY" "filename"
|
||||||
|
|
||||||
|
*example:*
|
||||||
|
```bash
|
||||||
|
# read file data-bot-bash/somevalues.jssh into array SOMEVALUES
|
||||||
|
jssh_readDB "SOMEVALUES" "${DATADIR:-}/somevalues"
|
||||||
|
|
||||||
|
print "${SOMEVALUES[*]}"
|
||||||
|
```
|
||||||
|
|
||||||
|
##### jssh_writeDB
|
||||||
|
wWrite content of given ARRAY into file. ARRAY name must be delared with "declare -A ARRAY" upfront,
|
||||||
|
"DB" file MUST exist or nothing is written.
|
||||||
|
|
||||||
|
*usage:* jssh_writeDB "ARRAY" "filename"
|
||||||
|
|
||||||
|
*example:*
|
||||||
|
```bash
|
||||||
|
MYVALUES["value1"]="value1"
|
||||||
|
MYVALUES["loveit"]="value2"
|
||||||
|
MYVALUES["whynot"]="value3"
|
||||||
|
|
||||||
|
# create DB
|
||||||
|
jssh_newDB "${DATADIR:-}/myvalues"
|
||||||
|
|
||||||
|
# write to file data-bot-bash/somevalues.jssh from array MYVALUES
|
||||||
|
jssh_writeDB "MYVALUES" "${DATADIR:-}/myvalues"
|
||||||
|
|
||||||
|
# show whats written
|
||||||
|
cat ""${DATADIR:-}/myvalues.jssh"
|
||||||
|
["value1"] "value1"
|
||||||
|
["loveit"] "value2"
|
||||||
|
["whynot"] "value3"
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
### Aliases - shortcuts for often used funtions
|
### Aliases - shortcuts for often used funtions
|
||||||
You must include ```source modules/aliases.sh``` in 'commands.sh' to have the following functions availible.
|
You must include ```source modules/aliases.sh``` in 'commands.sh' to have the following functions availible.
|
||||||
|
|
||||||
@ -565,11 +625,29 @@ file="$(download "https://avatars.githubusercontent.com/u/13046303" "avatar.jpg"
|
|||||||
echo "$file" -> ./data-bot-bash/12345-avatar.jpg
|
echo "$file" -> ./data-bot-bash/12345-avatar.jpg
|
||||||
```
|
```
|
||||||
|
|
||||||
|
##### _exec_if_function
|
||||||
|
Returns true, even if the given function does not exist. Return false if function exist but returns false.
|
||||||
|
|
||||||
|
*usage:* _exec_if_function function
|
||||||
|
|
||||||
|
*example:*
|
||||||
|
```bash
|
||||||
|
_exec_if_function "answer_inline_query" "${iQUERY[ID]}" "Answer params"
|
||||||
|
|
||||||
|
# fast replacment for module functions exists check:
|
||||||
|
if _is_function "answer_inline_query"
|
||||||
|
then
|
||||||
|
"answer_inline_query" "${iQUERY[ID]}" "Answer params"
|
||||||
|
fi
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
##### _exists
|
##### _exists
|
||||||
Returns true if the given function exist, can be used to check if a module is loaded.
|
Returns true if the given function exist, can be used to check if a module is loaded.
|
||||||
|
|
||||||
*usage* _exists command
|
*usage* _exists command
|
||||||
|
|
||||||
|
|
||||||
*example:*
|
*example:*
|
||||||
```bash
|
```bash
|
||||||
_exists "curl" && _message "Command curl is not installed!"
|
_exists "curl" && _message "Command curl is not installed!"
|
||||||
@ -585,7 +663,6 @@ Returns true if the given function exist, can be used to check if a module is lo
|
|||||||
_is_function "background" && _message "you can run background jobs!"
|
_is_function "background" && _message "you can run background jobs!"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
### Bashbot internal functions
|
### Bashbot internal functions
|
||||||
@ -655,7 +732,7 @@ Outputs decoded string to STDOUT
|
|||||||
*usage:* JsonDecode "string"
|
*usage:* JsonDecode "string"
|
||||||
|
|
||||||
##### JsonGetString
|
##### JsonGetString
|
||||||
Reads JSON fro STDIN and Outputs found String to STDOUT
|
Reads JSON from STDIN and Outputs found String to STDOUT
|
||||||
|
|
||||||
*usage:* JsonGetString `"path","to","string"`
|
*usage:* JsonGetString `"path","to","string"`
|
||||||
|
|
||||||
@ -664,12 +741,23 @@ Reads JSON fro STDIN and Outputs found Value to STDOUT
|
|||||||
|
|
||||||
*usage:* JsonGetValue `"path","to","value"`
|
*usage:* JsonGetValue `"path","to","value"`
|
||||||
|
|
||||||
|
|
||||||
|
##### Json2Array
|
||||||
|
Read JSON.sh style data from STDIN and asssign to given ARRAY
|
||||||
|
ARRAY name must be declared with "declare -A ARRAY" before calling
|
||||||
|
|
||||||
|
*usage:* Json2Array "ARRAY"
|
||||||
|
|
||||||
|
##### Array2Json
|
||||||
|
Output ARRAY as JSON.sh style data to STDOUT
|
||||||
|
|
||||||
|
*usage:* Array2Json "ARRAY"
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
##### get_chat_member_status
|
##### get_chat_member_status
|
||||||
*usage:* get_chat_member_status "${CHAT[ID]}" "${USER[ID]}"
|
*usage:* get_chat_member_status "${CHAT[ID]}" "${USER[ID]}"
|
||||||
|
|
||||||
this may get an official function ...
|
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
@ -679,14 +767,30 @@ Every Message sent to your Bot is processd by this function. It parse the send J
|
|||||||
##### process_updates
|
##### process_updates
|
||||||
If new updates are availible, this functions gets the JSON from Telegram and dispatch it.
|
If new updates are availible, this functions gets the JSON from Telegram and dispatch it.
|
||||||
|
|
||||||
|
##### process_inline
|
||||||
|
Every Inline Message sent to your Bot is processd by this function. It parse the send JSON and assign the found Values to bash variables.
|
||||||
|
|
||||||
|
##### start_timer
|
||||||
|
Start the the every minute timer ...
|
||||||
|
|
||||||
|
##### event_timer
|
||||||
|
Dispachter for BASHBOT_EVENT_TIMER
|
||||||
|
|
||||||
|
##### event_timer
|
||||||
|
Dispachter for BASHBOT_EVENT_INLINE
|
||||||
|
|
||||||
|
##### event_timer
|
||||||
|
Dispachter for BASHBOT_EVENT_MESSAGE and related
|
||||||
|
|
||||||
----
|
----
|
||||||
|
|
||||||
##### getBotName
|
##### getBotName
|
||||||
The name of your bot is availible as bash variable "$ME", there is no need to call this function if Bot is running.
|
The name of your bot is availible as bash variable "$ME", there is no need to call this function if Bot is running.
|
||||||
|
|
||||||
*usage:* ME="$(getBotNiname)"
|
*usage:* ME="$(getBotName)"
|
||||||
|
|
||||||
#### [Prev Best Practice](5_practice.md)
|
#### [Prev Best Practice](5_practice.md)
|
||||||
#### [Next Notes for Developers](7_develop.md)
|
#### [Next Notes for Developers](7_develop.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-1-g75691dc
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
111
doc/7_develop.md
111
doc/7_develop.md
@ -1,4 +1,5 @@
|
|||||||
#### [Home](../README.md)
|
#### [Home](../README.md)
|
||||||
|
|
||||||
## Notes for bashbot developers
|
## Notes for bashbot developers
|
||||||
This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development.
|
This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, not on develop your individual bot. Nevertheless the rules and tools described here can also help you with your bot development.
|
||||||
|
|
||||||
@ -6,7 +7,8 @@ bashbot development is done on github. If you want to provide fixes or new featu
|
|||||||
|
|
||||||
### Debugging Bashbot
|
### Debugging Bashbot
|
||||||
In normal mode of operation all bashbot output is discarded.
|
In normal mode of operation all bashbot output is discarded.
|
||||||
To get these messages (and more) you can start bashbot in the current shell ```./bashbot.sh startbot```. Now you can see all output or erros from bashbot.
|
To get these messages (and more) you can start bashbot in the current shell with ```./bashbot.sh startbot &```.
|
||||||
|
Now you can see all output or erros from bashbot.
|
||||||
In addition you can change the change the level of verbosity by adding a third argument after startbot.
|
In addition you can change the change the level of verbosity by adding a third argument after startbot.
|
||||||
```
|
```
|
||||||
"debug" redirects all output to "DEBUG.log", in addtion every update is logged in "MESSAGE.LOG" and "INLINE.log"
|
"debug" redirects all output to "DEBUG.log", in addtion every update is logged in "MESSAGE.LOG" and "INLINE.log"
|
||||||
@ -16,7 +18,93 @@ In addition you can change the change the level of verbosity by adding a third a
|
|||||||
"xdebugterm" same as xdebug but output and errors are sent to terminal
|
"xdebugterm" same as xdebug but output and errors are sent to terminal
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create a stripped down Version of your Bot
|
To stop bashhbot in debugging mode run ```ps -uf | grep debug``` and use 'kill -9' to kill all processes shwon.
|
||||||
|
|
||||||
|
### Modules and Addons
|
||||||
|
**Modules** live in ```modules/*.sh``` and are bashbot functions factored out in seperate files, gouped by functionality. Main reason for creating modules was
|
||||||
|
to keep 'bashbot.sh' small, while extending functionality. In addition not every functionality is needed by a bot, so you can
|
||||||
|
disable modules by removing them, e.g. rename the respective module files to 'module.sh.off'.
|
||||||
|
|
||||||
|
Modules must use only functions provided by 'bahsbot.sh' or the module itself, no depedencies to other modules or addons must exist.
|
||||||
|
If a module function is called from 'bashbot.sh', bashbot must work if the module is disabled, so the use of ```_is_function``` and
|
||||||
|
```_execute_if_function``` is mandatory.
|
||||||
|
|
||||||
|
**Addons** live in ```addons/*.sh.dist``` and are disabled by default. To activate an addon remove '.dist' from the filename, e.g.
|
||||||
|
```cp addons/example.sh.dist addons/example.sh```. Addons must register to BASHBOT_EVENTS at startup, e.g. to call a function everytime a message is recieved.
|
||||||
|
Registering to EVENTS is similar on how 'commands.sh' is executed, but more flexible and one major difference:
|
||||||
|
**Addons are executed in the context of the main script**, while 'commands.sh' is executed as a seperate process.
|
||||||
|
|
||||||
|
This is why event functions are time critical and must return as fast as possible. Spawn actions as a seperate process or function with '&', e.g.
|
||||||
|
send a message as respone from an addon: ```send_message "${CHAT[ID]}" "Message to send ..." &```.
|
||||||
|
|
||||||
|
#### Bashbot Events
|
||||||
|
Addons must register functions to bashbot events at startup by providing their name and a callback function.
|
||||||
|
If an event occours each registered function for the event is called.
|
||||||
|
|
||||||
|
Events run in the same context as the main bashbot loop, so variables set here are persistent as long bashbot is running.
|
||||||
|
|
||||||
|
Note: For the same reason event function MUST return imideatly! Time consuming tasks must be run in background or as a subshell, e.g. "long running &"
|
||||||
|
|
||||||
|
Availible events:
|
||||||
|
|
||||||
|
* BASHBOT_EVENT_INLINE an inline query is received
|
||||||
|
* BASHBOT_EVENT_MESSAGE any type of message is received
|
||||||
|
* BASHBOT_EVENT_TEXT a message containing text is recieved
|
||||||
|
* BASHBOT_EVENT_CMD a command is recieved (fist word starts with /)
|
||||||
|
* BASHBOT_EVENT_REPLYTO a reply to a message is received
|
||||||
|
* BASHBOT_EVENT_FORWARD a forwarded message is received
|
||||||
|
* BASHBOT_EVENT_CONTACT a contact is received
|
||||||
|
* BASHBOT_EVENT_LOCATION a location or a venue is received
|
||||||
|
* BASHBOT_EVENT_FILE a file is received
|
||||||
|
|
||||||
|
*usage*: BASHBOT_EVENT_xxx[ "uniqe-name" ]="callback"
|
||||||
|
|
||||||
|
"unique-name" can be every alphanumeric string incl. '-' and '_'. Per convention it is the name of the addon followed by an internal identyfier.
|
||||||
|
|
||||||
|
*Example:* Register a function to echo to any Text send to the bot
|
||||||
|
```bash
|
||||||
|
# register callback:
|
||||||
|
BASHBOT_EVENT_TEXT["example_1"]="example_echo"
|
||||||
|
|
||||||
|
# function called if a text is received
|
||||||
|
example_echo() {
|
||||||
|
# all availible bashbot functions and variables can be used
|
||||||
|
send_normal_message "${CHAT[ID]}" "${MESSAGE[0]}" & # note the &!
|
||||||
|
}
|
||||||
|
```
|
||||||
|
* BAHSBOT_EVENT_TIMER is executed every minute and can be used in 3 variants: oneshot, every minute, every X minutes.
|
||||||
|
|
||||||
|
Registering to BASHBOT_EVENT_TIMER works isimilar as for message events, but you must add a timing argument to the index name.
|
||||||
|
|
||||||
|
*usage:* BAHSBOT_EVENT_TIMER[ "name" , "time" ], where time is:
|
||||||
|
|
||||||
|
* -x execute ONCE in x minutes
|
||||||
|
* 0 ignored
|
||||||
|
* 1 execute every minute
|
||||||
|
* x execute every x minutes
|
||||||
|
|
||||||
|
*Examples:*
|
||||||
|
```bash
|
||||||
|
# register callback:
|
||||||
|
BAHSBOT_EVENT_TIMER["example_every","1"]="example_everymin"
|
||||||
|
|
||||||
|
# function called every minute
|
||||||
|
example_everymin() {
|
||||||
|
# timer events has no chat id, so send to yourself
|
||||||
|
send_normal_message "$(< "${BOTADMIN})" "$(date)" & # note the &!
|
||||||
|
}
|
||||||
|
|
||||||
|
# register other callback:
|
||||||
|
BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
|
||||||
|
|
||||||
|
BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
|
||||||
|
|
||||||
|
|
||||||
|
```
|
||||||
|
|
||||||
|
----
|
||||||
|
|
||||||
|
#### Create a stripped down Version of your Bot
|
||||||
Currently bashbot is more a bot development environment than a bot, containing examples, developer scripts, modules, documentation and more.
|
Currently bashbot is more a bot development environment than a bot, containing examples, developer scripts, modules, documentation and more.
|
||||||
You don't need all these files after you're finished with your cool new bot.
|
You don't need all these files after you're finished with your cool new bot.
|
||||||
|
|
||||||
@ -39,7 +127,7 @@ Now have a look at the directory 'standalone', here you find the files 'bashbot.
|
|||||||
5. give your (dev) fork a new version tag: ```git tag vx.xx```(optional)
|
5. give your (dev) fork a new version tag: ```git tag vx.xx```(optional)
|
||||||
6. setup github hooks by running ```dev/install-hooks.sh``` (optional)
|
6. setup github hooks by running ```dev/install-hooks.sh``` (optional)
|
||||||
|
|
||||||
### Test, Add, Push changes
|
#### Test, Add, Push changes
|
||||||
A typical bashbot develop loop looks as follow:
|
A typical bashbot develop loop looks as follow:
|
||||||
|
|
||||||
1. start developing - *change, copy, edit bashbot files ...*
|
1. start developing - *change, copy, edit bashbot files ...*
|
||||||
@ -51,7 +139,7 @@ A typical bashbot develop loop looks as follow:
|
|||||||
|
|
||||||
**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, addding and testing is done automatically.**
|
||||||
|
|
||||||
### common commands
|
#### 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.
|
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 availible, but if commands are missing, bashbot may not work.
|
||||||
|
|
||||||
@ -94,7 +182,7 @@ INDEX="$(( ${INDEX} + 1 ))" -> (( INDEX++ ))
|
|||||||
```
|
```
|
||||||
For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible)
|
For more examples see [Pure bash bible](https://github.com/dylanaraps/pure-bash-bible)
|
||||||
|
|
||||||
### Prepare a new version
|
#### Prepare a new version
|
||||||
After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or
|
After some development it may time to create a new version for the users. a new version can be in sub version upgrade, e.g. for fixes and smaller additions or
|
||||||
a new release version for new features. To mark a new version use ```git tag NEWVERSION``` and run ```dev/version.sh``` to update all version strings.
|
a new release version for new features. To mark a new version use ```git tag NEWVERSION``` and run ```dev/version.sh``` to update all version strings.
|
||||||
|
|
||||||
@ -105,7 +193,7 @@ Usually I start with pre versions and when everything looks good I push out a re
|
|||||||
|
|
||||||
If you release a new Version run ```dev/make-distribution.sh``` to create the zip and tar.gz archives in the dist directory and attach them to the github release. Do not forget to delete directory dist afterwards.
|
If you release a new Version run ```dev/make-distribution.sh``` to create the zip and tar.gz archives in the dist directory and attach them to the github release. Do not forget to delete directory dist afterwards.
|
||||||
|
|
||||||
### Versioning
|
#### Versioning
|
||||||
|
|
||||||
Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version.
|
Bashbot is tagged with version numbers. If you start a new development cycle you can tag your fork with a version higher than the current version.
|
||||||
E.g. if you fork 'v0.60' the next develop version should tagged as ```git tag "v0.61-dev"``` for fixes or ```git tag "v0.70-dev"``` for new features.
|
E.g. if you fork 'v0.60' the next develop version should tagged as ```git tag "v0.61-dev"``` for fixes or ```git tag "v0.70-dev"``` for new features.
|
||||||
@ -116,22 +204,22 @@ To update the Version Number in files run ```dev/version.sh files```, it will up
|
|||||||
To update version in all files run 'dev/version.sh' without parameter.
|
To update version in all files run 'dev/version.sh' without parameter.
|
||||||
|
|
||||||
|
|
||||||
### Shellcheck
|
#### Shellcheck
|
||||||
|
|
||||||
For a shell script running as a service it's important to be paranoid about quoting, globbing and other common problems. So it's a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6.
|
For a shell script running as a service it's important to be paranoid about quoting, globbing and other common problems. So it's a must to run shellchek on all shell scripts before you commit a change. this is automated by a git hook activated in Setup step 6.
|
||||||
|
|
||||||
To run shellcheck for a single script run ```shellcheck -x script.sh```, to check all schripts run ```dev/hooks/pre-commit.sh```.
|
To run shellcheck for a single script run ```shellcheck -x script.sh```, to check all schripts run ```dev/hooks/pre-commit.sh```.
|
||||||
|
|
||||||
|
|
||||||
## bashbot tests
|
### bashbot tests
|
||||||
Starting with version 0.70 bashbot has a test suite. To start testsuite run ```dev/all-tests.sh```. all-tests.sh will return 'SUCCESS' only if all tests pass.
|
Starting with version 0.70 bashbot has a test suite. To start testsuite run ```dev/all-tests.sh```. all-tests.sh will return 'SUCCESS' only if all tests pass.
|
||||||
|
|
||||||
### enabling / disabling tests
|
#### enabling / disabling tests
|
||||||
|
|
||||||
All tests are placed in the directory ```test```. To disable a test remove the execute flag from the '*-test.sh' script, to (re)enable a test make the script executable again.
|
All tests are placed in the directory ```test```. To disable a test remove the execute flag from the '*-test.sh' script, to (re)enable a test make the script executable again.
|
||||||
|
|
||||||
|
|
||||||
### creating new tests
|
#### creating new tests
|
||||||
To create a new test run ```test/ADD-test-new.sh``` and answer the questions, it will create the usually needed files and dirs:
|
To create a new test run ```test/ADD-test-new.sh``` and answer the questions, it will create the usually needed files and dirs:
|
||||||
|
|
||||||
Each test consists of a script script named after ```p-name-test.sh``` *(where p is test pass 'a-z' and name the name
|
Each test consists of a script script named after ```p-name-test.sh``` *(where p is test pass 'a-z' and name the name
|
||||||
@ -186,7 +274,6 @@ fi
|
|||||||
```
|
```
|
||||||
|
|
||||||
#### [Prev Function Reference](6_reference.md)
|
#### [Prev Function Reference](6_reference.md)
|
||||||
#### [Next Bashbot Environment](8_custom.md)
|
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
135
doc/8_custom.md
135
doc/8_custom.md
@ -1,135 +0,0 @@
|
|||||||
#### [Home](../README.md)
|
|
||||||
## Customize bashbots environment
|
|
||||||
This section describe how you can customize bashbot to your needs by setting environment variables.
|
|
||||||
|
|
||||||
|
|
||||||
### Change file locations
|
|
||||||
In standard setup bashbot is self containing, this means you can place 'telegram-bot-bash' any location
|
|
||||||
and run it from there. All files - programm, config, data etc - will reside in 'telegram-bot-bash'.
|
|
||||||
|
|
||||||
If you want to have other locations for config, data etc, define and export the following environment variables.
|
|
||||||
**Note: all specified directories and files must exist or running 'bashbot.sh' will fail.**
|
|
||||||
|
|
||||||
#### BASHBOT_ETC
|
|
||||||
Location of the files ```commands.sh```, ```mycommands.sh```, ```token```, ```botadmin```, ```botacl``` ...
|
|
||||||
```bash
|
|
||||||
unset BASHBOT_ETC # keep in telegram-bot-bash (default)
|
|
||||||
export BASHBOT_ETC "" # keep in telegram-bot-bash
|
|
||||||
|
|
||||||
export BASHBOT_ETC "/etc/bashbot" # unix like config location
|
|
||||||
|
|
||||||
export BASHBOT_ETC "/etc/bashbot/bot1" # multibot configuration bot 1
|
|
||||||
export BASHBOT_ETC "/etc/bashbot/bot2" # multibot configuration bot 2
|
|
||||||
```
|
|
||||||
|
|
||||||
e.g. /etc/bashbot
|
|
||||||
|
|
||||||
#### BASHBOT_VAR
|
|
||||||
Location of runtime data ```data-bot-bash```, ```count```
|
|
||||||
```bash
|
|
||||||
unset BASHBOT_VAR # keep in telegram-bot-bash (default)
|
|
||||||
export BASHBOT_VAR "" # keep in telegram-bot-bash
|
|
||||||
|
|
||||||
export BASHBOT_VAR "/var/spool/bashbot" # unix like config location
|
|
||||||
|
|
||||||
export BASHBOT_VAR "/var/spool/bashbot/bot1" # multibot configuration bot 1
|
|
||||||
export BASHBOT_VAR "/var/spool/bashbot/bot2" # multibot configuration bot 2
|
|
||||||
```
|
|
||||||
|
|
||||||
#### BASHBOT_JSONSH
|
|
||||||
Full path to JSON.sh script, default: './JSON.sh/JSON.sh', must end with '/JSON.sh'.
|
|
||||||
```bash
|
|
||||||
unset BASHBOT_JSONSH # telegram-bot-bash/JSON.sh/JSON.sh (default)
|
|
||||||
export BASHBOT_JSONSH "" # telegram-bot-bash/JSON.sh/JSON.sh
|
|
||||||
|
|
||||||
export BASHBOT_JSONSH "/usr/local/bin/JSON.sh" # installed in /usr/local/bin
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### 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.
|
|
||||||
|
|
||||||
```bash
|
|
||||||
unset BASHBOT_URL # use Telegram URL https://api.telegram.org/bot<token> (default)
|
|
||||||
|
|
||||||
export BASHBOT_URL "" # use use Telegram https://api.telegram.org/bot<token>
|
|
||||||
|
|
||||||
export BASHBOT_URL "https://my.url.com/bot" # use your URL https://my.url.com/bot<token>
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### BASHBOT_TOKEN
|
|
||||||
|
|
||||||
#### 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.
|
|
||||||
```bash
|
|
||||||
unset BASHBOT_WGET # use curl (default)
|
|
||||||
export BASHBOT_WGET "" # use curl
|
|
||||||
|
|
||||||
export BASHBOT_WGET "yes" # use wget
|
|
||||||
export BASHBOT_WGET "no" # use wget!
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
#### BASHBOT_SLEEP
|
|
||||||
Instead of polling permanently or with a fixed delay, bashbot offers a simple adaptive polling.
|
|
||||||
If messages are recieved bashbot polls with no dealy. If no messages are availible bashbot add 100ms delay
|
|
||||||
for every poll until the maximum of BASHBOT_SLEEP ms.
|
|
||||||
```bash
|
|
||||||
unset BASHBOT_SLEEP # 5000ms (default)
|
|
||||||
export BASHBOT_SLEEP "" # 5000ms
|
|
||||||
|
|
||||||
export BASHBOT_SLEEP "1000" # 1s maximum sleep
|
|
||||||
export BASHBOT_SLEEP "10000" # 10s maximum sleep
|
|
||||||
export BASHBOT_SLEEP "1" # values < 1000 disables sleep (not recommended)
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
### Testet configs as of v.07 release
|
|
||||||
**Note: Environment variables are not stored, you must setup them before every call to bashbot.sh, e.g. from a script.**
|
|
||||||
|
|
||||||
#### simple Unix like config, for one bot. bashbot is installed in '/usr/local/telegram-bot-bash'
|
|
||||||
```bash
|
|
||||||
# Note: all dirs and files must exist!
|
|
||||||
export BASHBOT_ETC "/etc/bashbot"
|
|
||||||
export BASHBOT_VAR "/var/spool/bashbot"
|
|
||||||
|
|
||||||
/usr/local/telegram-bot-bash/bashbot.sh start
|
|
||||||
```
|
|
||||||
|
|
||||||
#### Unix like config for one bot. bashbot.sh is installed in '/usr/bin'
|
|
||||||
```bash
|
|
||||||
# Note: all dirs and files must exist!
|
|
||||||
export BASHBOT_ETC "/etc/bashbot"
|
|
||||||
export BASHBOT_VAR "/var/spool/bashbot"
|
|
||||||
export BASHBOT_JSONSH "/var/spool/bashbot"
|
|
||||||
|
|
||||||
/usr/local/bin/bashbot.sh start
|
|
||||||
```
|
|
||||||
|
|
||||||
#### simple multibot config, everything is keept inside 'telegram-bot-bash' dir
|
|
||||||
```bash
|
|
||||||
# config for running Bot 1
|
|
||||||
# Note: all dirs and files must exist!
|
|
||||||
export BASHBOT_ETC "./mybot1"
|
|
||||||
export BASHBOT_VAR "./mybot1"
|
|
||||||
|
|
||||||
/usr/local/telegram-bot-bash/bashbot.sh start
|
|
||||||
```
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# config for running Bot 2
|
|
||||||
# Note: all dirs and files must exist!
|
|
||||||
export BASHBOT_ETC "./mybot2"
|
|
||||||
export BASHBOT_VAR "./mybot2"
|
|
||||||
|
|
||||||
/usr/local/telegram-bot-bash/bashbot.sh start
|
|
||||||
```
|
|
||||||
|
|
||||||
#### [Prev Notes for Developers](7_develop.md)
|
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-2-g58cf901
|
|
||||||
|
|
@ -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.
|
**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users.
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# file: run_filename
|
# file: run_filename
|
||||||
# background job to display content of all new files in WATCHDIR
|
# background job to display content of all new files in WATCHDIR
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# file: run_filename
|
# file: run_filename
|
||||||
# background job to display all new files in WATCHDIR
|
# background job to display all new files in WATCHDIR
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# file. multibot.sh
|
# file. multibot.sh
|
||||||
# description: run multiple telegram bots from one installation
|
# description: run multiple telegram bots from one installation
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||||
echo "Usage: $0 botname command"
|
echo "Usage: $0 botname command"
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
|
|
||||||
SHELL=/bin/sh
|
SHELL=/bin/sh
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
|
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# adjust your language setting here
|
# adjust your language setting here
|
||||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
# file: botacl
|
# file: botacl
|
||||||
# a user not listed here, will return false from 'user_is_allowed'
|
# a user not listed here, will return false from 'user_is_allowed'
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
# Format:
|
# Format:
|
||||||
# user:ressource:chat
|
# user:ressource:chat
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# to show how you can customize bashbot by only editing mycommands.sh
|
# to show how you can customize bashbot by only editing mycommands.sh
|
||||||
# NOTE: this is not tested, simply copied from original source and reworked!
|
# NOTE: this is not tested, simply copied from original source and reworked!
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
#
|
#
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
#
|
#
|
||||||
# source from commands.sh to use the aliases
|
# source from commands.sh to use the aliases
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# source from commands.sh to use the inline functions
|
# source from commands.sh to use the inline functions
|
||||||
|
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# source from commands.sh if you want ro use interactive or background jobs
|
# source from commands.sh if you want ro use interactive or background jobs
|
||||||
|
|
||||||
@ -37,7 +37,7 @@ killproc() {
|
|||||||
# $2 program
|
# $2 program
|
||||||
# $3 jobname
|
# $3 jobname
|
||||||
start_back() {
|
start_back() {
|
||||||
local fifo; fifo="${TMPDIR:-.}/$(procname "$1")"
|
local fifo; fifo="${DATADIR:-.}/$(procname "$1")"
|
||||||
printf '%s\n' "$1:$3:$2" >"${fifo}$3-back.cmd"
|
printf '%s\n' "$1:$3:$2" >"${fifo}$3-back.cmd"
|
||||||
start_proc "$1" "$2" "back-$3-"
|
start_proc "$1" "$2" "back-$3-"
|
||||||
}
|
}
|
||||||
@ -49,7 +49,7 @@ start_back() {
|
|||||||
start_proc() {
|
start_proc() {
|
||||||
[ "$2" = "" ] && return
|
[ "$2" = "" ] && return
|
||||||
[ -x "${2%% *}" ] || return 1
|
[ -x "${2%% *}" ] || return 1
|
||||||
local fifo; fifo="${TMPDIR:-.}/$(procname "$1" "$3")"
|
local fifo; fifo="${DATADIR:-.}/$(procname "$1" "$3")"
|
||||||
kill_proc "$1" "$3"
|
kill_proc "$1" "$3"
|
||||||
mkfifo "${fifo}"
|
mkfifo "${fifo}"
|
||||||
nohup bash -c "{ tail -f < \"${fifo}\" | $2 \"\" \"\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"
|
nohup bash -c "{ tail -f < \"${fifo}\" | $2 \"\" \"\" \"$fifo\" | \"${SCRIPT}\" outproc \"${1}\" \"${fifo}\"
|
||||||
@ -75,7 +75,7 @@ check_proc() {
|
|||||||
# $2 jobname
|
# $2 jobname
|
||||||
kill_back() {
|
kill_back() {
|
||||||
kill_proc "$1" "back-$2-"
|
kill_proc "$1" "back-$2-"
|
||||||
rm -f "${TMPDIR:-.}/$(procname "$1")$2-back.cmd"
|
rm -f "${DATADIR:-.}/$(procname "$1")$2-back.cmd"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ kill_proc() {
|
|||||||
local fifo prid
|
local fifo prid
|
||||||
fifo="$(procname "$1" "$2")"
|
fifo="$(procname "$1" "$2")"
|
||||||
prid="$(proclist "${fifo}")"
|
prid="$(proclist "${fifo}")"
|
||||||
fifo="${TMPDIR:-.}/${fifo}"
|
fifo="${DATADIR:-.}/${fifo}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
[ "${prid}" != "" ] && kill ${prid}
|
[ "${prid}" != "" ] && kill ${prid}
|
||||||
[ -s "${fifo}.log" ] || rm -f "${fifo}.log"
|
[ -s "${fifo}.log" ] || rm -f "${fifo}.log"
|
||||||
@ -95,7 +95,7 @@ kill_proc() {
|
|||||||
# $1 chat
|
# $1 chat
|
||||||
# $2 message
|
# $2 message
|
||||||
send_interactive() {
|
send_interactive() {
|
||||||
local fifo; fifo="${TMPDIR:-.}/$(procname "$1")"
|
local fifo; fifo="${DATADIR:-.}/$(procname "$1")"
|
||||||
[ -p "${fifo}" ] && printf '%s\n' "$2" >"${fifo}" & # not blocking!
|
[ -p "${fifo}" ] && printf '%s\n' "$2" >"${fifo}" & # not blocking!
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,8 +111,8 @@ inproc() {
|
|||||||
# resumeb*
|
# resumeb*
|
||||||
job_control() {
|
job_control() {
|
||||||
local content proc CHAT job fifo killall=""
|
local content proc CHAT job fifo killall=""
|
||||||
for FILE in "${TMPDIR:-.}/"*-back.cmd; do
|
for FILE in "${DATADIR:-.}/"*-back.cmd; do
|
||||||
[ "${FILE}" = "${TMPDIR:-.}/*-back.cmd" ] && echo -e "${RED}No background processes.${NC}" && break
|
[ "${FILE}" = "${DATADIR:-.}/*-back.cmd" ] && echo -e "${RED}No background processes.${NC}" && break
|
||||||
content="$(< "${FILE}")"
|
content="$(< "${FILE}")"
|
||||||
CHAT="${content%%:*}"
|
CHAT="${content%%:*}"
|
||||||
job="${content#*:}"
|
job="${content#*:}"
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# source from commands.sh to use the member functions
|
# source from commands.sh to use the member functions
|
||||||
|
|
||||||
|
50
modules/jsonDB.sh
Normal file
50
modules/jsonDB.sh
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
# file: modules/jsshDB.sh
|
||||||
|
# do not edit, this file will be overwritten on update
|
||||||
|
|
||||||
|
# This file is public domain in the USA and all free countries.
|
||||||
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
|
#
|
||||||
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
#
|
||||||
|
# source from commands.sh to use jsonDB functions
|
||||||
|
#
|
||||||
|
# jsonDB rovides simple functions to read and store bash Arrays
|
||||||
|
# from to file in JSON.sh output format
|
||||||
|
|
||||||
|
# read content of a file in JSON.sh format into given ARRAY
|
||||||
|
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||||
|
# $2 filename, must be relative to BASHBOT_ETC, and not contain '..'
|
||||||
|
jssh_readDB() {
|
||||||
|
local DB; DB="$(jssh_checkname "$2")"
|
||||||
|
[ "${DB}" = "" ] && return 1
|
||||||
|
[ ! -f "${DB}" ] && return 1
|
||||||
|
Json2Array "$1" <"${DB}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# write ARRAY content to a file in JSON.sh format
|
||||||
|
# $1 ARRAY name, must be delared with "declare -A ARRAY" upfront
|
||||||
|
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||||
|
jssh_writeDB() {
|
||||||
|
local DB; DB="$(jssh_checkname "$2")"
|
||||||
|
[ "${DB}" = "" ] && return 1
|
||||||
|
[ ! -f "${DB}" ] && return 1
|
||||||
|
Array2Json "$1" >"${DB}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# $1 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||||
|
jssh_newDB() {
|
||||||
|
local DB; DB="$(jssh_checkname "$1")"
|
||||||
|
[ "${DB}" = "" ] && return 1
|
||||||
|
[ -f "${DB}" ] && return 1 # already exist, do not zero out
|
||||||
|
printf '\n' >"${DB}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# $1 filename, check if must be relative to BASHBOT_ETC, and not contain '..'
|
||||||
|
jssh_checkname(){
|
||||||
|
[ "$1" = "" ] && return 1
|
||||||
|
local DB="${BASHBOT_ETC:-.}/$1.jssh"
|
||||||
|
[[ "$1" = "${BASHBOT_ETC:-.}"* ]] && DB="$1.jssh"
|
||||||
|
[[ "$1" = *'..'* ]] && return 1
|
||||||
|
printf '%s\n' "${DB}"
|
||||||
|
}
|
@ -5,7 +5,7 @@
|
|||||||
# This file is public domain in the USA and all free countries.
|
# This file is public domain in the USA and all free countries.
|
||||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# source from commands.sh to use the sendMessage functions
|
# source from commands.sh to use the sendMessage functions
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ send_button() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
UPLOADDIR="${BASHBOT_UPLOAD:-${TMPDIR}/upload}"
|
UPLOADDIR="${BASHBOT_UPLOAD:-${DATADIR}/upload}"
|
||||||
|
|
||||||
# for now this can only send local files with curl!
|
# for now this can only send local files with curl!
|
||||||
# extend to allow send files by URL or telegram ID
|
# extend to allow send files by URL or telegram ID
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# files: mycommands.sh.dist
|
# files: mycommands.sh.dist
|
||||||
# copy to mycommands.sh and add all your commands and functions here ...
|
# copy to mycommands.sh and add all your commands and functions here ...
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
#
|
#
|
||||||
|
|
||||||
# uncomment the following lines to overwrite info and help messages
|
# uncomment the following lines to overwrite info and help messages
|
||||||
@ -17,6 +17,8 @@ res=""
|
|||||||
export INLINE="0"
|
export INLINE="0"
|
||||||
# Set to .* to allow sending files from all locations
|
# Set to .* to allow sending files from all locations
|
||||||
export FILE_REGEX='/home/user/allowed/.*'
|
export FILE_REGEX='/home/user/allowed/.*'
|
||||||
|
# example: run bashbot over TOR
|
||||||
|
# export BASHBOT_CURL_ARGS="--socks5-hostname 127.0.0.1:9050"
|
||||||
|
|
||||||
if [ "$1" != "source" ];then
|
if [ "$1" != "source" ];then
|
||||||
# your additional bahsbot commands
|
# your additional bahsbot commands
|
||||||
@ -24,6 +26,8 @@ if [ "$1" != "source" ];then
|
|||||||
mycommands() {
|
mycommands() {
|
||||||
|
|
||||||
case "${MESSAGE}" in
|
case "${MESSAGE}" in
|
||||||
|
##################
|
||||||
|
# example commands, replace thm by your own
|
||||||
'/echo'*) # example echo command
|
'/echo'*) # example echo command
|
||||||
send_normal_message "${CHAT[ID]}" "$MESSAGE"
|
send_normal_message "${CHAT[ID]}" "$MESSAGE"
|
||||||
;;
|
;;
|
||||||
@ -54,6 +58,16 @@ if [ "$1" != "source" ];then
|
|||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
|
|
||||||
|
##########
|
||||||
|
# command overwrite examples
|
||||||
|
'info'*) # output date in front of regular info
|
||||||
|
send_normal_message "${CHAT[ID]}" "$(date)"
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
'/kickme'*) # this will replace the /kickme command
|
||||||
|
send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*"
|
||||||
|
return 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
#
|
#
|
||||||
# ADD a new test skeleton to test dir, but does not activate test
|
# ADD a new test skeleton to test dir, but does not activate test
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# magic to ensure that we're always inside the root of our application,
|
# magic to ensure that we're always inside the root of our application,
|
||||||
# no matter from which directory we'll run script
|
# no matter from which directory we'll run script
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# common variables
|
# common variables
|
||||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||||
@ -30,6 +30,10 @@ export INPUTFILE REFFILE OUTPUTFILE
|
|||||||
REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result"
|
REFFILE="${DIRME}/${REFDIR}/${REFDIR}.result"
|
||||||
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
|
OUTPUTFILE="${TESTDIR}/${REFDIR}.out"
|
||||||
|
|
||||||
|
# do not query telegram when testing
|
||||||
|
export BASHBOT_URL
|
||||||
|
BASHBOT_URL="https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?"
|
||||||
|
|
||||||
# print arrays in reproducible order
|
# print arrays in reproducible order
|
||||||
print_array() {
|
print_array() {
|
||||||
local idx t
|
local idx t
|
||||||
@ -50,6 +54,6 @@ echo "............................"
|
|||||||
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
|
[ "${TESTDIR}" = "" ] && echo "${NOSUCCESS} not called from testsuite, exit" && exit 1
|
||||||
|
|
||||||
# reset env for test
|
# reset env for test
|
||||||
unset IFS; set -f
|
unset IFS;
|
||||||
export TERM=""
|
export TERM=""
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
../dev/hooks/pre-commit.sh
|
../dev/hooks/pre-commit.sh
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
# file: b-example-test.sh
|
# file: b-example-test.sh
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -38,6 +38,7 @@ echo "Test if $JSONSHFILE exists ..."
|
|||||||
echo "Test Sourcing of bashbot.sh ..."
|
echo "Test Sourcing of bashbot.sh ..."
|
||||||
# shellcheck source=./bashbot.sh
|
# shellcheck source=./bashbot.sh
|
||||||
source "${TESTDIR}/bashbot.sh" source
|
source "${TESTDIR}/bashbot.sh" source
|
||||||
|
echo "Test Sourcing of commands.sh ..."
|
||||||
source "${TESTDIR}/commands.sh" source
|
source "${TESTDIR}/commands.sh" source
|
||||||
|
|
||||||
trap '' EXIT
|
trap '' EXIT
|
||||||
@ -46,5 +47,4 @@ echo "${SUCCESS}"
|
|||||||
|
|
||||||
echo "Test bashbot.sh count"
|
echo "Test bashbot.sh count"
|
||||||
cp "${REFDIR}/count.test" "${TESTDIR}/count"
|
cp "${REFDIR}/count.test" "${TESTDIR}/count"
|
||||||
"${TESTDIR}/bashbot.sh" count
|
#"${TESTDIR}/bashbot.sh" count
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -20,8 +20,10 @@ get_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# get telegram input from file
|
# get telegram input from file
|
||||||
export UPDATE
|
export UPDATE UPD
|
||||||
UPDATE="$(cat "${INPUTFILE}")"
|
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 phyton
|
||||||
echo "Check process_inline ..."
|
echo "Check process_inline ..."
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
["ok"] true
|
["ok"] true
|
||||||
["result",0,"update_id"]i 1234567890
|
["result",0,"update_id"] 1234567890
|
||||||
["result",0,"inline_query","id"] "987654321"
|
["result",0,"inline_query","id"] "987654321"
|
||||||
["result",0,"inline_query","query"] "message"
|
["result",0,"inline_query","query"] "message"
|
||||||
["result",0,"inline_query","from","id"] 123456789
|
["result",0,"inline_query","from","id"] 123456789
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -20,8 +20,10 @@ get_file() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# get telegram input from file
|
# get telegram input from file
|
||||||
export UPDATE
|
export UPDATE UPD
|
||||||
UPDATE="$(cat "${INPUTFILE}")"
|
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
|
# run process_message
|
||||||
echo "Check process_message ..."
|
echo "Check process_message ..."
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
["ok"] true
|
["ok"] true
|
||||||
["result",0,"update_id"] 146860800
|
["result",0,"update_id"] 146860800
|
||||||
["result",0,"message","message_id"] 6541 6541 # this is a cross check for JsonGetValue
|
["result",0,"message","message_id"] 6541
|
||||||
["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a"
|
["result",0,"message","text"] "\ud83d\ude02\ud83d\ude1d\ud83d\udc4c\u263a\u2764\ud83d\ude15\ud83d\ude08#\u20e3\ud83c\udf0f\ud83c\udf89\ud83d\ude4a\ud83d\ude49\u2615\ud83d\ude80\u2708\ud83d\ude82\ud83d\udcaf\u2714\u303d\ud83d\udd1a"
|
||||||
["result",0,"message","text"] "Cross check, this second text must be ignored"
|
|
||||||
["result",0,"message","from","id"] 123456789
|
["result",0,"message","from","id"] 123456789
|
||||||
["result",0,"message","from","is_bot"] false
|
["result",0,"message","from","is_bot"] false
|
||||||
["result",0,"message","from","first_name"] "Kay"
|
["result",0,"message","from","first_name"] "Kay"
|
||||||
@ -89,5 +88,4 @@
|
|||||||
["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"
|
["result",0,"message","contact","vcard"] "BEGIN:VCARD\nVERSION:2.1\nN:Pannenhilfe;ADAC;;;\nFN:ADAC Pannenhilfe\nTEL;CELL;PREF:+49179222222\nTEL;X-Mobil:222222\nEND:VCARD"
|
||||||
["result",0,"message","voice","duration"] 2
|
["result",0,"message","voice","duration"] 2
|
||||||
["result",0,"message","voice","mime_type"] "audio/ogg"
|
["result",0,"message","voice","mime_type"] "audio/ogg"
|
||||||
["result",0,"message","voice","file_id"] "AwADAgADOAQAAqd24Emnm_VGmmVEuAI"
|
|
||||||
["result",0,"message","voice","file_size"] 4262
|
["result",0,"message","voice","file_size"] 4262
|
||||||
|
@ -2,6 +2,7 @@ USER: FIRST_NAME Kay
|
|||||||
USER: ID 123456789
|
USER: ID 123456789
|
||||||
USER: LAST_NAME M
|
USER: LAST_NAME M
|
||||||
USER: USERNAME Gnadelwartz
|
USER: USERNAME Gnadelwartz
|
||||||
|
CHAT: ALL_ADMIN
|
||||||
CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS
|
CHAT: ALL_MEMBERS_ARE_ADMINISTRATORS
|
||||||
CHAT: FIRST_NAME Test
|
CHAT: FIRST_NAME Test
|
||||||
CHAT: ID 123456789
|
CHAT: ID 123456789
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -42,7 +42,7 @@ ALLOW='/tmp/allowed'
|
|||||||
FILE_REGEX="$ALLOW/.*"
|
FILE_REGEX="$ALLOW/.*"
|
||||||
[ -d "$ALLOW" ] || mkdir "$ALLOW"
|
[ -d "$ALLOW" ] || mkdir "$ALLOW"
|
||||||
touch "$ALLOW/this_is_my.gif" "$ALLOW/this_is_my.doc"
|
touch "$ALLOW/this_is_my.gif" "$ALLOW/this_is_my.doc"
|
||||||
touch "$TMPDIR/this_is_my.gif" "$TMPDIR/this_is_my.doc"
|
touch "$DATADIR/this_is_my.gif" "$DATADIR/this_is_my.doc"
|
||||||
|
|
||||||
while read -r line ; do
|
while read -r line ; do
|
||||||
echo -n "."
|
echo -n "."
|
||||||
|
@ -1,64 +1,64 @@
|
|||||||
chat:123456 JSON:"text":"# test for text only output"
|
chat:123456 JSON:"text":"# test for text only output"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"This is a normal text"
|
chat:123456 JSON:"text":"This is a normal text"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"This is a normal text
|
chat:123456 JSON:"text":"This is a normal text
|
||||||
with a line break"
|
with a line break"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":" This is a <b>HTML</b> text","parse_mode":"html"
|
chat:123456 JSON:"text":" This is a <b>HTML</b> text","parse_mode":"html"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":" This is a <b>HTML</b> text
|
chat:123456 JSON:"text":" This is a <b>HTML</b> text
|
||||||
with a line break","parse_mode":"html"
|
with a line break","parse_mode":"html"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":" This is a *MARKDOWN* text","parse_mode":"markdown"
|
chat:123456 JSON:"text":" This is a *MARKDOWN* text","parse_mode":"markdown"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":" This is a *MARKDOWN* text
|
chat:123456 JSON:"text":" This is a *MARKDOWN* text
|
||||||
with a line break","parse_mode":"markdown"
|
with a line break","parse_mode":"markdown"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"# test for keyboard, file, venue output"
|
chat:123456 JSON:"text":"# test for keyboard, file, venue output"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true}
|
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"keyboard": [ [ "Yep, sure" , "No, highly unlikely" ] ] , "one_time_keyboard":true}
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"latitude": la10, "longitude": lo20
|
chat:123456 JSON:"latitude": la10, "longitude": lo20
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendLocation
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendLocation
|
||||||
|
|
||||||
chat:123456 JSON:"latitude": la10, "longitude": lo20, "address": "Diagon Alley N. 37", "title": "my home"
|
chat:123456 JSON:"latitude": la10, "longitude": lo20, "address": "Diagon Alley N. 37", "title": "my home"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendVenue
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendVenue
|
||||||
|
|
||||||
chat:123456 JSON:"text":"# test for new inline button"
|
chat:123456 JSON:"text":"# test for new inline button"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]}
|
chat:123456 JSON:"text":"Text plus keyboard will appear in chat", "reply_markup": {"inline_keyboard": [ [ {"text":"Button Text", "url":"https://www..."}] ]}
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"STABILO 88/240 Fineliner point 88
|
chat:123456 JSON:"text":"STABILO 88/240 Fineliner point 88
|
||||||
|
|
||||||
[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg]
|
[https://images-na.ssl-images-amazon.com/images/I/41oypA3kmHL.l_SX300.jpg]
|
||||||
second part of text
|
second part of text
|
||||||
plus newline.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen ...", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]}
|
plus newline.", "reply_markup": {"inline_keyboard": [ [ {"text":"Bei Amazon ansehen ...", "url":"https://www.amazon.de/dp/B014TN3JYW"}] ]}
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"text":"# test for sendfile"
|
chat:123456 JSON:"text":"# test for sendfile"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendMessage
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendMessage
|
||||||
|
|
||||||
chat:123456 JSON:"action": "upload_photo"
|
chat:123456 JSON:"action": "upload_photo"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendChatAction
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendChatAction
|
||||||
|
|
||||||
chat:123456 JSON:"photo":"/tmp/allowed/this_is_my.gif","caption":"Text plus absolute file will appear in chat"
|
chat:123456 JSON:"photo":"/tmp/allowed/this_is_my.gif","caption":"Text plus absolute file will appear in chat"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendPhoto
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendPhoto
|
||||||
|
|
||||||
chat:123456 JSON:"action": "upload_document"
|
chat:123456 JSON:"action": "upload_document"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendChatAction
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendChatAction
|
||||||
|
|
||||||
chat:123456 JSON:"document":"/tmp/allowed/this_is_my.doc","caption":"Text plus absolute file will appear in chat"
|
chat:123456 JSON:"document":"/tmp/allowed/this_is_my.doc","caption":"Text plus absolute file will appear in chat"
|
||||||
URL:https://api.telegram.org/botbashbottestscript/sendDocument
|
URL:https://my-json-server.typicode.com/topkecleon/telegram-bot-bash/getMe?bashbottestscript/sendDocument
|
||||||
|
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v0.80-0-g5bce3f7
|
#### $$VERSION$$ v0.90-rc1-0-ge80b98a
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -31,7 +31,7 @@ set +f
|
|||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
|
cp ${TESTDIR}/*commands.sh "${BASHBOT_ETC}" || exit 1
|
||||||
set -f
|
set -f
|
||||||
cp "${TESTDIR}/bashbot.sh" "${BASHBOT_BIN}" || exit 1
|
cp -r "${TESTDIR}/bashbot.sh" "${TESTDIR}/modules" "${BASHBOT_BIN}" || exit 1
|
||||||
|
|
||||||
TESTTOKEN="bashbottestscript"
|
TESTTOKEN="bashbottestscript"
|
||||||
TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}"
|
TESTFILES="${TOKENFILE} ${ACLFILE} ${ADMINFILE}"
|
||||||
|
Loading…
Reference in New Issue
Block a user