mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-12-31 22:01:46 +00:00
commit
df53191838
@ -150,6 +150,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
|
||||
<li><a href="examples/README.md">Examples Dir</a></li>
|
||||
</ul>
|
||||
<h3>Your really first bashbot in a nutshell</h3>
|
||||
<p>Note for MacOS: you must install install a more current bash, see <a href="doc/0_install.md">Install Bashbot</a></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>
|
||||
<p>In addition you need a <a href="https://telegram.org">Telegram client</a> and a mobile phone to <a href="https://telegramguide.com/create-a-telegram-account/">register an account</a>. If you don't want to register for Telegram you should stop reading here ;-)</p>
|
||||
<p>After you're registered to Telegram send a message to <a href="https://telegram.me/botfather">@botfather</a>, <a href="doc/1_firstbot.md">create a new Telegram Bot token</a> and write it down. You need the token to install the bot.</p>
|
||||
@ -178,6 +179,10 @@ It features background tasks and interactive chats, and can serve as an interfac
|
||||
<p>Bash scripts in general are not designed to be bullet proof, so consider this Bot as a proof of concept. Bash programmers often struggle with 'quoting hell' and globbing, see <a href="https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells">Implications of wrong quoting</a></p>
|
||||
<p>Whenever you are processing input from from untrusted sources (messages, files, network) you must be as carefull as possible, e.g. set IFS appropriate, disable globbing (set -f) and quote everthing. In addition delete unused scripts and examples from your Bot, e.g. scripts 'notify', 'calc', 'question', and disable all not used commands.</p>
|
||||
<p>A powerful tool to improve your scripts is <code>shellcheck</code>. You can <a href="https://www.shellcheck.net/">use it online</a> or <a href="https://github.com/koalaman/shellcheck#installing">install shellcheck locally</a>. Shellcheck is used extensive in bashbot development to enshure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests. In addition bashbot has a <a href="doc/7_develop.md">test suite</a> to check if important functionality is working as expected.</p>
|
||||
<h3>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>Using the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using possibly broken, mangled or compromised bash executables.</p>
|
||||
<p>If you are a MacOS user or forced to use an alternative bash, see <a href="doc/0_install.md">Install Bashbot</a></p>
|
||||
<h3>Run your Bot as a restricted user</h3>
|
||||
<p><strong>I recommend to run your bot as a user, with almost no access rights.</strong> All files your Bot have write access to are in danger to be overwritten/deleted if your bot is hacked. For the same reason ervery file your Bot can read is in danger to be disclosed. Restict your Bots access rigths to the absolute minimum.</p>
|
||||
<p><strong>Never run your Bot as root, this is the most dangerous you can do!</strong> Usually the user 'nobody' has almost no rights on Unix/Linux systems. See <a href="doc/4_expert.md">Expert use</a> on how to run your Bot as an other user.</p>
|
||||
@ -223,6 +228,6 @@ It features background tasks and interactive chats, and can serve as an interfac
|
||||
<p>@Gnadelwartz</p>
|
||||
<h2>That's it!</h2>
|
||||
<p>If you feel that there's something missing or if you found a bug, feel free to submit a pull request!</p>
|
||||
<h4>$$VERSION$$ v0.94-pre-0-gac2ec02</h4>
|
||||
<h4>$$VERSION$$ V0.94-1-g7aa409f</h4>
|
||||
</body>
|
||||
</html>
|
||||
|
14
README.md
14
README.md
@ -59,6 +59,9 @@ Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Do
|
||||
* [Examples Dir](examples/README.md)
|
||||
|
||||
### Your really first bashbot in a nutshell
|
||||
|
||||
Note for MacOS: you must install install a more current bash, see [Install Bashbot](doc/0_install.md)
|
||||
|
||||
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 :-(
|
||||
|
||||
In addition you need a [Telegram client](https://telegram.org) and a mobile phone to [register an account](https://telegramguide.com/create-a-telegram-account/).
|
||||
@ -109,6 +112,15 @@ Whenever you are processing input from from untrusted sources (messages, files,
|
||||
A powerful tool to improve your scripts is ```shellcheck```. You can [use it online](https://www.shellcheck.net/) or [install shellcheck locally](https://github.com/koalaman/shellcheck#installing). Shellcheck is used extensive in bashbot development to enshure a high code quality, e.g. it's not allowed to push changes without passing all shellcheck tests.
|
||||
In addition bashbot has a [test suite](doc/7_develop.md) to check if important functionality is working as expected.
|
||||
|
||||
### Do not use #!/usr/bin/env bash
|
||||
|
||||
**We stay with /bin/bash shebang, because it's more save from security perspective.**
|
||||
|
||||
Using the system provided bash makes it harder for attackers or users to place alternative versions of bash and avoids using
|
||||
possibly broken, mangled or compromised bash executables.
|
||||
|
||||
If you are a MacOS user or forced to use an alternative bash, see [Install Bashbot](doc/0_install.md)
|
||||
|
||||
### Run your Bot as a restricted user
|
||||
**I recommend to run your bot as a user, with almost no access rights.**
|
||||
All files your Bot have write access to are in danger to be overwritten/deleted if your bot is hacked.
|
||||
@ -180,4 +192,4 @@ This may happen if to many wrong requests are sent to api.telegram.org, e.g. usi
|
||||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-1-g7aa409f
|
||||
|
18
README.txt
18
README.txt
@ -70,6 +70,10 @@ availible on www.github.com
|
||||
* [Examples Dir](examples/README.md)
|
||||
|
||||
### Your really first bashbot in a nutshell
|
||||
|
||||
Note for MacOS: you must install install a more current bash, see [Install
|
||||
Bashbot](doc/0_install.md)
|
||||
|
||||
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 :-(
|
||||
@ -150,6 +154,18 @@ allowed to push changes without passing all shellcheck tests.
|
||||
In addition bashbot has a [test suite](doc/7_develop.md) to check if important
|
||||
functionality is working as expected.
|
||||
|
||||
### Do not use #!/usr/bin/env bash
|
||||
|
||||
**We stay with /bin/bash shebang, because it's more save from security
|
||||
perspective.**
|
||||
|
||||
Using the system provided bash makes it harder for attackers or users to place
|
||||
alternative versions of bash and avoids using
|
||||
possibly broken, mangled or compromised bash executables.
|
||||
|
||||
If you are a MacOS user or forced to use an alternative bash, see [Install
|
||||
Bashbot](doc/0_install.md)
|
||||
|
||||
### Run your Bot as a restricted user
|
||||
**I recommend to run your bot as a user, with almost no access rights.**
|
||||
All files your Bot have write access to are in danger to be overwritten/deleted
|
||||
@ -253,4 +269,4 @@ tor proxy on your server you may uncomment the ```BASHBOT_CURL_ARGS``` line in
|
||||
If you feel that there's something missing or if you found a bug, feel free to
|
||||
submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-1-g7aa409f
|
||||
|
@ -4,7 +4,7 @@
|
||||
# this addon counts how many files, e.g. stickers, are sent to
|
||||
# a chat and takes actions if threshold is reached
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-4-gd28f975
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# used events:
|
||||
#
|
||||
|
@ -4,7 +4,7 @@
|
||||
# Addons can register to bashbot events at statup
|
||||
# by providing their name and a callback per event
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
# If an event occours each registered event function is called.
|
||||
#
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-11-gac9ca60
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-4-gd28f975
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -344,7 +344,7 @@ JsonGetValue() {
|
||||
# $1 ARRAY name, must be declared with "declare -A ARRAY" before calling
|
||||
Json2Array() {
|
||||
# shellcheck source=./commands.sh
|
||||
[ -z "$1" ] || source <( printf "$1"'=( %s )' "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\t/ s/\t/=/gp' -e 's/=(true|false)/="\1"/')" )
|
||||
[ -z "$1" ] || source <( printf "$1"'=( %s )' "$(sed -E -n -e '/\["[-0-9a-zA-Z_,."]+"\]\+*\t/ s/\t/=/gp' -e 's/=(true|false)/="\1"/')" )
|
||||
}
|
||||
# output ARRAY as JSON.sh style data
|
||||
# $1 ARRAY name, must be declared with "declare -A ARRAY" before calling
|
||||
|
@ -15,7 +15,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-7-g64efe96
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
|
||||
# adjust your language setting here, e.g.when run from other user or cron.
|
||||
@ -104,7 +104,7 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
|
||||
'/start'*)
|
||||
send_action "${CHAT[ID]}" "typing"
|
||||
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
||||
if _is_botadmin || _is_allowed "start" ; then
|
||||
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" || user_is_allowed "${USER[ID]}" "start" ; then
|
||||
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
|
||||
else
|
||||
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
|
||||
@ -115,9 +115,9 @@ if [ -z "${1}" ] || [[ "${1}" == *"debug"* ]];then
|
||||
send_markdown_message "${CHAT[ID]}" "${bashbot_help}"
|
||||
;;
|
||||
'/leavechat'*) # bot leave chat if user is admin in chat
|
||||
if user_is_botadmin "${USER[ID]}" ; then
|
||||
if user_is_admin "${CHAT[ID]}" "${USER[ID]}" || user_is_allowed "${USER[ID]}" "leave" ; then
|
||||
send_markdown_message "${CHAT[ID]}" "*LEAVING CHAT...*"
|
||||
leave_chat "${CHAT[ID]}"
|
||||
leave_chat "${CHAT[ID]}"
|
||||
fi
|
||||
;;
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# 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
|
||||
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
############
|
||||
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
############
|
||||
# NOTE: you MUST run install-hooks.sh again when updating this file!
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
# this has to run once atfer git clone
|
||||
# and every time we create new hooks
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file: make-distribution.sh
|
||||
# creates files and arcchives to dirtribute bashbot
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-12-gb1d569a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -5,7 +5,7 @@
|
||||
# If you your bot is finished you can use make-standalone.sh to create the
|
||||
# the old all-in-one bashbot: bashbot.sh and commands.sh only!
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -1,4 +1,4 @@
|
||||
# list of additional files to check from shellcheck
|
||||
#### $$VERSION$$ v0.94-pre-7-g64efe96
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
bashbot.rc
|
||||
mycommands.sh.clean
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/bin/bash
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
# shellcheck disable=SC2016
|
||||
#
|
||||
# Easy Versioning in git:
|
||||
|
@ -39,10 +39,21 @@ As an alternative to download the zip files, you can clone the github repository
|
||||
4. Extract all files to your existing bashbot dir
|
||||
5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update
|
||||
|
||||
If you modified 'commands.sh' move your changes to 'mycommands.sh', this avoids overwrrite of you changes on updates.
|
||||
If you modified ```commands.sh``` move your changes to ```mycommands.sh```, this avoids overwrrite of you changes on updates.
|
||||
|
||||
Now you can restart your bashbot instances.
|
||||
|
||||
### Note for MacOS Users
|
||||
|
||||
You must install a more current version of bash, as the default bash is way to old,
|
||||
see e.g. [Install Bash on Mac](http://macappstore.org/bash/)
|
||||
|
||||
After installation / update of bashbot you must change the shebang line to point to your bash location
|
||||
e.g. with the provided script ```examples/bash2env.sh```
|
||||
|
||||
We stay with /bin/bash shebang, because using the system bash is more save, see
|
||||
[Security Considerations](../README.md#Security-Considerations)
|
||||
|
||||
### Notes on Updates
|
||||
|
||||
#### removal of TMUX
|
||||
@ -87,5 +98,5 @@ The old format is supported for backward compatibility, but may fail for corner
|
||||
|
||||
#### [Next Create Bot](1_firstbot.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-1-g7aa409f
|
||||
|
||||
|
@ -65,5 +65,5 @@ group. This step is up to you actually.
|
||||
#### [Prev Installation](0_install.md)
|
||||
#### [Next Getting started](2_usage.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -43,6 +43,7 @@ Have FUN!
|
||||
│
|
||||
├── examples # example scripts and configs for bashbot
|
||||
│ ├── README.md # description of files and examples
|
||||
│ ├── bash2env.shh # script to convert /bin/bash shebang to /usr/bin/env, see [Security Considerations](../README.md#Security-Considerations)
|
||||
│ └── bashbot.cron # example crontab
|
||||
│
|
||||
├── doc # Documentation and License
|
||||
@ -240,5 +241,5 @@ send_action "${CHAT[ID]}" "action"
|
||||
#### [Prev Create Bot](1_firstbot.md)
|
||||
#### [Next Advanced Usage](3_advanced.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -180,5 +180,5 @@ See also [answer_inline_multi, answer_inline_compose](6_reference.md#answer_inli
|
||||
#### [Prev Getting started](2_usage.md)
|
||||
#### [Next Expert Use](4_expert.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -348,5 +348,5 @@ for every poll until the maximum of BASHBOT_SLEEP ms.
|
||||
#### [Prev Advanced Use](3_advanced.md)
|
||||
#### [Next Best Practice](5_practice.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -152,5 +152,5 @@ The second warning is about an unused variable, this is true because in our exam
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Functions Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -973,5 +973,5 @@ The name of your bot is availible as bash variable "$ME", there is no need to ca
|
||||
#### [Prev Best Practice](5_practice.md)
|
||||
#### [Next Notes for Developers](7_develop.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-13-g52bde30
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -328,5 +328,5 @@ fi
|
||||
|
||||
#### [Prev Function Reference](6_reference.md)
|
||||
|
||||
#### $$VERSION$$ v0.94-pre-0-gac2ec02
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
@ -55,6 +55,6 @@ convert existing bots.
|
||||
|
||||
**external-use** will contain some examples on how to send messages from external scripts to Telegram chats or users.
|
||||
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
||||
|
@ -4,7 +4,7 @@
|
||||
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file: run_filename
|
||||
# background job to display content of all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
@ -2,7 +2,7 @@
|
||||
# file: run_filename
|
||||
# background job to display all new files in WATCHDIR
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# 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.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
62
examples/bash2env.sh
Executable file
62
examples/bash2env.sh
Executable file
@ -0,0 +1,62 @@
|
||||
#!/bin/bash
|
||||
# file: bash2env.sh
|
||||
# simole helper script to convert bash shebang from
|
||||
# ! /bin/bash TO ! /usr/bin/env bash
|
||||
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
export 'LC_ALL=C.UTF-8'
|
||||
export 'LANG=C.UTF-8'
|
||||
export 'LANGUAGE=C.UTF-8'
|
||||
|
||||
unset IFS
|
||||
|
||||
################
|
||||
# uncomment thenfollowing line to make the conversion
|
||||
# DOIT="yes"
|
||||
|
||||
if [ "$1" = "" ] || [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
|
||||
echo "$0: convert bash shebang to /usr/bin/env bash"
|
||||
echo "usage: $0 script [script ...]"
|
||||
exit
|
||||
fi
|
||||
|
||||
# loop tomprocess files
|
||||
if [ "${DOIT}" = "yes" ]; then
|
||||
echo "Warning, changes will be done!"
|
||||
else
|
||||
echo "Dry run, output changes only!"
|
||||
echo "Uncomment DOIT=\"yes\" in script to make the changes permanent."
|
||||
|
||||
fi
|
||||
|
||||
echo "Press enter to continue ..."
|
||||
#shellcheck disable=SC2034
|
||||
read -r CONTINUE
|
||||
|
||||
|
||||
for file in "$@"
|
||||
do
|
||||
file "${file}"
|
||||
if [[ "$(file -b "${file}")" =~ Bourne.*script.*text ]]; then
|
||||
echo "Processing ${file} ..."
|
||||
if head -n 1 "${file}" | grep -q '^#!/bin/bash'; then
|
||||
if [ "${DOIT}" = "yes" ]; then
|
||||
sed -i -e '1 s|^#!/bin/bash|#!/usr/bin/env bash|' "${file}"
|
||||
head -n 1 "${file}"
|
||||
else
|
||||
sed -n -e '1 s|^#!/bin/bash|#!/usr/bin/env bash (dry run)|p' "${file}"
|
||||
fi
|
||||
else
|
||||
echo "No #!/bin/bash shebang, nothing to convert."
|
||||
fi
|
||||
echo -e "... done.\n"
|
||||
else
|
||||
echo -e "Not a bash script, skipping ${file} ...\n"
|
||||
fi
|
||||
done
|
@ -2,7 +2,7 @@
|
||||
# file. multibot.sh
|
||||
# description: run multiple telegram bots from one installation
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
if [ "${2}" = "" ] || [ "${2}" = "-h" ]; then
|
||||
echo "Usage: $0 botname command"
|
||||
|
@ -7,7 +7,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
|
||||
SHELL=/bin/sh
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# 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.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# 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.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
@ -1,7 +1,7 @@
|
||||
# file: botacl
|
||||
# a user not listed here, will return false from 'user_is_allowed'
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
# Format:
|
||||
# user:ressource:chat
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# to show how you can customize bashbot by only editing mycommands.sh
|
||||
# NOTE: this is not tested, simply copied from original source and reworked!
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-2-gc0a633f
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
# source from commands.sh to use the aliases
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-2-gc0a633f
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# 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.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-2-gc0a633f
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# source from commands.sh if you want ro use interactive or background jobs
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-5-g6c6b312
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
@ -45,6 +45,7 @@ user_is_admin() {
|
||||
[ "$1" = "$2" ] && return 0
|
||||
local me; me="$(get_chat_member_status "$1" "$2")"
|
||||
if [ "${me}" = "creator" ] || [ "${me}" = "administrator" ]; then return 0; fi
|
||||
user_is_botadmin "$2" && return 0
|
||||
return 1
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-13-g52bde30
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
# source from commands.sh to use jsonDB functions
|
||||
#
|
||||
@ -108,14 +108,13 @@ if _exists flock; then
|
||||
# $2 filename (must exist!), must be relative to BASHBOT_ETC, and not contain '..'
|
||||
jssh_deleteKeyDB() {
|
||||
[[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3
|
||||
local DB; DB="$(jssh_checkDB "$2")"
|
||||
declare -A oldARR
|
||||
# start atomic delete here, exclusive max wait 10s
|
||||
{ flock -e -w 10 200
|
||||
Json2Array "oldARR" <"${DB}"
|
||||
if [[ -v "oldAR[$1]" ]] ; then
|
||||
unset oldARR["$1"]
|
||||
Array2Json "oldARR" >"${DB}"
|
||||
fi
|
||||
unset oldARR["$1"]
|
||||
Array2Json "oldARR" >"${DB}"
|
||||
} 200>"${DB}${BASHBOT_LOCKNAME}"
|
||||
}
|
||||
|
||||
@ -238,11 +237,10 @@ jssh_insertDB_async() {
|
||||
|
||||
jssh_deleteKeyDB_async() {
|
||||
[[ "$1" =~ ^[-a-zA-Z0-9,._]+$ ]] || return 3
|
||||
local DB; DB="$(jssh_checkDB "$2")"
|
||||
declare -A oldARR
|
||||
jssh_readDB_async "oldARR" "$2" || return "$?"
|
||||
if [[ -v "oldAR[$1]" ]] ; then
|
||||
unset oldARR["$1"]
|
||||
jssh_writeDB_async "oldARR" "$2"
|
||||
fi
|
||||
unset oldARR["$1"]
|
||||
jssh_writeDB_async "oldARR" "$2"
|
||||
}
|
||||
|
||||
|
@ -5,7 +5,7 @@
|
||||
# This file is public domain in the USA and all free countries.
|
||||
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-8-g284172f
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# source once magic, function named like file
|
||||
eval "$(basename "${BASH_SOURCE[0]}")(){ :; }"
|
||||
|
@ -8,7 +8,7 @@
|
||||
# #### if you start to develop your own bot, use the clean version of this file:
|
||||
# #### mycommands.clean
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-7-g64efe96
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
|
||||
# uncomment the following lines to overwrite info and help messages
|
||||
@ -32,6 +32,9 @@ export FILE_REGEX="${BASHBOT_ETC}/.*"
|
||||
# set to "yes" and give your bot admin privilegs to remove service messaes from groups
|
||||
export SILENCER="no"
|
||||
|
||||
# messages for admin only commands
|
||||
NOTADMIN="Sorry, this command is allowed for admin or owner only"
|
||||
NOTBOTADMIN="Sorry, this command is allowed for bot owner only"
|
||||
|
||||
if [ "$1" = "startbot" ];then
|
||||
###################
|
||||
@ -63,6 +66,25 @@ else
|
||||
fi
|
||||
fi
|
||||
|
||||
# pre-check admin only commands
|
||||
case "${MESSAGE}" in
|
||||
# must be private, group admin, or botadmin
|
||||
'/run_'*|'stop_'*)
|
||||
send_action "${CHAT[ID]}" "typing"
|
||||
if ! user_is_admin "${CHAT[ID]}" "${USER[ID]}" ; then
|
||||
send_normal_message "${CHAT[ID]}" "${NOTADMIN}"; return 1
|
||||
fi
|
||||
# ok, now lets process the real command
|
||||
;;
|
||||
# must be botadmin
|
||||
'/echo'*)
|
||||
send_action "${CHAT[ID]}" "typing"
|
||||
if ! user_is_botadmin "${USER[ID]}" ; then
|
||||
send_markdown_message "${CHAT[ID]}" "*${NOTBOTADMIN}*"; return 1
|
||||
fi
|
||||
;;
|
||||
esac
|
||||
|
||||
case "${MESSAGE}" in
|
||||
##################
|
||||
# example commands, replace thm by your own
|
||||
|
@ -4,7 +4,7 @@
|
||||
# files: mycommands.sh.clean
|
||||
# copy to mycommands.sh and add all your commands and functions here ...
|
||||
#
|
||||
#### $$VERSION$$ v0.94-pre-7-g64efe96
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
#
|
||||
|
||||
##########
|
||||
|
@ -2,7 +2,7 @@
|
||||
#
|
||||
# ADD a new test skeleton to test dir, but does not activate test
|
||||
#
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# magic to ensure that we're always inside the root of our application,
|
||||
# no matter from which directory we'll run script
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-pre-4-gd28f975
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# common variables
|
||||
export TESTME DIRME TESTDIR LOGFILE REFDIR TESTNAME
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
../dev/hooks/pre-commit.sh
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# file: b-example-test.sh
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-pre-4-gd28f975
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-pre-10-g23a3d4b
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-pre-10-g23a3d4b
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env bash
|
||||
#### $$VERSION$$ v0.94-dev3-0-geef955a
|
||||
#### $$VERSION$$ V0.94-0-gbdb50c8
|
||||
|
||||
# include common functions and definitions
|
||||
# shellcheck source=test/ALL-tests.inc.sh
|
||||
|
Loading…
Reference in New Issue
Block a user