diff options
author | clsr <clsr@clsr.net> | 2017-04-23 22:02:55 +0200 |
---|---|---|
committer | clsr <clsr@clsr.net> | 2017-04-23 22:02:55 +0200 |
commit | 74c839cd6bb5582e30c4412dea34620be4c0c844 (patch) | |
tree | 499e60c7571273b6fed004d8d8e01c9e4ce44a8e | |
parent | ff2bc5d0931d4a460d4d74183b6f9dd9394c40a0 (diff) | |
download | mbibot-74c839cd6bb5582e30c4412dea34620be4c0c844.tar.gz mbibot-74c839cd6bb5582e30c4412dea34620be4c0c844.zip |
Let bash find and assign file descriptors for IRC socket and logging
-rwxr-xr-x | ircbot.bash | 6 | ||||
-rw-r--r-- | modules/log.bash | 10 |
2 files changed, 8 insertions, 8 deletions
diff --git a/ircbot.bash b/ircbot.bash index c50518b..3939311 100755 --- a/ircbot.bash +++ b/ircbot.bash @@ -73,7 +73,7 @@ verbose() { } connect() { - if ! exec 3<>"/dev/tcp/$IRCBOT_HOST/$IRCBOT_PORT"; then + if ! exec {_ircbot_fd}<>"/dev/tcp/$IRCBOT_HOST/$IRCBOT_PORT"; then return $? fi @@ -197,13 +197,13 @@ sendmsg() { # args: $1 - command, $2... - args (any number) if ! _trigger sendmsg "$msg" "$cmd" "${args[@]}"; then return $? fi - printf "%s\r\n" "$msg" >&3 + printf "%s\r\n" "$msg" >&$_ircbot_fd return $? } _readmsg() { local line - IFS= read -r -u 3 -t "${IRCBOT_READ_TIMEOUT:-300}" line + IFS= read -r -u $_ircbot_fd -t "${IRCBOT_READ_TIMEOUT:-300}" line success=$? printf "%s\n" "$line" | trimrn return $success diff --git a/modules/log.bash b/modules/log.bash index e9fc665..cd4e038 100644 --- a/modules/log.bash +++ b/modules/log.bash @@ -16,12 +16,12 @@ fi if [[ -n ${LOG_IRC:-} ]]; then if [[ ${LOG_SHOW_IRC:-0} -ne 0 ]]; then - exec 14> >(tee -a -- "$LOG_IRC") + exec {log_fd}> >(tee -a -- "$LOG_IRC") else - exec 14>>"$LOG_IRC" + exec {log_fd}>>"$LOG_IRC" fi elif [[ ${LOG_SHOW_IRC:-0} -ne 0 ]]; then - exec 14>&1 + exec {log_fd}>&1 fi if [[ -n ${LOG_ERR:-} ]]; then @@ -31,12 +31,12 @@ fi # log received messages on_readmsg() { # args: $1 - raw message, $2 - source, $3 - command, $4... - args - printf "%s <<< %s\n" "$(log_timestamp)" "$1" >&14 + printf "%s <<< %s\n" "$(log_timestamp)" "$1" >&$log_fd } # log sent messages on_sendmsg() { # args: $1 - raw message, $2 - command, $3... - args - printf "%s >>> %s\n" "$(log_timestamp)" "$1" >&14 + printf "%s >>> %s\n" "$(log_timestamp)" "$1" >&$log_fd } log_timestamp() { |