diff options
author | clsr <clsr@clsr.net> | 2017-03-22 21:07:10 +0100 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-03-22 21:07:10 +0100 |
commit | ff2bc5d0931d4a460d4d74183b6f9dd9394c40a0 (patch) | |
tree | 13dbf5a1395ae4e3dcd458bf114d962b28a8657c /modules/ibip.bash | |
download | mbibot-0.1.0.tar.gz mbibot-0.1.0.zip |
Initial commitv0.1.0
Diffstat (limited to 'modules/ibip.bash')
-rw-r--r-- | modules/ibip.bash | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/modules/ibip.bash b/modules/ibip.bash new file mode 100644 index 0000000..13efd0c --- /dev/null +++ b/modules/ibip.bash @@ -0,0 +1,41 @@ +# modules/ibip.bash +# +# Responds to ``.bots'' +# +# Settings: +# IBIP_TIMEOUT: seconds that must pass between IBIP responses; optional +# IBIP_COMMENT: the comment at the end of the IBIP message; optional +# IBIP_NOTICE: set to 1 to respond with NOTICE instead of PRIVMSG; optional + + +if [ -z "$IRCBOT_MODULE" ]; then + printf "error: %s is a module for ircbot.bash and should not be run separately\n" "$0" + exit 1 +fi + + +ibip_last=0 + +if [[ -z ${IBIP_COMMENT:-} ]]; then + IBIP_COMMENT='See https://git.clsr.net/mbibot' +fi + +# on_privmsg is called whenever a PRIVMSG is received +on_privmsg() { # args: $1 - source, $2 - channel/target, $3 - message + local ts where msgtype + where="$2" + if [[ $where == "$IRCBOT_NICK" ]]; then + where="$(parse_source_nick "$1")" + fi + msgtype=PRIVMSG + if [[ ${IBIP_NOTICE:-0} -ne 0 ]]; then + msgtype=NOTICE + fi + if [[ $3 == ".bots" ]]; then + ts="$(printf '%(%s)T' -1)" + if [[ -z ${IBIP_TIMEOUT:-} ]] || ((ts - ibip_last > IBIP_TIMEOUT)); then + ibip_last="$ts" + sendmsg "$msgtype" "$where" "Reporting in! [bash] $IBIP_COMMENT" + fi + fi +} |