commands may have @botname attached

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-04-27 13:36:32 +02:00
parent 293ad088e1
commit 3719c81f9d
10 changed files with 55 additions and 38 deletions

View File

@ -17,7 +17,7 @@ Most complete [UTF-8 support for bashbot](doc/4_expert.md#Bashbot-UTF-8-Support)
Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are availible on www.github.com Bashbot [Documentation](https://github.com/topkecleon/telegram-bot-bash) and [Downloads](https://github.com/topkecleon/telegram-bot-bash/releases) are availible on www.github.com
## Documentation ## Documentation
* [Bots: Introduction for developers] (https://core.telegram.org/bots) * [Bots: Introduction for developers](https://core.telegram.org/bots)
* [The one to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot) * [The one to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
* [Bot commands](https://core.telegram.org/bots#commands) * [Bot commands](https://core.telegram.org/bots#commands)
* [Install Bashbot](doc/0_install.md) * [Install Bashbot](doc/0_install.md)
@ -79,4 +79,4 @@ Bashbot is not more (in)secure as any other Bot written in any other language, w
If you feel that there's something missing or if you found a bug, feel free to submit a pull request! If you feel that there's something missing or if you found a bug, feel free to submit a pull request!
#### $$VERSION$$ v0.70-pre1-1-gbd4a116 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -27,7 +27,7 @@ are availible on www.github.com
Documentation Documentation
~~~~~~~~~~~~~ ~~~~~~~~~~~~~
* [Bots: Introduction for developers] (https://core.telegram.org/bots) * https://core.telegram.org/bots[Bots: Introduction for developers]
** https://core.telegram.org/bots#3-how-do-i-create-a-bot[The one to ** https://core.telegram.org/bots#3-how-do-i-create-a-bot[The one to
rule them all] rule them all]
** https://core.telegram.org/bots#commands[Bot commands] ** https://core.telegram.org/bots#commands[Bot commands]
@ -127,5 +127,5 @@ That's it!
If you feel that there's something missing or if you found a bug, feel If you feel that there's something missing or if you found a bug, feel
free to submit a pull request! free to submit a pull request!
latexmath:[\[VERSION\]] v0.70-pre1-1-gbd4a116 latexmath:[\[VERSION\]] v0.70-pre1-2-g293ad08
+++++++++++++++++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++++++++

View File

@ -5,7 +5,7 @@
# This file is public domain in the USA and all free countries. # This file is public domain in the USA and all free countries.
# Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying) # Elsewhere, consider it to be WTFPLv2. (wtfpl.net/txt/copying)
# #
#### $$VERSION$$ v0.70-pre1-0-g490c472 #### $$VERSION$$ v0.70-pre1-2-g293ad08
# #
# shellcheck disable=SC2154 # shellcheck disable=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -31,6 +31,7 @@ It currently can send, recieve and forward messages, custom keyboards, photos, a
# to change the default help messages overwrite in mycommands.sh # to change the default help messages overwrite in mycommands.sh
bashbot_help='*Available commands*: bashbot_help='*Available commands*:
*• /start*: _Start bot and get this message_. *• /start*: _Start bot and get this message_.
*• /help*: _Get this message_.
*• /info*: _Get shorter info message about this bot_. *• /info*: _Get shorter info message about this bot_.
*• /question*: _Start interactive chat_. *• /question*: _Start interactive chat_.
*• /cancel*: _Cancel any currently running interactive chats_. *• /cancel*: _Cancel any currently running interactive chats_.
@ -97,11 +98,11 @@ else
fi fi
case "$MESSAGE" in case "$MESSAGE" in
################################################ ################################################
# DEFAULT commands start here, edit messages only # GLOBAL commands start here, edit messages only
'/info') '/info'*)
_markdown_message "${bashbot_info}" _markdown_message "${bashbot_info}"
;; ;;
'/start') '/start'*)
send_action "${CHAT[ID]}" "typing" send_action "${CHAT[ID]}" "typing"
_is_botadmin && _markdown_message "You are *BOTADMIN*." _is_botadmin && _markdown_message "You are *BOTADMIN*."
if _is_allowed "start" ; then if _is_allowed "start" ; then
@ -111,19 +112,22 @@ else
fi fi
;; ;;
'/leavechat') # bot leave chat if user is admin in chat '/help'*)
_markdown_message "${bot_help}"
;;
'/leavechat'*) # bot leave chat if user is admin in chat
if _is_admin ; then if _is_admin ; then
_markdown_message "*LEAVING CHAT...*" _markdown_message "*LEAVING CHAT...*"
_leave _leave
fi fi
;; ;;
'/kickme') '/kickme'*)
_kick_user "${USER[ID]}" _kick_user "${USER[ID]}"
_unban_user "${USER[ID]}" _unban_user "${USER[ID]}"
;; ;;
'/cancel') '/cancel'*)
checkprog checkprog
if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi if [ "$res" -eq 0 ] ; then killproc && _message "Command canceled.";else _message "No command is currently running.";fi
;; ;;

View File

@ -12,7 +12,7 @@
Now your Bot is ready to start ... Now your Bot is ready to start ...
If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) **If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots)**
### Install from Github ### Install from Github
@ -63,5 +63,5 @@ The old format is supported for backward compatibility, but may fail for corner
#### [Next Create Bot](1_firstbot.md) #### [Next Create Bot](1_firstbot.md)
#### $$VERSION$$ v0.70-pre1-1-gbd4a116 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -1,8 +1,6 @@
#### [Home](../README.md) #### [Home](../README.md)
## Create a Telegram Bot with botfather ## Create a Telegram Bot with botfather
[BotFather is the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. **[BotFather is the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones.** [Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token)
[Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token)
### Creating a new Bot ### Creating a new Bot
@ -67,5 +65,5 @@ group. This step is up to you actually.
#### [Prev Installation](0_install.md) #### [Prev Installation](0_install.md)
#### [Next Getting started](2_usage.md) #### [Next Getting started](2_usage.md)
#### $$VERSION$$ v0.70-pre1-1-gbd4a116 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -37,7 +37,7 @@ To send a broadcast to all of users that ever used the bot run the following com
## Recieve data ## Recieve data
Evertime a Message is recieved, you can read incoming data using the following variables: Evertime a Message is recieved, you can read incoming data using the following variables:
* ```${MESSAGE}```: Current incoming messages * ```${MESSAGE}```: Current message
* ```${MESSAGE[ID]}```: ID of current message * ```${MESSAGE[ID]}```: ID of current message
* ```$CAPTION```: Captions * ```$CAPTION```: Captions
* ```$REPLYTO```: Original message wich was replied to * ```$REPLYTO```: Original message wich was replied to
@ -66,7 +66,7 @@ Evertime a Message is recieved, you can read incoming data using the following v
* ```${FORWARD[FIRST_NAME]}```: Original user's first name * ```${FORWARD[FIRST_NAME]}```: Original user's first name
* ```${FORWARD[LAST_NAME]}```: Original user's' last name * ```${FORWARD[LAST_NAME]}```: Original user's' last name
* ```${FORWARD[USERNAME]}```: Original user's username * ```${FORWARD[USERNAME]}```: Original user's username
* ```$URLS```: This array contains documents, audio files, stickers, voice recordings and stickers stored in the form of URLs. * ```$URLS```: This array contains documents, audio files, voice recordings and stickers as URL.
* ```${URLS[AUDIO]}```: Audio files * ```${URLS[AUDIO]}```: Audio files
* ```${URLS[VIDEO]}```: Videos * ```${URLS[VIDEO]}```: Videos
* ```${URLS[PHOTO]}```: Photos (maximum quality) * ```${URLS[PHOTO]}```: Photos (maximum quality)
@ -136,7 +136,7 @@ This function also allows a third parameter that disables additional function pa
```bash ```bash
send_message "${CHAT[ID]}" "lol" "safe" send_message "${CHAT[ID]}" "lol" "safe"
``` ```
More examples boutsend_message strings can be found in [Advanced Usage](3_advanced.md#Interactive-Chats) **See also [Interactive chats](3_advanced.md#Interactive-Chats)**
#### Send files, locations, keyboards. #### Send files, locations, keyboards.
@ -162,10 +162,10 @@ Allowed values: typing for text messages, upload_photo for photos, record_video
```bash ```bash
send_action "${CHAT[ID]}" "action" send_action "${CHAT[ID]}" "action"
``` ```
See also [Bashbot function reference](6_reference.md) **See also [Bashbot function reference](6_reference.md#Interactive_Chats)**
#### [Prev Create Bot](1_firstbot.md) #### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md) #### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.70-pre1-1-gbd4a116 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -47,7 +47,9 @@ In addition you can check individual capabilities of users as you must define in
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.
```bash ```bash
case "$MESSAGE" in case "$MESSAGE" in
'/start') ################################################
# GLOBAL commands start here, only edit messages
'/start'*)
user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*." user_is_botadmin "${USER[ID]}" && send_markdown_message "${CHAT[ID]}" "You are *BOTADMIN*."
if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then if user_is_allowed "${USER[ID]}" "start" "${CHAT[ID]}" ; then
bot_help "${CHAT[ID]}" bot_help "${CHAT[ID]}"
@ -56,7 +58,7 @@ You must use the function ```user_is_allowed``` to check if a user has the capab
;; ;;
esac esac
``` ```
See also [Bashbot User Access Control functions](6_functions.md#User_Access_Control) **See also [Bashbot User Access Control functions](6_functions.md#User_Access_Control)**
### Interactive Chats ### Interactive Chats
To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable To create interactive chats, write *(or edit the 'exmaples/question.sh' script)* a bash *(or C or python)* script, make it executable
@ -167,5 +169,5 @@ answer_inline_query "$iQUERY_ID" "cached_sticker" "identifier for the sticker"
#### [Prev Getting started](2_usage.md) #### [Prev Getting started](2_usage.md)
#### [Next Expert Use](4_expert.md) #### [Next Expert Use](4_expert.md)
#### $$VERSION$$ v0.70-pre1-1-gbd4a116 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -1,6 +1,14 @@
#### [Home](../README.md) #### [Home](../README.md)
## Best Practices ## Best Practices
### New to bot development?
If you are new to Bot development read [Bots: An introduction for developers](https://core.telegram.org/bots) and consult [Telegram Bot API Documentaion](https://core.telegram.org/bots/api/).
In addition you should know about [BotFatheri, the one bot to rule them all](https://core.telegram.org/bots#3-how-do-i-create-a-bot). It will help you create new bots and change settings for existing ones. [Commands known by Botfather](https://core.telegram.org/bots#generating-an-authorization-token)
If you dont't have a gibtup account, it may time to [sepup a free account now](https://github.com/pricing)
### Add commands to mycommands.sh only ### Add commands to mycommands.sh only
To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function: To ease updates never change ```bashbot.sh```, instead your commands and functions must go to ```mycommands.sh``` . Insert your Bot commands in the ```case ... esac``` block of the 'mycommands()' function:
```bash ```bash
@ -15,6 +23,7 @@ To ease updates never change ```bashbot.sh```, instead your commands and functio
/echo message - _echo the given messsage_ /echo message - _echo the given messsage_
' '
# NOTE: command can have @botname attached, you must add * in case tests...
mycommands() { mycommands() {
case "$MESSAGE" in case "$MESSAGE" in
@ -26,19 +35,22 @@ mycommands() {
} }
``` ```
### Reuse or disable standard commands ### Reuse or disable global commands
If you want to disable or reuse a standard bashbot command comment it out in 'commands.sh' by placing a '#' in front of
If you want to disable or reuse a global bashbot command comment it out in 'commands.sh' by placing a '#' in front of
every line from ```'/command')``` to ```;;```. every line from ```'/command')``` to ```;;```.
**Learn more about [Bot (global) commands](https://core.telegram.org/bots#commands).**
**Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** **Note: Never disable the catchall command ```*)``` in 'commands.sh'!!**
```bash ```bash
# file: commands.sh # file: commands.sh
case "$MESSAGE" in case "$MESSAGE" in
################################################ ################################################
# DEFAULT commands start here, edit messages only # GLOBAL commands start here, edit messages only
#'/start') #'/start'*)
# send_action "${CHAT[ID]}" "typing" # send_action "${CHAT[ID]}" "typing"
# _is_botadmin && _markdown_message "You are *BOTADMIN*." # _is_botadmin && _markdown_message "You are *BOTADMIN*."
# if _is_allowed "start" ; then # if _is_allowed "start" ; then
@ -66,7 +78,7 @@ If a command need more than 2-3 lines of code, you should use a function to sepe
mycommands() { mycommands() {
case "$MESSAGE" in case "$MESSAGE" in
'/process') # logic for /process is done in process_message '/process'*) # logic for /process is done in process_message
result="$(process_message "$MESSAGE")" result="$(process_message "$MESSAGE")"
send_normal_message "${CHAT[ID]}" "$result" send_normal_message "${CHAT[ID]}" "$result"
;; ;;
@ -141,5 +153,5 @@ The second warning is about an unused variable, this is true because in our exam
#### [Prev Best Practice](5_practice.md) #### [Prev Best Practice](5_practice.md)
#### [Next Functions Reference](6_reference.md) #### [Next Functions Reference](6_reference.md)
#### $$VERSION$$ v0.70-pre1-0-g490c472 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -194,7 +194,7 @@ if _is_admin ; then
fi fi
``` ```
See also [kicki Chat Member](https://core.telegram.org/bots/api/#kickchatmember) See also [kick Chat Member](https://core.telegram.org/bots/api/#kickchatmember)
---- ----
@ -234,7 +234,7 @@ if _is_admin ; then
fi fi
``` ```
See also [ChatMember](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](4_advanced.md) Bahsbot supports User Access Control, see [Advanced Usage](4_advanced.md)
@ -488,5 +488,5 @@ Send Input from Telegram to waiting Interactive Chat.
#### [Prev Best Practice](5_practice.md) #### [Prev Best Practice](5_practice.md)
#### [Next Notes for Developers](7_develop.md) #### [Next Notes for Developers](7_develop.md)
#### $$VERSION$$ v0.70-pre1-1-gbd4a116 #### $$VERSION$$ v0.70-pre1-2-g293ad08

View File

@ -2,7 +2,7 @@
# files: mycommands.sh.dist # files: mycommands.sh.dist
# copy to mycommands.sh and add all your commands and functions here ... # copy to mycommands.sh and add all your commands and functions here ...
# #
#### $$VERSION$$ v0.70-pre1-0-g490c472 #### $$VERSION$$ v0.70-pre1-2-g293ad08
# #
# shellcheck disable=SC2154 # shellcheck disable=SC2154
# shellcheck disable=SC2034 # shellcheck disable=SC2034
@ -16,13 +16,14 @@
# your additional bahsbot commands # your additional bahsbot commands
# NOTE: command can have @botname attached, you must add * in case tests...
mycommands() { mycommands() {
case "$MESSAGE" in case "$MESSAGE" in
'/echo'*) # example echo command '/echo'*) # example echo command
send_normal_message "${CHAT[ID]}" "$MESSAGE" send_normal_message "${CHAT[ID]}" "$MESSAGE"
;; ;;
'/question') # start interactive questions '/question'*) # start interactive questions
checkproc checkproc
if [ "$res" -gt 0 ] ; then if [ "$res" -gt 0 ] ; then
startproc "example/question" startproc "example/question"
@ -31,7 +32,7 @@ mycommands() {
fi fi
;; ;;
'/run-notify') # start notify background job '/run-notify'*) # start notify background job
myback="notify"; checkback "$myback" myback="notify"; checkback "$myback"
if [ "$res" -gt 0 ] ; then if [ "$res" -gt 0 ] ; then
background "example/notify 60" "$myback" # notify every 60 seconds background "example/notify 60" "$myback" # notify every 60 seconds
@ -39,7 +40,7 @@ mycommands() {
send_normal_message "${CHAT[ID]}" "Background command $myback already running ..." send_normal_message "${CHAT[ID]}" "Background command $myback already running ..."
fi fi
;; ;;
'/stop-notify') # kill notify background job '/stop-notify'*) # kill notify background job
myback="notify"; checkback "$myback" myback="notify"; checkback "$myback"
if [ "$res" -eq 0 ] ; then if [ "$res" -eq 0 ] ; then
killback "$myback" killback "$myback"