some doc updates plus working version of antiFlood.sh

This commit is contained in:
Kay Marquardt (Gnadelwartz) 2019-05-30 15:08:07 +02:00
parent 1c5594a5c2
commit b240edee41
7 changed files with 70 additions and 38 deletions

View File

@ -60,11 +60,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
<p>Bashbot <a href="https://github.com/topkecleon/telegram-bot-bash">Documentation</a> and <a href="https://github.com/topkecleon/telegram-bot-bash/releases">Downloads</a> are availible on www.github.com</p>
<h2 id="documentation">Documentation</h2>
<ul>
<li><a href="https://core.telegram.org/bots">Introdution to Telegram Bots</a>
<ul>
<li><a href="https://core.telegram.org/bots#3-how-do-i-create-a-bot">One Bot to rule them all</a></li>
<li><a href="https://core.telegram.org/bots#commands">Bot commands</a></li>
</ul></li>
<li><a href="https://core.telegram.org/bots">Introdution to Telegram Bots</a></li>
<li><a href="doc/0_install.md">Install Bashbot</a>
<ul>
<li>Install release</li>
@ -72,7 +68,7 @@ code > span.in { color: #60a0b0; font-weight: bold; font-style: italic; } /* Inf
<li>Update Bashbot</li>
<li>Notes on Updates</li>
</ul></li>
<li><a href="doc/1_firstbot.md">Create a new Telegram Bot with botfather</a></li>
<li><a href="doc/1_firstbot.md">Get Bottoken from Botfather</a></li>
<li><a href="doc/2_usage.md">Getting Started</a>
<ul>
<li>Managing your Bot</li>
@ -190,6 +186,6 @@ It features background tasks and interactive chats, and can serve as an interfac
<p><span class="citation">@Gnadelwartz</span></p>
<h2 id="thats-it">Thats it!</h2>
<p>If you feel that theres something missing or if you found a bug, feel free to submit a pull request!</p>
<h4 id="version-v0.90-dev2-19-g5779acc"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.90-dev2-19-g5779acc</h4>
<h4 id="version-v0.90-dev2-23-g2a28e7f"><br /><span class="math display"><em>V</em><em>E</em><em>R</em><em>S</em><em>I</em><em>O</em><em>N</em></span><br /> v0.90-dev2-23-g2a28e7f</h4>
</body>
</html>

View File

@ -179,4 +179,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.90-dev2-19-g5779acc
#### $$VERSION$$ v0.90-dev2-23-g2a28e7f

View File

@ -30,15 +30,12 @@ availible on www.github.com
## Documentation
* [Introdution to Telegram Bots](https://core.telegram.org/bots)
* [One Bot to rule them
all](https://core.telegram.org/bots#3-how-do-i-create-a-bot)
* [Bot commands](https://core.telegram.org/bots#commands)
* [Install Bashbot](doc/0_install.md)
* Install release
* Install from githup
* Update Bashbot
* Notes on Updates
* [Create a new Telegram Bot with botfather](doc/1_firstbot.md)
* [Get Bottoken from Botfather](doc/1_firstbot.md)
* [Getting Started](doc/2_usage.md)
* Managing your Bot
* Recieve data
@ -255,4 +252,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.90-dev2-19-g5779acc
#### $$VERSION$$ v0.90-dev2-23-g2a28e7f

View File

@ -24,54 +24,90 @@
# shellcheck disable=SC2140
# export used events
export BASHBOT_EVENT_TEXT BASHBOT_EVENT_CMD BASHBOT_EVENT_FILE
export BASHBOT_EVENT_TEXT BASHBOT_EVENT_CMD BASHBOT_EVENT_FILE BASHBOT_EVENT_TIMER
# any global variable defined by addons MUST be prefixed by addon name
ANTIFLOOD_ME="antiflood"
ANTIFL_ME="antiflood"
declare -Ax ANTIFLOOD_CHATS ANTIFLOOD_ACTUALS
declare -Ax ANTIFL_CHATS ANTIFL_ACTUALS
ANTIFLOOD_DEFAULT="5" # 5 files per minute
ANTIFLOOD_BAN="5" # 5 minutes
ANTIFL_DEFAULT="5" # 5 files per minute
ANTIFL_BAN="5" # 5 minutes
# initialize after installation or update
if [[ "$1" = "init"* ]]; then
: # nothing
ANTIFL_ADMIN="$(< "${BOTADMIN}")"
fi
# register on startbot
if [[ "$1" = "start"* ]]; then
#load existing chat settings on start
jssh_readDB "ANTIFLOOD_CHATS" "${ADDONDIR:-./addons}/$ANTIFLOOD_ME"
jssh_readDB "ANTIFL_CHATS" "${ADDONDIR:-./addons}/$ANTIFL_ME"
# register to CMD
BASHBOT_EVENT_CMD["${ANTIFLOOD_ME}"]="${ANTIFLOOD_ME}_cmd"
BASHBOT_EVENT_CMD["${ANTIFL_ME}"]="${ANTIFL_ME}_cmd"
# command /antiflood starts addon, $1 floodlevel $2 bantime
antiflood_cmd(){
case "${CMD[0]}" in
# command /antiflood starts detection, $1 floodlevel
"/antifl"*)
ANTIFLOOD_CHATS["${CHAT[ID]}","level"]="${ANTIFLOOD_DEFAULT}"
ANTIFLOOD_CHATS["${CHAT[ID]}","ban"]="${ANTIFLOOD_BAN}"
[[ "${CMD[1]}" =~ ^[0-9]+$ ]] && ANTIFLOOD_CHATS["${CHAT[ID]}","level"]="${CMD[1]}"
[[ "${CMD[2]}" =~ ^[0-9]+$ ]] && ANTIFLOOD_CHATS["${CHAT[ID]}","ban"]="${CMD[2]}"
ANTIFL_CHATS["${CHAT[ID]}","level"]="${ANTIFL_DEFAULT}"
ANTIFL_CHATS["${CHAT[ID]}","ban"]="${ANTIFL_BAN}"
[[ "${CMD[1]}" =~ ^[0-9]+$ ]] && ANTIFL_CHATS["${CHAT[ID]}","level"]="${CMD[1]}"
# antiflood_save &
;;
# command /floodapply starts counter meausares
"/floodap"*)
ANTIFL_CHATS["${CHAT[ID]}","active"]="yes"
;;
esac
}
# register to timer
BASHBOT_EVENT_TIMER["${ANTIFL_ME}","${ANTIFL_BAN}"]="antiflood_timer"
# save settings and reset flood level every BAN Min
antiflood_timer(){
unset ANTIFL_ACTUALS
jssh_writeBD "ANTIFL_CHATS" "${ADDONDIR:-./addons}/$ANTIFL_ME" &
}
# register to inline and command
BASHBOT_EVENT_TEXT["${ANTIFLOOD_ME}"]="${ANTIFLOOD_ME}_multievent"
BASHBOT_EVENT_FILE["${ANTIFLOOD_ME}"]="${ANTIFLOOD_ME}_multievent"
BASHBOT_EVENT_TEXT["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
BASHBOT_EVENT_FILE["${ANTIFL_ME}"]="${ANTIFL_ME}_multievent"
antiflood_multievent(){
# not started
[ "${ANTIFLOOD_CHATS["${CHAT[ID]}","level"]}" = "" ] && return
# count flood messages
[ "$1" = "text" ] && [ "${#MESSAGE[0]}" -lt "5" ] && (( ANTIFLOOD_ACTUALS["${CHAT[ID]}","${USER[ID]}"] += 1 ))
[ "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" = "" ] && return
# check user flood text
if [ "$1" = "text" ]; then
if [ "${#MESSAGE[0]}" -gt "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" ]; then
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]-- ))
# shellcheck disable=SC2154
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]-- ))
else
# shellcheck disable=SC2154
(( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}"]++ ))
fi
fi
# check user flood picture
# shellcheck disable=SC2154
[ "$1" = "file" ] && (( ANTIFLOOD_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"] += 1 ))
# antiflood_check &
[ "$1" = "file" ] && (( ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]++ ))
antiflood_action & # do actions in subshell
}
# check and handle actions
antiflood_action() {
# check flood level of user
if [ "${ANTIFL_ACTUALS["${CHAT[ID]}","${USER[ID]}","file"]}" -gt "${ANTIFL_CHATS["${CHAT[ID]}","level"]}" ]; then
if [ "${ANTIFL_CHATS["${CHAT[ID]}","active"]}" = "yes" ]; then
# remove message
delete_message "${CHAT[ID]}" "${MESSAGE[ID]}"
else
# inform admin
send_markdown_message "${ANTIFL_ADMIN}" "User ${USER[USERNAME]} reached flood level in chat ${CHAT[USERNAME]}!"
fi
fi
}
fi

View File

@ -5,7 +5,7 @@ The Bots standard commands are in the commands dispatcher ```commands.sh```, Do
Once you're done with editing start the Bot with ```./bashbot.sh start```. To stop the Bot run ```./bashbot.sh kill```
If something doesn't work as expected, debug with ```./bashbot.sh startbot DEBUG```, where DEBUG can be 'debug', 'xdebug' or 'xdebugx'.
If something doesn't work as expected, 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)
@ -223,5 +223,5 @@ send_action "${CHAT[ID]}" "action"
#### [Prev Create Bot](1_firstbot.md)
#### [Next Advanced Usage](3_advanced.md)
#### $$VERSION$$ v0.90-dev2-0-gec85636
#### $$VERSION$$ v0.90-dev2-24-g1c5594a

View File

@ -784,5 +784,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.90-dev2-22-g9148dc5
#### $$VERSION$$ v0.90-dev2-23-g2a28e7f

View File

@ -7,7 +7,8 @@ bashbot development is done on github. If you want to provide fixes or new featu
### Debugging Bashbot
In normal mode of operation all bashbot output is discarded.
To get these messages (and more) you can start bashbot in the current shell ```./bashbot.sh startbot```. Now you can see all output or erros from bashbot.
To get these messages (and more) you can start bashbot in the current shell with ```./bashbot.sh startbot &```.
Now you can see all output or erros from bashbot.
In addition you can change the change the level of verbosity by adding a third argument after startbot.
```
"debug" redirects all output to "DEBUG.log", in addtion every update is logged in "MESSAGE.LOG" and "INLINE.log"
@ -17,6 +18,8 @@ In addition you can change the change the level of verbosity by adding a third a
"xdebugterm" same as xdebug but output and errors are sent to terminal
```
To stop bashhbot in debugging mode use ```./bashbot.sh kill``` as ususal.
### Modules and Addons
**Modules** live in ```modules/*.sh``` and are bashbot functions factored out in seperate files, gouped by functionality. Main reason for creating modules was
to keep 'bashbot.sh' small, while extending functionality. In addition not every functionality is needed by a bot, so you can
@ -272,5 +275,5 @@ fi
#### [Prev Function Reference](6_reference.md)
#### $$VERSION$$ v0.90-dev2-22-g9148dc5
#### $$VERSION$$ v0.90-dev2-24-g1c5594a