mirror of
https://github.com/octoleo/telegram-bot-bash.git
synced 2024-11-25 16:57:33 +00:00
Bashbot Version 0.52 - user acls added
This commit is contained in:
parent
db7b19fbc4
commit
1144a1ff69
@ -8,7 +8,7 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M (@gnadel
|
||||
|
||||
Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1.
|
||||
|
||||
[Download from github](https://github.com/topkecleon/telegram-bot-bash/releases)
|
||||
[Download latest release from github](https://github.com/topkecleon/telegram-bot-bash/releases)
|
||||
|
||||
Released to the public domain wherever applicable.
|
||||
Elsewhere, consider it released under the [WTFPLv2](http://www.wtfpl.net/txt/copying/).
|
||||
@ -25,7 +25,8 @@ git clone --recursive https://github.com/topkecleon/telegram-bot-bash
|
||||
```
|
||||
3. Change to directory ```telegram-bot.bash```, run ```./bashbot.sh init``` and follow the instructions. At this stage you are asked for your Bots token given by botfather.
|
||||
|
||||
|
||||
## Update bashbot
|
||||
[Download latest update zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and copy all files to bashbot dir. run ```sudo ./bashbot.sh init```.
|
||||
|
||||
## Getting started
|
||||
- [Create your first telegram bot](doc/1_firstbot.md)
|
||||
@ -35,6 +36,7 @@ git clone --recursive https://github.com/topkecleon/telegram-bot-bash
|
||||
- Send Messages
|
||||
- Send files, location etc.
|
||||
- [Advanced Features](doc/3_advanced.md)
|
||||
- Access Control
|
||||
- Interactive Chats
|
||||
- Background Jobs
|
||||
- Inline queries
|
||||
@ -73,4 +75,4 @@ No - its not less (in)secure as any other Bot written in any other language. But
|
||||
|
||||
If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
|
||||
|
||||
#### $$VERSION$$ v0.6-dev2-8-g649fe44
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
16
README.txt
16
README.txt
@ -11,8 +11,8 @@ Written by Drew (@topkecleon), Daniil Gentili (@danogentili), and Kay M
|
||||
|
||||
Contributions by JuanPotato, BigNerd95, TiagoDanin, and iicc1.
|
||||
|
||||
https://github.com/topkecleon/telegram-bot-bash/releases[Download from
|
||||
github]
|
||||
https://github.com/topkecleon/telegram-bot-bash/releases[Download latest
|
||||
release from github]
|
||||
|
||||
Released to the public domain wherever applicable. Elsewhere, consider
|
||||
it released under the http://www.wtfpl.net/txt/copying/[WTFPLv2].
|
||||
@ -34,6 +34,13 @@ git clone --recursive https://github.com/topkecleon/telegram-bot-bash
|
||||
follow the instructions. At this stage you are asked for your Bots token
|
||||
given by botfather.
|
||||
|
||||
Update bashbot
|
||||
~~~~~~~~~~~~~~
|
||||
|
||||
https://github.com/topkecleon/telegram-bot-bash/releases[Download latest
|
||||
update zip from github] and copy all files to bashbot dir. run
|
||||
`sudo ./bashbot.sh init`.
|
||||
|
||||
Getting started
|
||||
~~~~~~~~~~~~~~~
|
||||
|
||||
@ -44,6 +51,7 @@ Getting started
|
||||
* Send Messages
|
||||
* Send files, location etc.
|
||||
* link:doc/3_advanced.md[Advanced Features]
|
||||
* Access Control
|
||||
* Interactive Chats
|
||||
* Background Jobs
|
||||
* Inline queries
|
||||
@ -111,5 +119,5 @@ That's it!
|
||||
If you feel that there's something missing or if you found a bug, feel
|
||||
free to submit a pull request!
|
||||
|
||||
latexmath:[\[VERSION\]] v0.6-dev2-8-g649fe44
|
||||
++++++++++++++++++++++++++++++++++++++++++++
|
||||
latexmath:[\[VERSION\]] v0.52-0-gdb7b19f
|
||||
++++++++++++++++++++++++++++++++++++++++
|
||||
|
@ -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.6-dev2-8-g649fe44
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
|
||||
SHELL=/bin/sh
|
||||
|
@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
# description: Start or stop telegram-bash-bot
|
||||
#
|
||||
#### $$VERSION$$ v0.6-dev2-13-g88cf2d9
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
# shellcheck disable=SC2009
|
||||
# shellcheck disable=SC2181
|
||||
|
||||
|
20
bashbot.sh
20
bashbot.sh
@ -10,7 +10,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.6-dev2-14-g56cb1bb
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
#
|
||||
# Exit Codes:
|
||||
# - 0 sucess (hopefully)
|
||||
@ -78,6 +78,12 @@ if [ ! -f "${BOTADMIN}" ]; then
|
||||
fi
|
||||
fi
|
||||
|
||||
BOTACL="./botacl"
|
||||
if [ ! -f "${BOTACL}" ]; then
|
||||
echo -e "${ORANGE}Create empty ${BOTACL} file.${NC}"
|
||||
touch "${BOTACL}"
|
||||
fi
|
||||
|
||||
TMPDIR="./tmp-bot-bash"
|
||||
if [ ! -d "${TMPDIR}" ]; then
|
||||
mkdir "${TMPDIR}"
|
||||
@ -264,6 +270,16 @@ user_is_botadmin() {
|
||||
return 1
|
||||
}
|
||||
|
||||
user_is_allowed() {
|
||||
local acl; acl="$1"
|
||||
[ "$1" == "" ] && return 1
|
||||
grep -F -xq "${acl}:*:*" <"${BOTACL}" && return 0
|
||||
[ "$2" != "" ] && acl="${acl}:$2"
|
||||
grep -F -xq "${acl}:*" <"${BOTACL}" && return 0
|
||||
[ "$3" != "" ] && acl="${acl}:$3"
|
||||
grep -F -xq "${acl}" <"${BOTACL}"
|
||||
}
|
||||
|
||||
answer_inline_query() {
|
||||
case "$2" in
|
||||
"article")
|
||||
@ -618,7 +634,7 @@ case "$1" in
|
||||
chmod 711 .
|
||||
chmod -R a-w ./*
|
||||
chmod -R u+w "${COUNT}" "${TMPDIR}" "${BOTADMIN}" ./*.log 2>/dev/null
|
||||
chmod -R o-r,o-w "${COUNT}" "${TMPDIR}" "${TOKEN}" "${BOTADMIN}" 2>/dev/null
|
||||
chmod -R o-r,o-w "${COUNT}" "${TMPDIR}" "${TOKEN}" "${BOTADMIN}" "${BOTACL}" 2>/dev/null
|
||||
ls -la
|
||||
exit
|
||||
fi
|
||||
|
@ -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.6-dev2-14-g56cb1bb
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
#
|
||||
# shellcheck disable=SC2154
|
||||
# shellcheck disable=SC2034
|
||||
@ -119,7 +119,10 @@ else
|
||||
'/start')
|
||||
send_action "${CHAT[ID]}" "typing"
|
||||
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
||||
bashbot_help "${CHAT[ID]}"
|
||||
if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
|
||||
bot_help "${CHAT[ID]}"
|
||||
else
|
||||
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
|
||||
;;
|
||||
|
||||
'/leavechat') # bot leave chat if user is admin in chat
|
||||
|
@ -70,5 +70,5 @@ git clone --recursive https://github.com/topkecleon/telegram-bot-bash
|
||||
```
|
||||
3. Change to directory ```telegram-bot.bash```, run ```./bashbot.sh init``` and follow the instructions. At this stage you are asked for your Bots token given by botfather.
|
||||
|
||||
#### $$VERSION$$ v0.6-dev2-10-gdb64978
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
|
@ -147,6 +147,6 @@ Allowed values: typing for text messages, upload_photo for photos, record_video
|
||||
send_action "${CHAT[ID]}" "action"
|
||||
```
|
||||
|
||||
#### $$VERSION$$ v0.6-dev2-10-gdb64978
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
|
||||
|
@ -1,5 +1,61 @@
|
||||
|
||||
## Advanced Features
|
||||
### Access control
|
||||
Bashbot offers functions to check if a has Telegram capabilities like chat admin or chat creator:
|
||||
```bash
|
||||
# return true if user is admin/owner of the bot
|
||||
# -> botadmin is stored in file './botadmin'
|
||||
user_is_botadmin "user"
|
||||
|
||||
# return true if user is creator or admin of a chat
|
||||
user_is_admin "chat" "user"
|
||||
|
||||
# return true if user is creator of a chat or it's a one to one chat
|
||||
user_is_creator "chat" "user"
|
||||
|
||||
# examples:
|
||||
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
||||
|
||||
user_is_admin "${CHAT[ID]}" "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *CHATADMIN*."
|
||||
|
||||
```
|
||||
In addtion you can configure individual capabilities for users in the file ```./botacl```:
|
||||
```bash
|
||||
# botacl
|
||||
# if a user is not listed here, function 'user_is_allowed' will always return false
|
||||
#
|
||||
# Format:
|
||||
# user:ressource:chat
|
||||
|
||||
# allow user 123456789 access to all resources in all chats
|
||||
123456789:*:*
|
||||
|
||||
# allow user 12131415 to start bot in all chats
|
||||
12131415:start:*
|
||||
|
||||
# allow user 987654321 only to start bot in chat 98979695
|
||||
987654321:start:98979695
|
||||
|
||||
# * are only allowed on the right hand side and not for user!
|
||||
# the following exaples are NOT valid!
|
||||
*:*:*
|
||||
*:start:*
|
||||
*:*:98979695
|
||||
```
|
||||
you have to check yourself if a user is allowed to to something by calling function ```user_is_allowed```.
|
||||
example to check if a user is allowed to start bot:
|
||||
```bash
|
||||
case "$MESSAGE" in
|
||||
'/start')
|
||||
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
|
||||
if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
|
||||
bot_help "${CHAT[ID]}"
|
||||
else
|
||||
send_normal_message "${CHAT[ID]}" "You are not allowed to start Bot."
|
||||
;;
|
||||
esac
|
||||
```
|
||||
|
||||
### Interactive Chats
|
||||
To create interactive chats, write (or edit the question script) a normal bash (or C or python) script, chmod +x it and then change the argument of the startproc function to match the command you usually use to start the script.
|
||||
The text that the script will output will be sent in real time to the user, and all user input will be sent to the script (as long as it's running or until the user kills it with /cancel).
|
||||
@ -97,5 +153,5 @@ To send stickers through an *inline query*:
|
||||
answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
|
||||
```
|
||||
|
||||
#### $$VERSION$$ v0.6-dev2-10-gdb64978
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
|
@ -102,5 +102,5 @@ An example crontab is provided in ```bashbot.cron```.
|
||||
- if you run bashbot as an other user or a system service edit ```bashbot.cron``` to fit your needs and replace username```nobody``` with the username you want to run bashbot. copy the modified file to ```/etc/cron.d/bashbot```
|
||||
|
||||
|
||||
#### $$VERSION$$ v0.6-dev2-10-gdb64978
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
|
@ -111,5 +111,5 @@ In bashbot.sh line 490:
|
||||
```
|
||||
As you can see there are only two warnings in bashbots scripts. The first is a hint you may use shell substitions instead of sed, but this is only possible for simple cases. The second warning is about an unused variable, this is true because in our examples CONTACT is not used but assigned in case you want to use it :-)
|
||||
|
||||
#### $$VERSION$$ v0.6-dev2-10-gdb64978
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
|
2
notify
2
notify
@ -2,7 +2,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.6-dev2-8-g649fe44
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
2
question
2
question
@ -3,7 +3,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.6-dev2-8-g649fe44
|
||||
#### $$VERSION$$ v0.52-0-gdb7b19f
|
||||
|
||||
# adjust your language setting here
|
||||
# https://github.com/topkecleon/telegram-bot-bash#setting-up-your-environment
|
||||
|
Loading…
Reference in New Issue
Block a user