mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2025-01-25 22:58:25 +00:00
commit
6dc8f1b267
209
README.html
209
README.html
@ -6,73 +6,74 @@
|
|||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes" />
|
||||||
<title>Bashbot README</title>
|
<title>Bashbot README</title>
|
||||||
<style>
|
<style>
|
||||||
code{white-space: pre-wrap;}
|
code{white-space: pre-wrap;}
|
||||||
span.smallcaps{font-variant: small-caps;}
|
span.smallcaps{font-variant: small-caps;}
|
||||||
span.underline{text-decoration: underline;}
|
span.underline{text-decoration: underline;}
|
||||||
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
div.column{display: inline-block; vertical-align: top; width: 50%;}
|
||||||
</style>
|
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
|
||||||
<style>
|
ul.task-list{list-style: none;}
|
||||||
a.sourceLine { display: inline-block; line-height: 1.25; }
|
pre > code.sourceCode { white-space: pre; position: relative; }
|
||||||
a.sourceLine { pointer-events: none; color: inherit; text-decoration: inherit; }
|
pre > code.sourceCode > span { display: inline-block; line-height: 1.25; }
|
||||||
a.sourceLine:empty { height: 1.2em; }
|
pre > code.sourceCode > span:empty { height: 1.2em; }
|
||||||
.sourceCode { overflow: visible; }
|
code.sourceCode > span { color: inherit; text-decoration: inherit; }
|
||||||
code.sourceCode { white-space: pre; position: relative; }
|
div.sourceCode { margin: 1em 0; }
|
||||||
div.sourceCode { margin: 1em 0; }
|
pre.sourceCode { margin: 0; }
|
||||||
pre.sourceCode { margin: 0; }
|
@media screen {
|
||||||
@media screen {
|
div.sourceCode { overflow: auto; }
|
||||||
div.sourceCode { overflow: auto; }
|
}
|
||||||
}
|
@media print {
|
||||||
@media print {
|
pre > code.sourceCode { white-space: pre-wrap; }
|
||||||
code.sourceCode { white-space: pre-wrap; }
|
pre > code.sourceCode > span { text-indent: -5em; padding-left: 5em; }
|
||||||
a.sourceLine { text-indent: -1em; padding-left: 1em; }
|
}
|
||||||
}
|
pre.numberSource code
|
||||||
pre.numberSource a.sourceLine
|
{ counter-reset: source-line 0; }
|
||||||
{ position: relative; left: -4em; }
|
pre.numberSource code > span
|
||||||
pre.numberSource a.sourceLine::before
|
{ position: relative; left: -4em; counter-increment: source-line; }
|
||||||
{ content: attr(title);
|
pre.numberSource code > span > a:first-child::before
|
||||||
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
{ content: counter(source-line);
|
||||||
border: none; pointer-events: all; display: inline-block;
|
position: relative; left: -1em; text-align: right; vertical-align: baseline;
|
||||||
-webkit-touch-callout: none; -webkit-user-select: none;
|
border: none; display: inline-block;
|
||||||
-khtml-user-select: none; -moz-user-select: none;
|
-webkit-touch-callout: none; -webkit-user-select: none;
|
||||||
-ms-user-select: none; user-select: none;
|
-khtml-user-select: none; -moz-user-select: none;
|
||||||
padding: 0 4px; width: 4em;
|
-ms-user-select: none; user-select: none;
|
||||||
color: #aaaaaa;
|
padding: 0 4px; width: 4em;
|
||||||
}
|
color: #aaaaaa;
|
||||||
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
|
}
|
||||||
div.sourceCode
|
pre.numberSource { margin-left: 3em; border-left: 1px solid #aaaaaa; padding-left: 4px; }
|
||||||
{ }
|
div.sourceCode
|
||||||
@media screen {
|
{ }
|
||||||
a.sourceLine::before { text-decoration: underline; }
|
@media screen {
|
||||||
}
|
pre > code.sourceCode > span > a:first-child::before { text-decoration: underline; }
|
||||||
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
}
|
||||||
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
code span.al { color: #ff0000; font-weight: bold; } /* Alert */
|
||||||
code span.at { color: #7d9029; } /* Attribute */
|
code span.an { color: #60a0b0; font-weight: bold; font-style: italic; } /* Annotation */
|
||||||
code span.bn { color: #40a070; } /* BaseN */
|
code span.at { color: #7d9029; } /* Attribute */
|
||||||
code span.bu { } /* BuiltIn */
|
code span.bn { color: #40a070; } /* BaseN */
|
||||||
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
code span.bu { } /* BuiltIn */
|
||||||
code span.ch { color: #4070a0; } /* Char */
|
code span.cf { color: #007020; font-weight: bold; } /* ControlFlow */
|
||||||
code span.cn { color: #880000; } /* Constant */
|
code span.ch { color: #4070a0; } /* Char */
|
||||||
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
code span.cn { color: #880000; } /* Constant */
|
||||||
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
code span.co { color: #60a0b0; font-style: italic; } /* Comment */
|
||||||
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
code span.cv { color: #60a0b0; font-weight: bold; font-style: italic; } /* CommentVar */
|
||||||
code span.dt { color: #902000; } /* DataType */
|
code span.do { color: #ba2121; font-style: italic; } /* Documentation */
|
||||||
code span.dv { color: #40a070; } /* DecVal */
|
code span.dt { color: #902000; } /* DataType */
|
||||||
code span.er { color: #ff0000; font-weight: bold; } /* Error */
|
code span.dv { color: #40a070; } /* DecVal */
|
||||||
code span.ex { } /* Extension */
|
code span.er { color: #ff0000; font-weight: bold; } /* Error */
|
||||||
code span.fl { color: #40a070; } /* Float */
|
code span.ex { } /* Extension */
|
||||||
code span.fu { color: #06287e; } /* Function */
|
code span.fl { color: #40a070; } /* Float */
|
||||||
code span.im { } /* Import */
|
code span.fu { color: #06287e; } /* Function */
|
||||||
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
code span.im { } /* Import */
|
||||||
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
code span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Information */
|
||||||
code span.op { color: #666666; } /* Operator */
|
code span.kw { color: #007020; font-weight: bold; } /* Keyword */
|
||||||
code span.ot { color: #007020; } /* Other */
|
code span.op { color: #666666; } /* Operator */
|
||||||
code span.pp { color: #bc7a00; } /* Preprocessor */
|
code span.ot { color: #007020; } /* Other */
|
||||||
code span.sc { color: #4070a0; } /* SpecialChar */
|
code span.pp { color: #bc7a00; } /* Preprocessor */
|
||||||
code span.ss { color: #bb6688; } /* SpecialString */
|
code span.sc { color: #4070a0; } /* SpecialChar */
|
||||||
code span.st { color: #4070a0; } /* String */
|
code span.ss { color: #bb6688; } /* SpecialString */
|
||||||
code span.va { color: #19177c; } /* Variable */
|
code span.st { color: #4070a0; } /* String */
|
||||||
code span.vs { color: #4070a0; } /* VerbatimString */
|
code span.va { color: #19177c; } /* Variable */
|
||||||
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
code span.vs { color: #4070a0; } /* VerbatimString */
|
||||||
|
code span.wa { color: #60a0b0; font-weight: bold; font-style: italic; } /* Warning */
|
||||||
</style>
|
</style>
|
||||||
<!--[if lt IE 9]>
|
<!--[if lt IE 9]>
|
||||||
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
<script src="//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv-printshiv.min.js"></script>
|
||||||
@ -162,7 +163,7 @@ Written by Drew (@topkecleon) and Kay M (@gnadelwartz).
|
|||||||
<pre><code>which bash && echo "bash seems available..."
|
<pre><code>which bash && echo "bash seems available..."
|
||||||
</code></pre>
|
</code></pre>
|
||||||
<p>Create a new directory, change to it: <code>mkdir tbb; cd tbb</code> and download the latest '*.tar.gz' file from <a href="https://github.com/topkecleon/telegram-bot-bash/releases">https://github.com/topkecleon/telegram-bot-bash/releases</a>. This can be done with the commands:</p>
|
<p>Create a new directory, change to it: <code>mkdir tbb; cd tbb</code> and download the latest '*.tar.gz' file from <a href="https://github.com/topkecleon/telegram-bot-bash/releases">https://github.com/topkecleon/telegram-bot-bash/releases</a>. This can be done with the commands:</p>
|
||||||
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb2-1" title="1"><span class="fu">wget</span> -q https://github.com/<span class="va">$(</span><span class="fu">wget</span> -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - <span class="kw">|</span> <span class="fu">egrep</span> <span class="st">'/.*/.*/.*tar.gz'</span> -o<span class="va">)</span></a></code></pre></div>
|
<div class="sourceCode" id="cb2"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb2-1"><a href="#cb2-1"></a><span class="fu">wget</span> -q https://github.com/<span class="va">$(</span><span class="fu">wget</span> -q https://github.com/topkecleon/telegram-bot-bash/releases/latest -O - <span class="kw">|</span> <span class="fu">egrep</span> <span class="st">'/.*/.*/.*tar.gz'</span> -o<span class="va">)</span></span></code></pre></div>
|
||||||
<p>Extract the '*.tar.gz' file and change to bashbot directory: <code>tar -xzf *.tar.gz; cd telegram-bot-bash</code>, install bashbot: <code>./bashbot.sh init</code> and enter your bot token when asked. All other questions can be answered by hitting the <Return> key.</p>
|
<p>Extract the '*.tar.gz' file and change to bashbot directory: <code>tar -xzf *.tar.gz; cd telegram-bot-bash</code>, install bashbot: <code>./bashbot.sh init</code> and enter your bot token when asked. All other questions can be answered by hitting the <Return> key.</p>
|
||||||
<p>That's all, now you can start your bot with <code>./bashbot.sh start</code> and send him messages:</p>
|
<p>That's all, now you can start your bot with <code>./bashbot.sh start</code> and send him messages:</p>
|
||||||
<pre><code>/start
|
<pre><code>/start
|
||||||
@ -199,18 +200,18 @@ It features background tasks and interactive chats, and can serve as an interfac
|
|||||||
<p>A powerful tool to improve your scripts is <code>shellcheck</code>. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install shellcheck locally</a>. Shellcheck is used extensively in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a <a href="doc/7_develop.md">test suite</a> to check if important functionality is working as expected.</p>
|
<p>A powerful tool to improve your scripts is <code>shellcheck</code>. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install shellcheck locally</a>. Shellcheck is used extensively in bashbot development to ensure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a <a href="doc/7_develop.md">test suite</a> to check if important functionality is working as expected.</p>
|
||||||
<h3>Use printf whenever possible</h3>
|
<h3>Use printf whenever possible</h3>
|
||||||
<p>If you're writing a script and it is taking external input (from the user as arguments or file system...), you shouldn't use echo to display it. <a href="https://unix.stackexchange.com/a/6581">Use printf whenever possible</a></p>
|
<p>If you're writing a script and it is taking external input (from the user as arguments or file system...), you shouldn't use echo to display it. <a href="https://unix.stackexchange.com/a/6581">Use printf whenever possible</a></p>
|
||||||
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb5-1" title="1"> <span class="co"># very simple</span></a>
|
<div class="sourceCode" id="cb5"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb5-1"><a href="#cb5-1"></a> <span class="co"># very simple</span></span>
|
||||||
<a class="sourceLine" id="cb5-2" title="2"> <span class="bu">echo</span> <span class="st">"text with variables. PWD=</span><span class="va">$PWD</span><span class="st">"</span></a>
|
<span id="cb5-2"><a href="#cb5-2"></a> <span class="bu">echo</span> <span class="st">"text with variables. PWD=</span><span class="va">$PWD</span><span class="st">"</span></span>
|
||||||
<a class="sourceLine" id="cb5-3" title="3"> <span class="bu">printf</span> <span class="st">'%s\n'</span> <span class="st">"text with variables. PWD=</span><span class="va">$PWD</span><span class="st">"</span></a>
|
<span id="cb5-3"><a href="#cb5-3"></a> <span class="bu">printf</span> <span class="st">'%s\n'</span> <span class="st">"text with variables. PWD=</span><span class="va">$PWD</span><span class="st">"</span></span>
|
||||||
<a class="sourceLine" id="cb5-4" title="4"> <span class="ex">-</span><span class="op">></span> text with variables. PWD=/home/xxx</a>
|
<span id="cb5-4"><a href="#cb5-4"></a> <span class="ex">-</span><span class="op">></span> text with variables. PWD=/home/xxx</span>
|
||||||
<a class="sourceLine" id="cb5-5" title="5"></a>
|
<span id="cb5-5"><a href="#cb5-5"></a></span>
|
||||||
<a class="sourceLine" id="cb5-6" title="6"> <span class="co"># more advanced</span></a>
|
<span id="cb5-6"><a href="#cb5-6"></a> <span class="co"># more advanced</span></span>
|
||||||
<a class="sourceLine" id="cb5-7" title="7"> <span class="va">FLOAT=</span><span class="st">"1.2346777892864"</span> <span class="va">INTEGER=</span><span class="st">"12345.123"</span></a>
|
<span id="cb5-7"><a href="#cb5-7"></a> <span class="va">FLOAT=</span><span class="st">"1.2346777892864"</span> <span class="va">INTEGER=</span><span class="st">"12345.123"</span></span>
|
||||||
<a class="sourceLine" id="cb5-8" title="8"> <span class="bu">echo</span> <span class="st">"text with variabeles. float=</span><span class="va">$FLOAT</span><span class="st">, integer=</span><span class="va">$INTEGER</span><span class="st">, PWD=</span><span class="va">$PWD</span><span class="st">"</span></a>
|
<span id="cb5-8"><a href="#cb5-8"></a> <span class="bu">echo</span> <span class="st">"text with variabeles. float=</span><span class="va">$FLOAT</span><span class="st">, integer=</span><span class="va">$INTEGER</span><span class="st">, PWD=</span><span class="va">$PWD</span><span class="st">"</span></span>
|
||||||
<a class="sourceLine" id="cb5-9" title="9"> <span class="ex">-</span><span class="op">></span>text with variables. float=1.2346777892864, integer=12345.123, PWD=/home/xxx</a>
|
<span id="cb5-9"><a href="#cb5-9"></a> <span class="ex">-</span><span class="op">></span>text with variables. float=1.2346777892864, integer=12345.123, PWD=/home/xxx</span>
|
||||||
<a class="sourceLine" id="cb5-10" title="10"></a>
|
<span id="cb5-10"><a href="#cb5-10"></a></span>
|
||||||
<a class="sourceLine" id="cb5-11" title="11"> <span class="bu">printf</span> <span class="st">"text with variables. float=%.2f, integer=%d, PWD=%s\n"</span> <span class="st">""</span> <span class="st">"</span><span class="va">$INTEGER</span><span class="st">"</span> <span class="st">"</span><span class="va">$PWD</span><span class="st">"</span></a>
|
<span id="cb5-11"><a href="#cb5-11"></a> <span class="bu">printf</span> <span class="st">"text with variables. float=%.2f, integer=%d, PWD=%s\n"</span> <span class="st">""</span> <span class="st">"</span><span class="va">$INTEGER</span><span class="st">"</span> <span class="st">"</span><span class="va">$PWD</span><span class="st">"</span></span>
|
||||||
<a class="sourceLine" id="cb5-12" title="12"> <span class="ex">-</span><span class="op">></span>text with variables. float=1.23, integer=12345, PWD=/home/xxx</a></code></pre></div>
|
<span id="cb5-12"><a href="#cb5-12"></a> <span class="ex">-</span><span class="op">></span>text with variables. float=1.23, integer=12345, PWD=/home/xxx</span></code></pre></div>
|
||||||
<h3>Do not use #!/usr/bin/env bash</h3>
|
<h3>Do not use #!/usr/bin/env bash</h3>
|
||||||
<p><strong>We stay with /bin/bash shebang, because it's more save from security perspective.</strong></p>
|
<p><strong>We stay with /bin/bash shebang, because it's more save from security perspective.</strong></p>
|
||||||
<p>Use of a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.</p>
|
<p>Use of a fixed path to the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using a possibly broken, mangled or compromised bash executable.</p>
|
||||||
@ -240,38 +241,38 @@ It features background tasks and interactive chats, and can serve as an interfac
|
|||||||
<h3>Can I send messages from CLI and scripts?</h3>
|
<h3>Can I send messages from CLI and scripts?</h3>
|
||||||
<p>Of course, you can send messages from CLI and scripts, simply install bashbot as <a href="#Your-really-first-bashbot-in-a-nutshell">described here</a>, send the message '/start' to set yourself as botadmin and stop the bot with <code>./bashbot.sh stop</code>.</p>
|
<p>Of course, you can send messages from CLI and scripts, simply install bashbot as <a href="#Your-really-first-bashbot-in-a-nutshell">described here</a>, send the message '/start' to set yourself as botadmin and stop the bot with <code>./bashbot.sh stop</code>.</p>
|
||||||
<p>Run the following commands in your bash shell or script while you are in the installation directory:</p>
|
<p>Run the following commands in your bash shell or script while you are in the installation directory:</p>
|
||||||
<div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb6-1" title="1"><span class="co"># prepare bash / script to send commands</span></a>
|
<div class="sourceCode" id="cb6"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb6-1"><a href="#cb6-1"></a><span class="co"># prepare bash / script to send commands</span></span>
|
||||||
<a class="sourceLine" id="cb6-2" title="2"><span class="bu">export</span> <span class="va">BASHBOT_HOME=</span><span class="st">"</span><span class="va">$(</span><span class="bu">pwd</span><span class="va">)</span><span class="st">"</span></a>
|
<span id="cb6-2"><a href="#cb6-2"></a><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>
|
||||||
<a class="sourceLine" id="cb6-3" title="3"><span class="bu">source</span> ./bashbot.sh source</a>
|
<span id="cb6-3"><a href="#cb6-3"></a><span class="bu">source</span> ./bashbot.sh source</span>
|
||||||
<a class="sourceLine" id="cb6-4" title="4"></a>
|
<span id="cb6-4"><a href="#cb6-4"></a></span>
|
||||||
<a class="sourceLine" id="cb6-5" title="5"><span class="co"># send me a test message</span></a>
|
<span id="cb6-5"><a href="#cb6-5"></a><span class="co"># send me a test message</span></span>
|
||||||
<a class="sourceLine" id="cb6-6" title="6"><span class="ex">send_message</span> <span class="st">"</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">"botadmin"</span><span class="va">)</span><span class="st">"</span> <span class="st">"test"</span></a>
|
<span id="cb6-6"><a href="#cb6-6"></a><span class="ex">send_message</span> <span class="st">"</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">"botadmin"</span><span class="va">)</span><span class="st">"</span> <span class="st">"test"</span></span>
|
||||||
<a class="sourceLine" id="cb6-7" title="7"></a>
|
<span id="cb6-7"><a href="#cb6-7"></a></span>
|
||||||
<a class="sourceLine" id="cb6-8" title="8"><span class="co"># send me output of a system command</span></a>
|
<span id="cb6-8"><a href="#cb6-8"></a><span class="co"># send me output of a system command</span></span>
|
||||||
<a class="sourceLine" id="cb6-9" title="9"><span class="ex">send_message</span> <span class="st">"</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">"botadmin"</span><span class="va">)</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></a></code></pre></div>
|
<span id="cb6-9"><a href="#cb6-9"></a><span class="ex">send_message</span> <span class="st">"</span><span class="va">$(</span><span class="ex">getConfigKey</span> <span class="st">"botadmin"</span><span class="va">)</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></span></code></pre></div>
|
||||||
<p>For more information see <a href="doc/8_custom.md">Expert Use</a></p>
|
<p>For more information see <a href="doc/8_custom.md">Expert Use</a></p>
|
||||||
<h3>Blocked by telegram?</h3>
|
<h3>Blocked by telegram?</h3>
|
||||||
<p>This may happen if to many or wrong requests are sent to api.telegram.org, e.g. using a invalid token or not existing API calls. If the block stay for longer time you can ask telegram service to unblock your IP-Adress.</p>
|
<p>This may happen if to many or wrong requests are sent to api.telegram.org, e.g. using a invalid token or not existing API calls. If the block stay for longer time you can ask telegram service to unblock your IP-Adress.</p>
|
||||||
<p>You can check with curl or wget if you are blocked by Telegram:</p>
|
<p>You can check with curl or wget if you are blocked by Telegram:</p>
|
||||||
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb7-1" title="1"><span class="ex">curl</span> -m 10 https://api.telegram.org/bot</a>
|
<div class="sourceCode" id="cb7"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb7-1"><a href="#cb7-1"></a><span class="ex">curl</span> -m 10 https://api.telegram.org/bot</span>
|
||||||
<a class="sourceLine" id="cb7-2" title="2"><span class="co">#curl: (28) Connection timed out after 10001 milliseconds</span></a>
|
<span id="cb7-2"><a href="#cb7-2"></a><span class="co">#curl: (28) Connection timed out after 10001 milliseconds</span></span>
|
||||||
<a class="sourceLine" id="cb7-3" title="3"></a>
|
<span id="cb7-3"><a href="#cb7-3"></a></span>
|
||||||
<a class="sourceLine" id="cb7-4" title="4"><span class="fu">wget</span> -t 1 -T 10 https://api.telegram.org/bot</a>
|
<span id="cb7-4"><a href="#cb7-4"></a><span class="fu">wget</span> -t 1 -T 10 https://api.telegram.org/bot</span>
|
||||||
<a class="sourceLine" id="cb7-5" title="5"><span class="co">#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.</span></a></code></pre></div>
|
<span id="cb7-5"><a href="#cb7-5"></a><span class="co">#Connecting to api.telegram.org (api.telegram.org)|46.38.243.234|:443... failed: Connection timed out.</span></span></code></pre></div>
|
||||||
<p>Since Version 0.96 bashbot offers the option to recover from broken connections (aka blocked). Therefore you can provide a function named <code>bashbotBlockRecover()</code> in <code>mycommands.sh</code>. If the function exists it is called every time when a broken connection is detected.</p>
|
<p>Since Version 0.96 bashbot offers the option to recover from broken connections (aka blocked). Therefore you can provide a function named <code>bashbotBlockRecover()</code> in <code>mycommands.sh</code>. If the function exists it is called every time when a broken connection is detected.</p>
|
||||||
<p>Possible actions are: Check if network is working, change IP-Adress or simply wait some time.</p>
|
<p>Possible actions are: Check if network is working, change IP-Adress or simply wait some time.</p>
|
||||||
<p>If everything seems OK return 0 for retry or any non 0 value to give up.</p>
|
<p>If everything seems OK return 0 for retry or any non 0 value to give up.</p>
|
||||||
<div class="sourceCode" id="cb8"><pre class="sourceCode bash"><code class="sourceCode bash"><a class="sourceLine" id="cb8-1" title="1"><span class="co"># called when bashbot sedn command failed because we can not connect to telegram</span></a>
|
<div class="sourceCode" id="cb8"><pre class="sourceCode bash"><code class="sourceCode bash"><span id="cb8-1"><a href="#cb8-1"></a><span class="co"># called when bashbot sedn command failed because we can not connect to telegram</span></span>
|
||||||
<a class="sourceLine" id="cb8-2" title="2"><span class="co"># return 0 to retry, return non 0 to give up</span></a>
|
<span id="cb8-2"><a href="#cb8-2"></a><span class="co"># return 0 to retry, return non 0 to give up</span></span>
|
||||||
<a class="sourceLine" id="cb8-3" title="3"><span class="fu">bashbotBlockRecover()</span> <span class="kw">{</span></a>
|
<span id="cb8-3"><a href="#cb8-3"></a><span class="fu">bashbotBlockRecover()</span> <span class="kw">{</span></span>
|
||||||
<a class="sourceLine" id="cb8-4" title="4"> <span class="co"># place your commands to unblock here, e.g. change IP-Adess or simply wait</span></a>
|
<span id="cb8-4"><a href="#cb8-4"></a> <span class="co"># place your commands to unblock here, e.g. change IP-Adess or simply wait</span></span>
|
||||||
<a class="sourceLine" id="cb8-5" title="5"> <span class="fu">sleep</span> 60 <span class="kw">&&</span> <span class="bu">return</span> 0 <span class="co"># may be temporary</span></a>
|
<span id="cb8-5"><a href="#cb8-5"></a> <span class="fu">sleep</span> 60 <span class="kw">&&</span> <span class="bu">return</span> 0 <span class="co"># may be temporary</span></span>
|
||||||
<a class="sourceLine" id="cb8-6" title="6"> <span class="bu">return</span> 1 </a>
|
<span id="cb8-6"><a href="#cb8-6"></a> <span class="bu">return</span> 1 </span>
|
||||||
<a class="sourceLine" id="cb8-7" title="7"> <span class="kw">}</span></a>
|
<span id="cb8-7"><a href="#cb8-7"></a> <span class="kw">}</span></span>
|
||||||
<a class="sourceLine" id="cb8-8" title="8"></a></code></pre></div>
|
<span id="cb8-8"><a href="#cb8-8"></a></span></code></pre></div>
|
||||||
<p>@Gnadelwartz</p>
|
<p>@Gnadelwartz</p>
|
||||||
<h2>That's it!</h2>
|
<h2>That's it all guys!</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>$$VERSION$$ v1.1-0-gc0eb399</h4>
|
<h4>$$VERSION$$ v1.1-0-ge835bbc</h4>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
@ -350,9 +350,9 @@ wait
|
|||||||
|
|
||||||
@Gnadelwartz
|
@Gnadelwartz
|
||||||
|
|
||||||
## That's it!
|
## That's it all guys!
|
||||||
|
|
||||||
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$$ v1.1-0-gc0eb399
|
#### $$VERSION$$ v1.1-0-ge835bbc
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
# Addons can register to bashbot events at startup
|
# Addons can register to bashbot events at startup
|
||||||
# by providing their name and a callback per event
|
# by providing their name and a callback per event
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
#
|
#
|
||||||
# If an event occurs each registered event function is called.
|
# If an event occurs each registered event function is called.
|
||||||
#
|
#
|
||||||
@ -29,7 +29,7 @@
|
|||||||
# BASHBOT_EVENT_LOCATION location or venue received
|
# BASHBOT_EVENT_LOCATION location or venue received
|
||||||
# BASHBOT_EVENT_FILE file received
|
# BASHBOT_EVENT_FILE file received
|
||||||
#
|
#
|
||||||
# BAHSBOT_EVENT_TIMER this event is a bit special as it fires every Minute
|
# BASHBOT_EVENT_TIMER this event is a bit special as it fires every Minute
|
||||||
# and has 3 meanings: oneshot, every time, every X minutes.
|
# and has 3 meanings: oneshot, every time, every X minutes.
|
||||||
#
|
#
|
||||||
# all global variables and functions can be used in registered functions.
|
# all global variables and functions can be used in registered functions.
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
# description: Start or stop telegram-bash-bot
|
# description: Start or stop telegram-bash-bot
|
||||||
#
|
#
|
||||||
#### $$VERSION$$ v1.1-0-gc0eb399
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
# shellcheck disable=SC2009
|
# shellcheck disable=SC2009
|
||||||
# shellcheck disable=SC2181
|
# shellcheck disable=SC2181
|
||||||
|
|
||||||
@ -17,14 +17,13 @@
|
|||||||
|
|
||||||
# save default values
|
# save default values
|
||||||
TERM="" # disable bashbot clear and color output
|
TERM="" # disable bashbot clear and color output
|
||||||
runas="nobody"
|
|
||||||
runcmd="echo Dry run:" # not activated until you edit lines below
|
runcmd="echo Dry run:" # not activated until you edit lines below
|
||||||
|
|
||||||
#######################
|
#######################
|
||||||
# Configuration Section
|
# Configuration Section
|
||||||
|
|
||||||
# edit the next line to fit the user you want to run bashbot, e.g. nobody:
|
# edit the next line to fit the user you want to run bashbot, e.g. nobody:
|
||||||
# runas="nobody"
|
runas="nobody"
|
||||||
|
|
||||||
# uncomment one of the following lines to fit your system
|
# uncomment one of the following lines to fit your system
|
||||||
# runcmd="su $runas -s /bin/bash -c " # runasuser with *su*
|
# runcmd="su $runas -s /bin/bash -c " # runasuser with *su*
|
||||||
@ -81,4 +80,3 @@ case "$1" in
|
|||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
exit $RETVAL
|
exit $RETVAL
|
||||||
|
|
||||||
|
195
bashbot.sh
195
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$$ v1.1-0-gc0eb399
|
#### $$VERSION$$ v1.2-dev-25-g0b64af7
|
||||||
#
|
#
|
||||||
# Exit Codes:
|
# Exit Codes:
|
||||||
# - 0 success (hopefully)
|
# - 0 success (hopefully)
|
||||||
@ -21,7 +21,7 @@
|
|||||||
# - 4 unknown command
|
# - 4 unknown command
|
||||||
# - 5 cannot connect to telegram bot
|
# - 5 cannot connect to telegram bot
|
||||||
# - 6 mandatory module not found
|
# - 6 mandatory module not found
|
||||||
# - 6 can't get bottoken
|
# - 7 can't get bottoken
|
||||||
# - 10 not bash!
|
# - 10 not bash!
|
||||||
# shellcheck disable=SC2140,SC2031,SC2120,SC1091
|
# shellcheck disable=SC2140,SC2031,SC2120,SC1091
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ fi
|
|||||||
ADDONDIR="${BASHBOT_ETC:-.}/addons"
|
ADDONDIR="${BASHBOT_ETC:-.}/addons"
|
||||||
RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original
|
RUNUSER="${USER}" # USER is overwritten by bashbot array :-(, save original
|
||||||
|
|
||||||
# OK everything setup, lest start
|
# OK everything setup, lets start
|
||||||
if [[ -z "${SOURCE}" && -z "$BASHBOT_HOME" ]] && ! cd "${RUNDIR}" ; then
|
if [[ -z "${SOURCE}" && -z "$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
|
||||||
@ -190,7 +190,7 @@ if [ -z "${BOTTOKEN}" ]; then
|
|||||||
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
|
[ -n "${token}" ] && printf '["bottoken"]\t"%s"\n' "${token}" >> "${BOTCONFIG}.jssh"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# no boteadmin, setup botadmin
|
# no botadmin, setup botadmin
|
||||||
if [ -z "$(getConfigKey "botadmin")" ]; then
|
if [ -z "$(getConfigKey "botadmin")" ]; then
|
||||||
# convert old admin
|
# convert old admin
|
||||||
if [ -r "${BOTADMIN}" ]; then
|
if [ -r "${BOTADMIN}" ]; then
|
||||||
@ -250,16 +250,16 @@ debug_checks "start SOURCE=${SOURCE:-no}" "$@"
|
|||||||
if [ -z "${BOTTOKEN}" ]; then
|
if [ -z "${BOTTOKEN}" ]; then
|
||||||
BOTTOKEN="$(getConfigKey "bottoken")"
|
BOTTOKEN="$(getConfigKey "bottoken")"
|
||||||
if [ -z "${BOTTOKEN}" ]; then
|
if [ -z "${BOTTOKEN}" ]; then
|
||||||
BOTERROR="Warning: can't get bot token, try to recover working config"
|
BOTERROR="Warning: can't get bot token, try to recover working config"
|
||||||
echo -e "${ORANGE}${BOTERROR}${NC}"
|
echo -e "${ORANGE}${BOTERROR}${NC}"
|
||||||
if [ -r "${BOTCONFIG}.jssh.ok" ]; then
|
if [ -r "${BOTCONFIG}.jssh.ok" ]; then
|
||||||
log_error "${BOTERROR}"
|
log_error "${BOTERROR}"
|
||||||
cp "${BOTCONFIG}.jssh.ok" "${BOTCONFIG}.jssh"
|
cp "${BOTCONFIG}.jssh.ok" "${BOTCONFIG}.jssh"
|
||||||
BOTTOKEN="$(getConfigKey "bottoken")"
|
BOTTOKEN="$(getConfigKey "bottoken")"
|
||||||
else
|
else
|
||||||
echo -e "${RED}Error: Missing bot token! remove ${BOTCONFIG}.jssh and run \"bashbot.sh init\" may fix it.${NC}"
|
echo -e "${RED}Error: Missing bot token! remove ${BOTCONFIG}.jssh and run \"bashbot.sh init\" may fix it.${NC}"
|
||||||
exit 7
|
exit 7
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -268,12 +268,12 @@ fi
|
|||||||
if ! check_token "${BOTTOKEN}"; then
|
if ! check_token "${BOTTOKEN}"; then
|
||||||
echo -e "${ORANGE}Warning: your bottoken may incorrect. it should have the following format:${NC}"
|
echo -e "${ORANGE}Warning: your bottoken may incorrect. it should have the following format:${NC}"
|
||||||
echo -e "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}\c"
|
echo -e "${GREY}123456789${RED}:${GREY}Aa-Zz_0Aa-Zz_1Aa-Zz_2Aa-Zz_3Aa-Zz_4${ORANGE} => ${NC}\c"
|
||||||
echo -e "${GREY}8-10 digits${RED}:${GREY}35 alnum characters + '_-'${NC}"
|
echo -e "${GREY}8-10 digits${RED}:${GREY}35 alphanumeric characters + '_-'${NC}"
|
||||||
echo -e "${ORANGE}Your current token is: '${GREY}^$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")${ORANGE}'${NC}"
|
echo -e "${ORANGE}Your current token is: '${GREY}^$(cat -ve <<<"${BOTTOKEN//:/${RED}:${GREY}}")${ORANGE}'${NC}"
|
||||||
[[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]] &&\
|
[[ ! "${BOTTOKEN}" =~ ^[0-9]{8,10}: ]] &&\
|
||||||
echo -e "${ORANGE}Possible problem in the digits part, len is $(($(wc -c <<<"${BOTTOKEN%:*}")-1))${NC}"
|
echo -e "${ORANGE}Possible problem in the digits part, len is $(($(wc -c <<<"${BOTTOKEN%:*}")-1))${NC}"
|
||||||
[[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\
|
[[ ! "${BOTTOKEN}" =~ :[a-zA-Z0-9_-]{35}$ ]] &&\
|
||||||
echo -e "${ORANGE}Posilbe problem in the charatcers part, len is $(($(wc -c <<<"${BOTTOKEN#*:}")-1))${NC}"
|
echo -e "${ORANGE}Possible problem in the characters part, len is $(($(wc -c <<<"${BOTTOKEN#*:}")-1))${NC}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
||||||
@ -300,7 +300,7 @@ export res CAPTION
|
|||||||
|
|
||||||
|
|
||||||
##################
|
##################
|
||||||
# read commamds file if we are not sourced
|
# read commands file if we are not sourced
|
||||||
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
COMMANDS="${BASHBOT_ETC:-.}/commands.sh"
|
||||||
if [ -z "${SOURCE}" ]; then
|
if [ -z "${SOURCE}" ]; then
|
||||||
if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then
|
if [ ! -f "${COMMANDS}" ] || [ ! -r "${COMMANDS}" ]; then
|
||||||
@ -350,14 +350,14 @@ procname(){
|
|||||||
printf '%s\n' "$2${ME}_$1"
|
printf '%s\n' "$2${ME}_$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 string to search for proramm incl. parameters
|
# $1 string to search for programme incl. parameters
|
||||||
# returns a list of PIDs of all current bot proceeses matching $1
|
# returns a list of PIDs of all current bot processes matching $1
|
||||||
proclist() {
|
proclist() {
|
||||||
# shellcheck disable=SC2009
|
# shellcheck disable=SC2009
|
||||||
ps -fu "${UID}" | grep -F "$1" | grep -v ' grep'| grep -F "${ME}" | sed 's/\s\+/\t/g' | cut -f 2
|
ps -fu "${UID}" | grep -F "$1" | grep -v ' grep'| grep -F "${ME}" | sed 's/\s\+/\t/g' | cut -f 2
|
||||||
}
|
}
|
||||||
|
|
||||||
# $1 string to search for proramm to kill
|
# $1 string to search for programme to kill
|
||||||
killallproc() {
|
killallproc() {
|
||||||
local procid; procid="$(proclist "$1")"
|
local procid; procid="$(proclist "$1")"
|
||||||
if [ -n "${procid}" ] ; then
|
if [ -n "${procid}" ] ; then
|
||||||
@ -372,7 +372,7 @@ killallproc() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
# $ chat $2 mesgid $3 nolog
|
# $ chat $2 msg_id $3 nolog
|
||||||
declare -xr DELETE_URL=$URL'/deleteMessage'
|
declare -xr DELETE_URL=$URL'/deleteMessage'
|
||||||
delete_message() {
|
delete_message() {
|
||||||
[ -z "$3" ] && printf "%s: Delete Message CHAT=%s MSG_ID=%s\n" "$(date)" "${1}" "${2}" >>"${UPDATELOG}"
|
[ -z "$3" ] && printf "%s: Delete Message CHAT=%s MSG_ID=%s\n" "$(date)" "${1}" "${2}" >>"${UPDATELOG}"
|
||||||
@ -385,11 +385,42 @@ get_file() {
|
|||||||
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
|
printf '%s\n' "${URL}"/"$(JsonGetString <<< "${res}" '"result","file_path"')"
|
||||||
}
|
}
|
||||||
|
|
||||||
# curl is preferred, but may not available on embedded systems
|
# return TRUE if curl is found or custom curl detected
|
||||||
|
# return FALSE if no curl is found or wget is forced by BASHBOT_WGET
|
||||||
|
# sets BASHBOT_CURL to point to curl
|
||||||
|
function detect_curl() {
|
||||||
|
# custom curl command
|
||||||
|
[ -n "${BASHBOT_CURL}" ] && return 0
|
||||||
|
# use wget
|
||||||
|
[ -n "${BASHBOT_WGET}" ] && return 1
|
||||||
|
# default use curl in PATH
|
||||||
|
BASHBOT_CURL="curl"
|
||||||
|
_exists curl && return 0
|
||||||
|
# search in usual locations
|
||||||
|
local file
|
||||||
|
for file in /usr/bin /bin /usr/local/bin; do
|
||||||
|
if [ -x "${file}/curl" ]; then
|
||||||
|
BASHBOT_CURL="${file}/curl"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
# curl not in PATH and not in usual locations
|
||||||
|
local warn="Warning: Curl not detected, try fallback to wget! pls install curl or adjust BASHBOT_CURL/BASHBOT_WGET environment variables."
|
||||||
|
printf "%s: %s\n" "$(date)" "${warn}" >>"${UPDATELOG}"
|
||||||
|
[ -n "${BASHBOTDEBUG}" ] && printf "%s: %s\n" "$(date)" "${warn}" >>"${DEBUGLOG}"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# iconv used to filter out broken utf characters, if not installed fake it
|
||||||
|
if ! _exists iconv; then
|
||||||
|
printf "%s: %s\n" "$(date)" "Warning: iconv not installed, pls imstall iconv!" >>"${UPDATELOG}"
|
||||||
|
function iconv() { cat; }
|
||||||
|
fi
|
||||||
|
|
||||||
TIMEOUT="${BASHBOT_TIMEOUT}"
|
TIMEOUT="${BASHBOT_TIMEOUT}"
|
||||||
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
|
[[ "$TIMEOUT" =~ ^[0-9]+$ ]] || TIMEOUT="20"
|
||||||
|
|
||||||
if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
if detect_curl ; then
|
||||||
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
|
[ -z "${BASHBOT_CURL}" ] && BASHBOT_CURL="curl"
|
||||||
# simple curl or wget call, output to stdout
|
# simple curl or wget call, output to stdout
|
||||||
getJson(){
|
getJson(){
|
||||||
@ -406,11 +437,11 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} -m "${TIMEOUT}"\
|
||||||
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
-d '{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' -X POST "${3}" \
|
||||||
-H "Content-Type: application/json" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
-H "Content-Type: application/json" | "${JSONSHFILE}" -b -n 2>/dev/null )"
|
||||||
sendJsonResult "${res}" "sendJson (curl)" "$@"
|
sendJsonResult "${res}" "sendJson (curl)" "$@"
|
||||||
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" &
|
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" &
|
||||||
}
|
}
|
||||||
#$1 Chat, $2 what , $3 file, $4 URL, $5 caption
|
#$1 Chat, $2 what, $3 file, $4 URL, $5 caption
|
||||||
sendUpload() {
|
sendUpload() {
|
||||||
[ "$#" -lt 4 ] && return
|
[ "$#" -lt 4 ] && return
|
||||||
if [ -n "$5" ]; then
|
if [ -n "$5" ]; then
|
||||||
@ -418,11 +449,11 @@ if [ -z "${BASHBOT_WGET}" ] && _exists curl ; then
|
|||||||
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${UPDATELOG}"
|
printf "%s: sendUpload CHAT=%s WHAT=%s FILE=%s CAPT=%s\n" "$(date)" "${1}" "${2}" "${3}" "${4}" >>"${UPDATELOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
||||||
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
-F "$2=@$3;${3##*/}" -F "caption=$5" | "${JSONSHFILE}" -b -n 2>/dev/null )"
|
||||||
else
|
else
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
res="$("${BASHBOT_CURL}" -s -k ${BASHBOT_CURL_ARGS} "$4" -F "chat_id=$1"\
|
||||||
-F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
-F "$2=@$3;${3##*/}" | "${JSONSHFILE}" -b -n 2>/dev/null )"
|
||||||
fi
|
fi
|
||||||
sendJsonResult "${res}" "sendUpload (curl)" "$@"
|
sendJsonResult "${res}" "sendUpload (curl)" "$@"
|
||||||
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
|
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "upload" "$@" &
|
||||||
@ -442,7 +473,7 @@ else
|
|||||||
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${UPDATELOG}"
|
printf "%s: sendJson (wget) CHAT=%s JSON=%s URL=%s\n" "$(date)" "${1}" "${2:0:100}" "${3##*/}" >>"${UPDATELOG}"
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
|
res="$(wget --no-check-certificate -t 2 -T "${TIMEOUT}" ${BASHBOT_WGET_ARGS} -qO - --post-data='{'"${chat} $(iconv -f utf-8 -t utf-8 -c <<<$2)"'}' \
|
||||||
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -s -b -n 2>/dev/null )"
|
--header='Content-Type:application/json' "${3}" | "${JSONSHFILE}" -b -n 2>/dev/null )"
|
||||||
sendJsonResult "${res}" "sendJson (wget)" "$@"
|
sendJsonResult "${res}" "sendJson (wget)" "$@"
|
||||||
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" &
|
[ -n "${BASHBOT_EVENT_SEND[*]}" ] && event_send "send" "${@}" &
|
||||||
}
|
}
|
||||||
@ -492,13 +523,13 @@ sendJsonResult(){
|
|||||||
else
|
else
|
||||||
# oops something went wrong!
|
# oops something went wrong!
|
||||||
if [ "${res}" != "" ]; then
|
if [ "${res}" != "" ]; then
|
||||||
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")"
|
BOTSENT[ERROR]="$(JsonGetValue '"error_code"' <<< "${1}")"
|
||||||
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")"
|
BOTSENT[DESCRIPTION]="$(JsonGetString '"description"' <<< "${1}")"
|
||||||
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")"
|
BOTSENT[RETRY]="$(JsonGetValue '"parameters","retry_after"' <<< "${1}")"
|
||||||
else
|
else
|
||||||
BOTSENT[OK]="false"
|
BOTSENT[OK]="false"
|
||||||
BOTSENT[ERROR]="999"
|
BOTSENT[ERROR]="999"
|
||||||
BOTSENT[DESCRIPTION]="Send to telegram not possible, timeout/broken/no connection"
|
BOTSENT[DESCRIPTION]="Send to telegram not possible, timeout/broken/no connection"
|
||||||
fi
|
fi
|
||||||
# log error
|
# log error
|
||||||
[[ "${BOTSENT[ERROR]}" = "400" && "${BOTSENT[DESCRIPTION]}" == *"starting at byte offset"* ]] &&\
|
[[ "${BOTSENT[ERROR]}" = "400" && "${BOTSENT[DESCRIPTION]}" == *"starting at byte offset"* ]] &&\
|
||||||
@ -509,36 +540,36 @@ sendJsonResult(){
|
|||||||
[ -n "${BASHBOT_RETRY}${BASHBOT_WGET}" ] && return
|
[ -n "${BASHBOT_RETRY}${BASHBOT_WGET}" ] && return
|
||||||
|
|
||||||
# OK, we can retry sendJson, let's see what's failed
|
# OK, we can retry sendJson, let's see what's failed
|
||||||
# throttled, telegram say we send to much messages
|
# throttled, telegram say we send too many messages
|
||||||
if [ -n "${BOTSENT[RETRY]}" ]; then
|
if [ -n "${BOTSENT[RETRY]}" ]; then
|
||||||
BASHBOT_RETRY="$(( ++BOTSENT[RETRY] ))"
|
BASHBOT_RETRY="$(( ++BOTSENT[RETRY] ))"
|
||||||
printf "Retry %s in %s seconds ...\n" "${2}" "${BASHBOT_RETRY}"
|
printf "Retry %s in %s seconds ...\n" "${2}" "${BASHBOT_RETRY}"
|
||||||
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
|
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
|
||||||
unset BASHBOT_RETRY
|
unset BASHBOT_RETRY
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
# timeout, failed connection or blocked
|
# timeout, failed connection or blocked
|
||||||
if [ "${BOTSENT[ERROR]}" == "999" ];then
|
if [ "${BOTSENT[ERROR]}" == "999" ];then
|
||||||
# check if default curl and args are OK
|
# check if default curl and args are OK
|
||||||
if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then
|
if ! curl -sL -k -m 2 "${URL}" >/dev/null 2>&1 ; then
|
||||||
printf "%s: BASHBOT IP Address seems blocked!\n" "$(date)"
|
printf "%s: BASHBOT IP Address seems blocked!\n" "$(date)"
|
||||||
# user provided function to recover or notify block
|
# user provided function to recover or notify block
|
||||||
if _exec_if_function bashbotBlockRecover; then
|
if _exec_if_function bashbotBlockRecover; then
|
||||||
BASHBOT_RETRY="2"
|
BASHBOT_RETRY="2"
|
||||||
printf "bashbotBlockRecover returned true, retry %s ...\n" "${2}"
|
printf "bashbotBlockRecover returned true, retry %s ...\n" "${2}"
|
||||||
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
|
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
|
||||||
unset BASHBOT_RETRY
|
unset BASHBOT_RETRY
|
||||||
fi
|
fi
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
# are not blocked, default curl and args are working
|
# are not blocked, default curl and args are working
|
||||||
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then
|
if [ -n "${BASHBOT_CURL_ARGS}" ] || [ "${BASHBOT_CURL}" != "curl" ]; then
|
||||||
printf "Problem with \"%s %s\"? retry %s with default config ...\n"\
|
printf "Problem with \"%s %s\"? retry %s with default config ...\n"\
|
||||||
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
|
"${BASHBOT_CURL}" "${BASHBOT_CURL_ARGS}" "${2}"
|
||||||
BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
|
BASHBOT_RETRY="2"; BASHBOT_CURL="curl"; BASHBOT_CURL_ARGS=""
|
||||||
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
|
sendJsonRetry "${2}" "${BASHBOT_RETRY}" "${@:3}"
|
||||||
unset BASHBOT_RETRY
|
unset BASHBOT_RETRY
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
} >>"${ERRORLOG}"
|
} >>"${ERRORLOG}"
|
||||||
@ -564,21 +595,21 @@ title2Json(){
|
|||||||
|
|
||||||
# get bot name
|
# get bot name
|
||||||
getBotName() {
|
getBotName() {
|
||||||
getJson "$ME_URL" | "${JSONSHFILE}" -s -b -n 2>/dev/null | JsonGetString '"result","username"'
|
getJson "$ME_URL" | "${JSONSHFILE}" -b -n 2>/dev/null | JsonGetString '"result","username"'
|
||||||
}
|
}
|
||||||
|
|
||||||
# pure bash implementation, done by KayM (@gnadelwartz)
|
# pure bash implementation, done by KayM (@gnadelwartz)
|
||||||
# see https://stackoverflow.com/a/55666449/9381171
|
# see https://stackoverflow.com/a/55666449/9381171
|
||||||
JsonDecode() {
|
JsonDecode() {
|
||||||
local out="$1" remain="" U=""
|
local out="$1" remain="" U=""
|
||||||
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
|
local regexp='(.*)\\u[dD]([0-9a-fA-F]{3})\\u[dD]([0-9a-fA-F]{3})(.*)'
|
||||||
while [[ "${out}" =~ $regexp ]] ; do
|
while [[ "${out}" =~ $regexp ]] ; do
|
||||||
U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 ))
|
U=$(( ( (0xd${BASH_REMATCH[2]} & 0x3ff) <<10 ) | ( 0xd${BASH_REMATCH[3]} & 0x3ff ) + 0x10000 ))
|
||||||
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
|
remain="$(printf '\\U%8.8x' "${U}")${BASH_REMATCH[4]}${remain}"
|
||||||
out="${BASH_REMATCH[1]}"
|
out="${BASH_REMATCH[1]}"
|
||||||
done
|
done
|
||||||
# this echo must stay for correct decoding!
|
# this echo must stay for correct decoding!
|
||||||
echo -e "${out}${remain}"
|
echo -e "${out}${remain}"
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonGetString() {
|
JsonGetString() {
|
||||||
@ -608,7 +639,7 @@ process_client() {
|
|||||||
# log message on debug
|
# log message on debug
|
||||||
[[ -n "${debug}" ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log"
|
[[ -n "${debug}" ]] && printf "\n%s: New Message ==========\n%s\n" "$(date)" "$UPDATE" >>"${LOGDIR}/MESSAGE.log"
|
||||||
|
|
||||||
# check for uers / groups to ignore
|
# check for users / groups to ignore
|
||||||
jssh_updateArray_async "BASHBOTBLOCKED" "${BLOCKEDFILE}"
|
jssh_updateArray_async "BASHBOTBLOCKED" "${BLOCKEDFILE}"
|
||||||
[ -n "${USER[ID]}" ] && [[ -n "${BASHBOTBLOCKED[${USER[ID]}]}" || -n "${BASHBOTBLOCKED[${CHAT[ID]}]}" ]] && return
|
[ -n "${USER[ID]}" ] && [[ -n "${BASHBOTBLOCKED[${USER[ID]}]}" || -n "${BASHBOTBLOCKED[${CHAT[ID]}]}" ]] && return
|
||||||
|
|
||||||
@ -796,7 +827,7 @@ process_message() {
|
|||||||
MESSAGE[0]+="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's|\\/|/|g')"
|
MESSAGE[0]+="$(JsonDecode "${UPD["result",${num},"message","text"]}" | sed 's|\\/|/|g')"
|
||||||
MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}"
|
MESSAGE[ID]="${UPD["result",${num},"message","message_id"]}"
|
||||||
|
|
||||||
# Chat ID is now parsed when update isreceived
|
# Chat ID is now parsed when update is received
|
||||||
CHAT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","last_name"]}")"
|
CHAT[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","last_name"]}")"
|
||||||
CHAT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","first_name"]}")"
|
CHAT[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","chat","first_name"]}")"
|
||||||
CHAT[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","chat","username"]}")"
|
CHAT[USERNAME]="$(JsonDecode "${UPD["result",${num},"message","chat","username"]}")"
|
||||||
@ -806,7 +837,7 @@ process_message() {
|
|||||||
CHAT[TYPE]="$(JsonDecode "${UPD["result",${num},"message","chat","type"]}")"
|
CHAT[TYPE]="$(JsonDecode "${UPD["result",${num},"message","chat","type"]}")"
|
||||||
CHAT[ALL_ADMIN]="${UPD["result",${num},"message","chat","all_members_are_administrators"]}"
|
CHAT[ALL_ADMIN]="${UPD["result",${num},"message","chat","all_members_are_administrators"]}"
|
||||||
|
|
||||||
# user ID is now parsed when update isreceived
|
# user ID is now parsed when update is received
|
||||||
#USER[ID]="${UPD["result",${num},"message","from","id"]}"
|
#USER[ID]="${UPD["result",${num},"message","from","id"]}"
|
||||||
USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")"
|
USER[FIRST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","first_name"]}")"
|
||||||
USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")"
|
USER[LAST_NAME]="$(JsonDecode "${UPD["result",${num},"message","from","last_name"]}")"
|
||||||
@ -903,7 +934,7 @@ process_message() {
|
|||||||
[ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[PINNED]}" ] &&\
|
[ -z "${MESSAGE[0]}" ] && [ -n "${SERVICE[PINNED]}" ] &&\
|
||||||
MESSAGE[0]="/_new_pinned_message ${USER[ID]} ${PINNED[ID]} ${PINNED[MESSAGE]}"
|
MESSAGE[0]="/_new_pinned_message ${USER[ID]} ${PINNED[ID]} ${PINNED[MESSAGE]}"
|
||||||
fi
|
fi
|
||||||
# set SSERVICE to yes if a service message was received
|
# set SERVICE to yes if a service message was received
|
||||||
[[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes"
|
[[ "${SERVICE[*]}" =~ ^[[:blank:]]*$ ]] || SERVICE[0]="yes"
|
||||||
|
|
||||||
# split message in command and args
|
# split message in command and args
|
||||||
@ -928,7 +959,7 @@ start_bot() {
|
|||||||
[[ "${1}" == *"debug" ]] && exec &>>"${DEBUGLOG}"
|
[[ "${1}" == *"debug" ]] && exec &>>"${DEBUGLOG}"
|
||||||
printf "%s\n" "${DEBUGMSG}"; DEBUGMSG="${1}"
|
printf "%s\n" "${DEBUGMSG}"; DEBUGMSG="${1}"
|
||||||
[[ "${DEBUGMSG}" == "xdebug"* ]] && set -x
|
[[ "${DEBUGMSG}" == "xdebug"* ]] && set -x
|
||||||
#cleaup old pipes and empty logfiles
|
# cleaup old pipes and empty logfiles
|
||||||
find "${DATADIR}" -type p -delete
|
find "${DATADIR}" -type p -delete
|
||||||
find "${DATADIR}" -size 0 -name "*.log" -delete
|
find "${DATADIR}" -size 0 -name "*.log" -delete
|
||||||
# load addons on startup
|
# load addons on startup
|
||||||
@ -963,8 +994,8 @@ start_bot() {
|
|||||||
# adaptive sleep in ms rounded to next 0.1 s
|
# adaptive sleep in ms rounded to next 0.1 s
|
||||||
sleep "$(_round_float "${nextsleep}e-3" "1")"
|
sleep "$(_round_float "${nextsleep}e-3" "1")"
|
||||||
# get next update
|
# get next update
|
||||||
UPDATE="$(getJson "$UPD_URL$OFFSET" "nolog" 2>/dev/null | "${JSONSHFILE}" -s -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)"
|
UPDATE="$(getJson "${UPD_URL}${OFFSET}" "nolog" 2>/dev/null | "${JSONSHFILE}" -b -n 2>/dev/null | iconv -f utf-8 -t utf-8 -c)"
|
||||||
# did we ge an responsn0r
|
# did we get an response?
|
||||||
if [ -n "${UPDATE}" ]; then
|
if [ -n "${UPDATE}" ]; then
|
||||||
# we got something, do processing
|
# we got something, do processing
|
||||||
[ "${OFFSET}" = "-999" ] && [ "${nextsleep}" -gt "$((maxsleep*2))" ] &&\
|
[ "${OFFSET}" = "-999" ] && [ "${nextsleep}" -gt "$((maxsleep*2))" ] &&\
|
||||||
@ -981,7 +1012,7 @@ start_bot() {
|
|||||||
process_updates "${DEBUGMSG}"
|
process_updates "${DEBUGMSG}"
|
||||||
fi
|
fi
|
||||||
else
|
else
|
||||||
# ups, something bad happened, wait maxsleep*10
|
# oops, something bad happened, wait maxsleep*10
|
||||||
(( nextsleep=nextsleep*2 , nextsleep= nextsleep>maxsleep*10 ?maxsleep*10:nextsleep ))
|
(( nextsleep=nextsleep*2 , nextsleep= nextsleep>maxsleep*10 ?maxsleep*10:nextsleep ))
|
||||||
[ "${OFFSET}" = "-999" ] &&\
|
[ "${OFFSET}" = "-999" ] &&\
|
||||||
log_error "Repeated timeout/broken/no connection on telegram update, sleep $(_round_float "${nextsleep}e-3")s"
|
log_error "Repeated timeout/broken/no connection on telegram update, sleep $(_round_float "${nextsleep}e-3")s"
|
||||||
@ -1017,7 +1048,7 @@ bot_init() {
|
|||||||
done
|
done
|
||||||
echo "Done."
|
echo "Done."
|
||||||
fi
|
fi
|
||||||
#setup bashbot
|
# setup bashbot
|
||||||
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
|
[[ "${UID}" -eq "0" ]] && RUNUSER="nobody"
|
||||||
echo -n "Enter User to run bashbot [$RUNUSER]: "
|
echo -n "Enter User to run bashbot [$RUNUSER]: "
|
||||||
read -r TOUSER
|
read -r TOUSER
|
||||||
@ -1081,11 +1112,11 @@ if [ -z "${SOURCE}" ]; then
|
|||||||
##############
|
##############
|
||||||
# internal options only for use from bashbot and developers
|
# internal options only for use from bashbot and developers
|
||||||
case "${1}" in
|
case "${1}" in
|
||||||
# update botname botname when starting only
|
# update botname when starting only
|
||||||
"botname"|"start"*)
|
"botname"|"start"*)
|
||||||
ME="$(getBotName)"
|
ME="$(getBotName)"
|
||||||
if [ -n "${ME}" ]; then
|
if [ -n "${ME}" ]; then
|
||||||
# ok we have a connection an got botname, save it
|
# ok we have a connection and got botname, save it
|
||||||
[ -n "${CLEAR}" ] && echo -e "${GREY}Bottoken is valid ...${NC}"
|
[ -n "${CLEAR}" ] && echo -e "${GREY}Bottoken is valid ...${NC}"
|
||||||
jssh_updateKeyDB "botname" "${ME}" "${BOTCONFIG}"
|
jssh_updateKeyDB "botname" "${ME}" "${BOTCONFIG}"
|
||||||
rm -f "${BOTCONFIG}.jssh.flock"
|
rm -f "${BOTCONFIG}.jssh.flock"
|
||||||
@ -1115,7 +1146,7 @@ if [ -z "${SOURCE}" ]; then
|
|||||||
debug_checks "end outproc" "$@"
|
debug_checks "end outproc" "$@"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
# finally starts the read update loop, internal use only1
|
# finally starts the read update loop, internal use only1
|
||||||
"startbot" )
|
"startbot" )
|
||||||
start_bot "$2"
|
start_bot "$2"
|
||||||
debug_checks "end startbot" "$@"
|
debug_checks "end startbot" "$@"
|
||||||
@ -1127,7 +1158,7 @@ if [ -z "${SOURCE}" ]; then
|
|||||||
debug_checks "end init" "$@"
|
debug_checks "end init" "$@"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
# print usage sats
|
# print usage stats
|
||||||
"count") echo -e "${RED}Command ${GREY}count${RED} is deprecated, use ${GREY}stats{$RED}instead.${NC}";&
|
"count") echo -e "${RED}Command ${GREY}count${RED} is deprecated, use ${GREY}stats{$RED}instead.${NC}";&
|
||||||
"stats")
|
"stats")
|
||||||
ME="$(getConfigKey "botname")"
|
ME="$(getConfigKey "botname")"
|
||||||
@ -1163,7 +1194,7 @@ if [ -z "${SOURCE}" ]; then
|
|||||||
debug_checks "end $1" "$@"
|
debug_checks "end $1" "$@"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
# sedn message to all users
|
# send message to all users
|
||||||
'broadcast')
|
'broadcast')
|
||||||
ME="$(getConfigKey "botname")"
|
ME="$(getConfigKey "botname")"
|
||||||
declare -A SENDALL
|
declare -A SENDALL
|
||||||
@ -1184,7 +1215,7 @@ if [ -z "${SOURCE}" ]; then
|
|||||||
debug_checks "end $1" "$@"
|
debug_checks "end $1" "$@"
|
||||||
exit
|
exit
|
||||||
;;
|
;;
|
||||||
# does what is says
|
# does what it says
|
||||||
"status")
|
"status")
|
||||||
ME="$(getConfigKey "botname")"
|
ME="$(getConfigKey "botname")"
|
||||||
SESSION="${ME:-_bot}-startbot"
|
SESSION="${ME:-_bot}-startbot"
|
||||||
@ -1199,7 +1230,7 @@ if [ -z "${SOURCE}" ]; then
|
|||||||
debug_checks "end status" "$@"
|
debug_checks "end status" "$@"
|
||||||
;;
|
;;
|
||||||
|
|
||||||
# start bot as background jod and check if bot is running
|
# start bot as background job and check if bot is running
|
||||||
"start")
|
"start")
|
||||||
# shellcheck disable=SC2086
|
# shellcheck disable=SC2086
|
||||||
SESSION="${ME:-_bot}-startbot"
|
SESSION="${ME:-_bot}-startbot"
|
||||||
@ -1257,6 +1288,6 @@ if [ -z "${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 running a Telegram BOT with root privilegs!${NC}"
|
echo -e "${ORANGE}You are at HIGH RISK when running a Telegram BOT with root privileges!${NC}"
|
||||||
fi
|
fi
|
||||||
fi # end source
|
fi # end source
|
||||||
|
2
db.json
2
db.json
@ -14,7 +14,7 @@
|
|||||||
"ok":
|
"ok":
|
||||||
{
|
{
|
||||||
"ok":true,
|
"ok":true,
|
||||||
"description":"Ttest for ok"
|
"description":"Test for ok"
|
||||||
} ,
|
} ,
|
||||||
"getMe":
|
"getMe":
|
||||||
{
|
{
|
||||||
|
@ -39,11 +39,20 @@ In addition you can check individual capabilities of users as you must define in
|
|||||||
# allow user 987654321 only to start bot in chat 98979695
|
# allow user 987654321 only to start bot in chat 98979695
|
||||||
987654321:start:98979695
|
987654321:start:98979695
|
||||||
|
|
||||||
|
# special case allow ALL users ONE action in all groups or in one group
|
||||||
|
ALL:search:*
|
||||||
|
ALL:search:98979695
|
||||||
|
|
||||||
|
# not valid, ALL must have an action!
|
||||||
|
ALL:*:*
|
||||||
|
|
||||||
# * are only allowed on the right hand side and not for user!
|
# * are only allowed on the right hand side and not for user!
|
||||||
# the following examples are NOT valid!
|
# the following examples are NOT valid!
|
||||||
*:*:*
|
*:*:*
|
||||||
*:start:*
|
*:start:*
|
||||||
*:*:98979695
|
*:*:98979695
|
||||||
|
|
||||||
|
|
||||||
```
|
```
|
||||||
You must use the function ```user_is_allowed``` to check if a user has the capability to do something. Example: Check if user has capability to start bot.
|
You must use the function ```user_is_allowed``` to check if a user has the capability to do something. Example: Check if user has capability to start bot.
|
||||||
|
|
||||||
@ -288,5 +297,5 @@ Note: If you disable automatic retry, se above, you disable also connection prob
|
|||||||
#### [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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-14-g6ec00d4
|
||||||
|
|
||||||
|
@ -107,8 +107,8 @@ by sourcing it:
|
|||||||
|
|
||||||
*usage:* . bashbot.sh source
|
*usage:* . bashbot.sh source
|
||||||
|
|
||||||
Before sourcing 'bahsbot.sh' for interactive and script use, you should export and set BASHBOT_HOME to bashbots installation dir,
|
Before sourcing 'bashbot.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)
|
e.g. '/usr/local/telegram-bot-bash'. see [Bashbot Environment](#Bashbot-environment)
|
||||||
|
|
||||||
**Note:** *If you don't set BASHBOT_HOME bashbot will use the actual directory as NEW home directory
|
**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!*
|
which means it will create all needed files and ask for bot token and botadmin if you are not in the real bot home!*
|
||||||
@ -378,5 +378,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
|
|||||||
#### [Prev Advanced Use](3_advanced.md)
|
#### [Prev Advanced Use](3_advanced.md)
|
||||||
#### [Next Best Practice](5_practice.md)
|
#### [Next Best Practice](5_practice.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
|
@ -15,7 +15,7 @@ To start with a clean/minimal bot copy ```mycommands.sh.clean``` to ```mycommand
|
|||||||
the message strings and place commands in the```case ... esac``` block of the function mycommands():
|
the message strings and place commands in the```case ... esac``` block of the function mycommands():
|
||||||
```bash
|
```bash
|
||||||
# file: mycommands.sh
|
# file: mycommands.sh
|
||||||
# your additional bahsbot commands
|
# your additional bashbot commands
|
||||||
|
|
||||||
# uncomment the following lines to overwrite info and help messages
|
# uncomment the following lines to overwrite info and help messages
|
||||||
bashbot_info='This is *MY* variant of _bashbot_, the Telegram bot written entirely in bash.
|
bashbot_info='This is *MY* variant of _bashbot_, the Telegram bot written entirely in bash.
|
||||||
@ -158,5 +158,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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
|
@ -281,7 +281,7 @@ fi
|
|||||||
*See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)*
|
*See also [Chat Member](https://core.telegram.org/bots/api/#chatmember)*
|
||||||
|
|
||||||
##### user_is_allowed
|
##### user_is_allowed
|
||||||
Bahsbot supports User Access Control, see [Advanced Usage](3_advanced.md)
|
Bashbot supports User Access Control, see [Advanced Usage](3_advanced.md)
|
||||||
|
|
||||||
*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}"
|
*usage:* user_is_allowed "${USER[ID]}" "what" "${CHAT[ID]}"
|
||||||
|
|
||||||
@ -1049,5 +1049,5 @@ The name of your bot is available as bash variable "$ME", there is no need to ca
|
|||||||
#### [Prev Best Practice](5_practice.md)
|
#### [Prev Best Practice](5_practice.md)
|
||||||
#### [Next Notes for Developers](7_develop.md)
|
#### [Next Notes for Developers](7_develop.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
## 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, modules and addons, not on develop your individual bot. Nevertheless the information provided here should help your bot development also.
|
This section is about help and best practices for new bashbot developers. The main focus on is creating new versions of bashbot, modules and addons, not on develop your individual bot. Nevertheless the information provided here should help your bot development also.
|
||||||
|
|
||||||
If you want to provide fixes or new features [fork bashbot on githup](https://help.github.com/en/articles/fork-a-repo) and provide changes as [pull request on github](https://help.github.com/en/articles/creating-a-pull-request).
|
If you want to provide fixes or new features [fork bashbot on github](https://help.github.com/en/articles/fork-a-repo) and provide changes as [pull request on github](https://help.github.com/en/articles/creating-a-pull-request).
|
||||||
|
|
||||||
### Debugging Bashbot
|
### Debugging Bashbot
|
||||||
Usually all bashbot output is discarded.
|
Usually all bashbot output is discarded.
|
||||||
@ -31,13 +31,13 @@ you can the change the level of verbosity of the debug argument:
|
|||||||
to keep 'bashbot.sh' small, while extending functionality. In addition not every function is needed by all bots, so you can
|
to keep 'bashbot.sh' small, while extending functionality. In addition not every function is needed by all bots, so you can
|
||||||
disable modules, e.g. by rename the respective module file to 'module.sh.off'.
|
disable modules, e.g. by rename the respective module file to 'module.sh.off'.
|
||||||
|
|
||||||
Modules must use only functions provided by 'bahsbot.sh' or the module itself and should not depend on other modules or addons.
|
Modules must use only functions provided by 'bashbot.sh' or the module itself and should not depend on other modules or addons.
|
||||||
The only mandatory module is 'module/sendMessage.sh'.
|
The only mandatory module is 'module/sendMessage.sh'.
|
||||||
|
|
||||||
If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ```_is_function``` or
|
If a not mandatory module is used in 'bashbot.sh' or 'commands.sh', the use of ```_is_function``` or
|
||||||
```_execute_if_function``` is mandatory to catch absence of the module.
|
```_execute_if_function``` is mandatory to catch absence of the module.
|
||||||
|
|
||||||
**Addons** resides in ```addons/*.sh.dist``` and are not endabled by default. To activate an addon rename it to end with '.sh', e.g. by
|
**Addons** resides in ```addons/*.sh.dist``` and are not enabled by default. To activate an addon rename it to end with '.sh', e.g. by
|
||||||
```cp addons/example.sh.dist addons/example.sh```.
|
```cp addons/example.sh.dist addons/example.sh```.
|
||||||
|
|
||||||
Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function every time a message is received.
|
Addons must register themself to BASHBOT_EVENTS at startup, e.g. to call a function every time a message is received.
|
||||||
@ -115,7 +115,7 @@ To avoid wrong use of EVENT_SEND, e.g. fork bomb, event processing is suspended
|
|||||||
*Example:*
|
*Example:*
|
||||||
```bash
|
```bash
|
||||||
# register callback:
|
# register callback:
|
||||||
BAHSBOT_EVENT_SEND["example_log","1"]="example_log"
|
BASHBOT_EVENT_SEND["example_log","1"]="example_log"
|
||||||
EXAMPLE_LOG="${BASHBOT_ETC:-.}/addons/${EXAMPLE_ME}.log"
|
EXAMPLE_LOG="${BASHBOT_ETC:-.}/addons/${EXAMPLE_ME}.log"
|
||||||
|
|
||||||
# Note: do not call any send message functions from EVENT_SEND!
|
# Note: do not call any send message functions from EVENT_SEND!
|
||||||
@ -130,7 +130,7 @@ example_log(){
|
|||||||
|
|
||||||
Important: Bashbot timer tick is disabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero.
|
Important: Bashbot timer tick is disabled by default and must be enabled by setting BASHBOT_START_TIMER to any value not zero.
|
||||||
|
|
||||||
* BAHSBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes.
|
* BASHBOT_EVENT_TIMER executed every minute and can be used in 3 variants: oneshot, once a minute, every X minutes.
|
||||||
|
|
||||||
Registering to BASHBOT_EVENT_TIMER works similar as for message events, but you must add a timing argument to the name.
|
Registering to BASHBOT_EVENT_TIMER works similar as for message events, but you must add a timing argument to the name.
|
||||||
EVENT_TIMER is triggered every 60s and waits until the current running command is finished, so it's not exactly every
|
EVENT_TIMER is triggered every 60s and waits until the current running command is finished, so it's not exactly every
|
||||||
@ -139,7 +139,7 @@ minute, but once a minute.
|
|||||||
Every time EVENT_TIMER is triggered the variable "EVENT_TIMER" is increased. each callback is executed if ```EVENT_TIMER % time``` is '0' (true).
|
Every time EVENT_TIMER is triggered the variable "EVENT_TIMER" is increased. each callback is executed if ```EVENT_TIMER % time``` is '0' (true).
|
||||||
This means if you register an every 5 minutes callback first execution may < 5 Minutes, all subsequent executions are once every 5. Minute.
|
This means if you register an every 5 minutes callback first execution may < 5 Minutes, all subsequent executions are once every 5. Minute.
|
||||||
|
|
||||||
*usage:* BAHSBOT_EVENT_TIMER[ "name" , "time" ], where time is:
|
*usage:* BASHBOT_EVENT_TIMER[ "name" , "time" ], where time is:
|
||||||
|
|
||||||
* 0 ignored
|
* 0 ignored
|
||||||
* 1 execute once every minute
|
* 1 execute once every minute
|
||||||
@ -151,7 +151,7 @@ Note: If you want exact "in x minutes" use "EVENT_TIMER plus x" as time: ```-(EV
|
|||||||
*Example:*
|
*Example:*
|
||||||
```bash
|
```bash
|
||||||
# register callback:
|
# register callback:
|
||||||
BAHSBOT_EVENT_TIMER["example_every","1"]="example_everymin"
|
BASHBOT_EVENT_TIMER["example_every","1"]="example_everymin"
|
||||||
|
|
||||||
# function called every minute
|
# function called every minute
|
||||||
example_everymin() {
|
example_everymin() {
|
||||||
@ -160,13 +160,13 @@ example_everymin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
# register other callback:
|
# register other callback:
|
||||||
BAHSBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
|
BASHBOT_EVENT_TIMER["example_every5","5"]="example_every5min"
|
||||||
|
|
||||||
# execute once on the next 10 minutes since start "event"
|
# execute once on the next 10 minutes since start "event"
|
||||||
BAHSBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
|
BASHBOT_EVENT_TIMER["example_10min","-10"]="example_in10min"
|
||||||
|
|
||||||
# once in exact 10 minutes
|
# once in exact 10 minutes
|
||||||
BAHSBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in10min"
|
BASHBOT_EVENT_TIMER["example_10min","$(( (EVENT_TIMER+10) * -1 ))"]="example_in10min"
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -297,7 +297,7 @@ To create a new test run ```test/ADD-test-new.sh``` and answer the questions, it
|
|||||||
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
|
||||||
of your test)* and an optional dir ```p-name-test/``` *(script name minus '.sh')* for additional files.
|
of your test)* and an optional dir ```p-name-test/``` *(script name minus '.sh')* for additional files.
|
||||||
|
|
||||||
Tests with no dependency to other tests will run in pass 'a', tests which need an initialized bahsbot environment must run in pass 'd' or later.
|
Tests with no dependency to other tests will run in pass 'a', tests which need an initialized bashbot environment must run in pass 'd' or later.
|
||||||
A temporary test environment is created when 'ALL-tests.sh' starts and deleted after all tests are finished.
|
A temporary test environment is created when 'ALL-tests.sh' starts and deleted after all tests are finished.
|
||||||
|
|
||||||
The file ```ALL-tests.inc.sh``` must be included from all tests and provide the test environment as shell variables:
|
The file ```ALL-tests.inc.sh``` must be included from all tests and provide the test environment as shell variables:
|
||||||
@ -347,5 +347,5 @@ fi
|
|||||||
|
|
||||||
#### [Prev Function Reference](6_reference.md)
|
#### [Prev Function Reference](6_reference.md)
|
||||||
|
|
||||||
#### $$VERSION$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# copy to mycommands.sh and add all your commands an functions here ...
|
# copy to mycommands.sh and add all your commands an functions here ...
|
||||||
export res
|
export res
|
||||||
|
|
||||||
# your additional bahsbot commands ...
|
# your additional bashbot commands ...
|
||||||
mycommands() {
|
mycommands() {
|
||||||
|
|
||||||
case "$MESSAGE" in
|
case "$MESSAGE" in
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
######
|
######
|
||||||
# parameters
|
# parameters
|
||||||
@ -24,6 +24,7 @@ unset IFS
|
|||||||
# discard STDIN for background jobs!
|
# discard STDIN for background jobs!
|
||||||
cat >/dev/null &
|
cat >/dev/null &
|
||||||
|
|
||||||
|
# shellcheck source=examples/background-scripts/mycommands.sh
|
||||||
source "./mycommands.sh"
|
source "./mycommands.sh"
|
||||||
|
|
||||||
# check if $1 is a number
|
# check if $1 is a number
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
######
|
######
|
||||||
# parameters
|
# parameters
|
||||||
@ -24,6 +24,8 @@ cat >/dev/null &
|
|||||||
|
|
||||||
# watch for new files created by a trusted program
|
# watch for new files created by a trusted program
|
||||||
WATCHDIR="/my_trusted/dir_to_watch"
|
WATCHDIR="/my_trusted/dir_to_watch"
|
||||||
|
|
||||||
|
# shellcheck source=examples/background-scripts/mycommands.sh
|
||||||
source "./mycommands.sh"
|
source "./mycommands.sh"
|
||||||
|
|
||||||
# test your script and the remove ...
|
# test your script and the remove ...
|
||||||
@ -39,4 +41,3 @@ loop_callback() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
watch_dir_loop "$WATCHDIR"
|
watch_dir_loop "$WATCHDIR"
|
||||||
|
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
######
|
######
|
||||||
# parameters
|
# parameters
|
||||||
@ -19,11 +19,13 @@ export 'LANGUAGE=C.UTF-8'
|
|||||||
unset IFS
|
unset IFS
|
||||||
# set -f # if you are paranoid use set -f to disable globbing
|
# set -f # if you are paranoid use set -f to disable globbing
|
||||||
|
|
||||||
# discard STDIN for background jobs!
|
# shellcheck source=examples/background-scripts/mycommands.sh
|
||||||
cat >/dev/null &
|
cat >/dev/null &
|
||||||
|
|
||||||
# watch for new logfiles
|
# watch for new logfiles
|
||||||
WATCHDIR="/var/log"
|
WATCHDIR="/var/log"
|
||||||
|
|
||||||
|
# shellcheck disable=SC1091
|
||||||
source "./mycommands.sh"
|
source "./mycommands.sh"
|
||||||
|
|
||||||
# test your script and the remove ...
|
# test your script and the remove ...
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||||
echo "Usage: $0 botname command"
|
echo "Usage: $0 botname command"
|
||||||
@ -23,8 +23,8 @@ if true; then
|
|||||||
else
|
else
|
||||||
# alternative linux like locations
|
# alternative linux like locations
|
||||||
BINDIR="/usr/local/bin"
|
BINDIR="/usr/local/bin"
|
||||||
ETC="/etc/bahsbot"
|
ETC="/etc/bashbot"
|
||||||
VAR="/var/bahsbot"
|
VAR="/var/bashbot"
|
||||||
export BASHBOT_JSONSH="/usr/local/bin/JSON.sh"
|
export BASHBOT_JSONSH="/usr/local/bin/JSON.sh"
|
||||||
|
|
||||||
fi
|
fi
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
#
|
#
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
@ -206,7 +206,7 @@ else
|
|||||||
my_startup
|
my_startup
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# your additional bahsbot commands
|
# your additional bashbot commands
|
||||||
# NOTE: command can have @botname attached, you must add * in case tests...
|
# NOTE: command can have @botname attached, you must add * in case tests...
|
||||||
mycommands() {
|
mycommands() {
|
||||||
# a service Message was received
|
# a service Message was received
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
#
|
#
|
||||||
# shellcheck disable=SC2154
|
# shellcheck disable=SC2154
|
||||||
# shellcheck disable=SC2034
|
# shellcheck disable=SC2034
|
||||||
@ -32,7 +32,7 @@ bashbot_help='*Available commands*:
|
|||||||
'
|
'
|
||||||
|
|
||||||
|
|
||||||
# your additional bahsbot commands
|
# your additional bashbot commands
|
||||||
# NOTE: command can have @botname attached, you must add * in case tests...
|
# NOTE: command can have @botname attached, you must add * in case tests...
|
||||||
mycommands() {
|
mycommands() {
|
||||||
local msg=""
|
local msg=""
|
||||||
|
@ -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$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-14-g6ec00d4
|
||||||
|
|
||||||
# will be automatically sourced from bashbot
|
# will be automatically sourced from bashbot
|
||||||
|
|
||||||
@ -59,11 +59,18 @@ user_is_botadmin() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
user_is_allowed() {
|
user_is_allowed() {
|
||||||
local acl="$1"
|
|
||||||
[ -z "$1" ] && return 1
|
[ -z "$1" ] && return 1
|
||||||
grep -F -xq "${acl}:*:*" <"${BOTACL}" && return 0
|
# user can do everything
|
||||||
[ -n "$2" ] && acl="${acl}:$2"
|
grep -F -xq "$1:*:*" <"${BOTACL}" && return 0
|
||||||
grep -F -xq "${acl}:*" <"${BOTACL}" && return 0
|
[ -z "$2" ] && return 1
|
||||||
[ -n "$3" ] && acl="${acl}:$3"
|
# user is allowed todo one action in every chat
|
||||||
grep -F -xq "${acl}" <"${BOTACL}"
|
grep -F -xq "$1:$2:*" <"${BOTACL}" && return 0
|
||||||
|
# all users are allowed to do one action in every chat
|
||||||
|
grep -F -xq "ALL:$2:*" <"${BOTACL}" && return 0
|
||||||
|
[ -z "$3" ] && return 1
|
||||||
|
# user is allowed to do one action in one chat
|
||||||
|
grep -F -xq "$1:$2:$3" <"${BOTACL}" && return 0
|
||||||
|
# all users are allowed to do one action in one chat
|
||||||
|
grep -F -xq "ALL:$2:$3" <"${BOTACL}" && return 0
|
||||||
|
return 1
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
#### $$VERSION$$ v1.0-0-g99217c4
|
#### $$VERSION$$ v1.2-dev-13-g2a5d47d
|
||||||
|
|
||||||
# include common functions and definitions
|
# include common functions and definitions
|
||||||
# shellcheck source=test/ALL-tests.inc.sh
|
# shellcheck source=test/ALL-tests.inc.sh
|
||||||
@ -23,7 +23,7 @@ do
|
|||||||
for jsonfile in "${REFDIR}"/*.in
|
for jsonfile in "${REFDIR}"/*.in
|
||||||
do
|
do
|
||||||
set -f
|
set -f
|
||||||
[ "${i}" = "1" ] && "${JSON}" -s -b -n <"${jsonfile}" >"${jsonfile}.out-${i}"
|
[ "${i}" = "1" ] && "${JSON}" -b -n <"${jsonfile}" >"${jsonfile}.out-${i}"
|
||||||
[ "${i}" = "2" ] && "${JSON}" <"${jsonfile}" >"${jsonfile}.out-${i}"
|
[ "${i}" = "2" ] && "${JSON}" <"${jsonfile}" >"${jsonfile}.out-${i}"
|
||||||
|
|
||||||
# output processed input
|
# output processed input
|
||||||
|
Loading…
x
Reference in New Issue
Block a user