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/ctcpversion.bash | |
download | mbibot-ff2bc5d0931d4a460d4d74183b6f9dd9394c40a0.tar.gz mbibot-ff2bc5d0931d4a460d4d74183b6f9dd9394c40a0.zip |
Initial commitv0.1.0
Diffstat (limited to 'modules/ctcpversion.bash')
-rw-r--r-- | modules/ctcpversion.bash | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/modules/ctcpversion.bash b/modules/ctcpversion.bash new file mode 100644 index 0000000..092013b --- /dev/null +++ b/modules/ctcpversion.bash @@ -0,0 +1,32 @@ +# modules/ctcpversion.bash +# +# Responds to CTCP VERSION direct message requests. +# +# Settings: +# CTCP_VERSION: response to the CTCP VERSION request; optional, defaults to bash version + + +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 + + +# respond to CTCP VERSION requests +on_ctcp() { # args: $1 - source, $2 - CTCP command, $3 - CTCP argument + local version interpreter + if [[ $2 == VERSION ]]; then + if [[ -n ${CTCP_VERSION:-} ]]; then + version="$CTCP_VERSION" + else + interpreter=sh # I should make it actually find out which interpreter it's running if it's not bash or zsh; also, fails on dash as it lacks --version + if [ "$BASH_VERSION" ]; then + interpreter=bash + elif [ "$ZSH_VERSION" ]; then + interpreter=zsh + fi + version="$("$interpreter" --version 2>&1 | sed 1q)" + fi + sendmsg NOTICE "$(parse_source_nick "$1")" "$(sed 's/^.*$/\x01&\x01/' <<< "VERSION $version")" + fi +} |