From 43372f527835e42a37a48ac4dd772e55f0c7752d Mon Sep 17 00:00:00 2001 From: "Kay Marquardt (Gnadelwartz)" Date: Sat, 25 May 2019 13:55:11 +0200 Subject: [PATCH] adjust documentation to command overwrite --- doc/0_install.md | 8 ++++---- doc/2_usage.md | 9 ++++----- doc/5_practice.md | 41 ++++++++++++++++++++--------------------- 3 files changed, 28 insertions(+), 30 deletions(-) diff --git a/doc/0_install.md b/doc/0_install.md index 1a80084..1f3abf0 100644 --- a/doc/0_install.md +++ b/doc/0_install.md @@ -7,9 +7,10 @@ * /usr/local if you want to run as service 2. [Download latest release zip from github](https://github.com/topkecleon/telegram-bot-bash/releases) and extract all files. 3. Change into the directory ```telegram-bot-bash``` -4. Create default commands with ```cp commands.sh.dist commands.sh; cp mycommands.sh.dist mycommands.sh``` +4. Acticate the bot example commands ``cp mycommands.sh.dist mycommands.sh``` 5. Run ```./bashbot.sh init``` to setup the environment and enter your Bots token given by botfather. +Edit 'mycommands.sh to your needs. 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)** @@ -38,8 +39,7 @@ As an alternative to download the zip files, you can clone the github repository 4. Extract all files to your existing bashbot dir 5. Run ```sudo ./bashbot.sh init``` to setup your environment after the update -If you modified 'commands.sh' re apply all changes to the new 'commands.sh'. To avoid this all your modifications -must be done in 'mycommands.sh' only. +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. @@ -87,5 +87,5 @@ The old format is supported for backward compatibility, but may fail for corner #### [Next Create Bot](1_firstbot.md) -#### $$VERSION$$ v0.80-18-g6b88656 +#### $$VERSION$$ v0.80-24-g68bee46 diff --git a/doc/2_usage.md b/doc/2_usage.md index 33632e7..47acd26 100644 --- a/doc/2_usage.md +++ b/doc/2_usage.md @@ -1,12 +1,11 @@ #### [Home](../README.md) ## Gettting Started -The Bots standard commands are in ```commands.sh``` file. You must not add your commands to 'commands.sh', instead place them in ```mycommands.sh```, there you also find examples how to process messages and send out text. See [Best practices](5_practice.md) for more information. +The Bots standard commands are in ```commands.sh``` file. Do not edit 'commands.sh', instead add your commands and functions to ```mycommands.sh```. In 'mycommands.sh.dist' you will find examples how add your own commands and overwrtie existing ones. See [Best practices](5_practice.md) for more information. -Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. -To stop the Bot run ```./bashbot.sh kill``` +Once you're done with editing 'mycommands.sh' start the Bot with ```./bashbot.sh start```. To stop the Bot run ```./bashbot.sh kill``` -If some thing doesn't work as it should, you can debug with ```./bashbot.sh startbot DEBUG``` where DEBUG can be 'debug', 'xdebug' or 'xdebugx'. +If something doesn't work as expected, you can debug with ```./bashbot.sh startbot DEBUG``` where DEBUG can be 'debug', 'xdebug' or 'xdebugx'. See [Bashbot Development](7_develop.md) for more information. To use the functions provided in this script in other scripts simply source bashbot: ```source bashbot.sh source```. see [Expert Use](8_expert.md#Expert-use) @@ -215,5 +214,5 @@ send_action "${CHAT[ID]}" "action" #### [Prev Create Bot](1_firstbot.md) #### [Next Advanced Usage](3_advanced.md) -#### $$VERSION$$ v0.80-21-gf019ab1 +#### $$VERSION$$ v0.80-24-g68bee46 diff --git a/doc/5_practice.md b/doc/5_practice.md index 786b052..15f22b9 100644 --- a/doc/5_practice.md +++ b/doc/5_practice.md @@ -35,34 +35,33 @@ mycommands() { } ``` -### Reuse or disable global commands +### Overwrite, extend and disable global commands -If you want to disable or reuse a global bashbot command comment it out in 'commands.sh' by placing a '#' in front of -every line from ```'/command')``` to ```;;```. +You can overwrite a global bashbot command by placing the same commands in ```mycommands.sh``` and add ```return 1``` +ad the end of your command, see '/kickme' below. + +To disable a global bashbot command place create a command simply containing 'return 1', see '/leave' below. + +In case you want to add some processing to the global bashbot command add ```return 0```, then both command will be executed. **Learn more about [Bot commands](https://core.telegram.org/bots#commands).** -**Note: Never disable the catchall command ```*)``` in 'commands.sh'!!** ```bash # file: commands.sh case "$MESSAGE" in - ################################################ - # GLOBAL commands start here, edit messages only - - #'/start'*) - # send_action "${CHAT[ID]}" "typing" - # _is_botadmin && _markdown_message "You are *BOTADMIN*." - # if _is_allowed "start" ; then - # _markdown_message "${bot_help}" - # else - # _message "You are not allowed to start Bot." - # fi - # ;; - - *) # forward other messages to optional dispatcher - _is_function send_interactive && send_interactive "${CHAT[ID]}" "${MESSAGE}" - _is_function mycommands && mycommands + ########## + # command overwrite examples + 'info'*) # output date in front of regular info + send_normal_message "${CHAT[ID]}" "$(date)" + return 0 + ;; + '/kickme'*) # this will replace the /kickme command + send_markdown_mesage "${CHAT[ID]}" "*This bot will not kick you!*" + return 1 + ;; + '/leave'*) # disable all commands starting with leave + return 1 ;; esac ``` @@ -153,5 +152,5 @@ The second warning is about an unused variable, this is true because in our exam #### [Prev Best Practice](5_practice.md) #### [Next Functions Reference](6_reference.md) -#### $$VERSION$$ v0.80-18-g6b88656 +#### $$VERSION$$ v0.80-24-g68bee46