Implement logic for breaking up a long irc message

This commit is contained in:
Nick Chambers 2021-06-16 12:13:00 -05:00
parent ca0982b08d
commit 847a35f4d8
1 changed files with 61 additions and 4 deletions

65
rowbot
View File

@ -134,7 +134,7 @@ cleanup() {
trap cleanup EXIT trap cleanup EXIT
### ###
# net code # net/reload code
### ###
if [[ $reload = yes ]]; then if [[ $reload = yes ]]; then
@ -150,6 +150,12 @@ if [[ $reload = yes ]]; then
if [[ -v PING_PID ]]; then if [[ -v PING_PID ]]; then
ping_pid=$PING_PID ping_pid=$PING_PID
fi fi
nick=$NICK ident=$IDENT
if [[ -v HOST ]]; then
host=$HOST
fi
elif [[ $tls = yes ]]; then elif [[ $tls = yes ]]; then
sock_dir=$(mktemp -d) sock_dir=$(mktemp -d)
mkfifo "$sock_dir"/rb{in,out} mkfifo "$sock_dir"/rb{in,out}
@ -256,6 +262,8 @@ on_001() {
done & done &
ping_pid=$! ping_pid=$!
nick=${params[0]}
who "$nick" %%uht,42
} }
on_002() { on_002() {
@ -314,6 +322,10 @@ on_266() {
info %s "${params[3]}" info %s "${params[3]}"
} }
on_315() {
debug "end of WHO for %s" "${params[1]}"
}
on_332() { on_332() {
info "topic for %s is %s" "${params[1]}" "${params[2]}" info "topic for %s is %s" "${params[1]}" "${params[2]}"
} }
@ -328,6 +340,14 @@ on_353() {
info "members of %s: %s" "${params[2]}" "${params[3]}" info "members of %s: %s" "${params[2]}" "${params[3]}"
} }
on_354() {
if (( ${params[1]} == 42 )); then
debug "received the identifying who"
ident=${params[2]} host=${params[3]}
debug "ident=%s host=%s" "$ident" "$host"
fi
}
on_366() { on_366() {
debug "%s: end of NAMES list" "${params[1]}" debug "%s: end of NAMES list" "${params[1]}"
} }
@ -361,6 +381,18 @@ nick() {
} }
notice() { notice() {
if [[ -v host ]]; then
local msg_len msg=$2
(( msg_len = 494 - (${#nick} + ${#ident} + ${#host} + ${#1}) ))
debug "max message length is %d" "$msg_len"
while (( ${#msg} > msg_len )); do
send "NOTICE %s :"$'\xe2\x80\x8b'"%s" "$1" "${msg:0:$msg_len}"
info "[%s/%s] %s" "$nick" "$1" "${msg:0:$msg_len}"
msg=${msg:$msg_len}
done
fi
send "NOTICE %s :%s" "$1" "$2" send "NOTICE %s :%s" "$1" "$2"
info "[%s/%s] %s" "$nick" "$1" "$2" info "[%s/%s] %s" "$nick" "$1" "$2"
} }
@ -384,8 +416,20 @@ pong() {
} }
privmsg() { privmsg() {
send "PRIVMSG %s :\u200b%s" "$1" "$2" if [[ -v host ]]; then
info "<%s/%s> %s" "$nick" "$1" "$2" local msg_len msg=$2
(( msg_len = 493 - (${#nick} + ${#ident} + ${#host} + ${#1}) ))
debug "max message length is %d" "$msg_len"
while (( ${#msg} > msg_len )); do
send "PRIVMSG %s :"$'\xe2\x80\x8b'"%s" "$1" "${msg:0:$msg_len}"
info "<%s/%s> %s" "$nick" "$1" "${msg:0:$msg_len}"
msg=${msg:$msg_len}
done
fi
send "PRIVMSG %s :"$'\xe2\x80\x8b'"%s" "$1" "$msg"
info "<%s/%s> %s" "$nick" "$1" "$msg"
} }
quit() { quit() {
@ -400,6 +444,14 @@ user() {
send "USER %s 0 * :%s" "$ident" "$realname" send "USER %s 0 * :%s" "$ident" "$realname"
} }
who() {
if (( $# > 1 )); then
send "WHO %s %s" "$1" "$2"
else
send "WHO %s" "$1"
fi
}
### ###
# app hooks # app hooks
## ##
@ -512,7 +564,7 @@ hook_post_PRIVMSG_control_panel() {
case ${words[0]:${#trigger}} in case ${words[0]:${#trigger}} in
raw) raw)
local cmd local cmd
cmd=${params[1]#*"$trigger"raw} cmd=${cmd# } cmd=${params[1]#"$trigger"raw} cmd=${cmd# }
info "%s is executing command: %s" "$from" "$cmd" info "%s is executing command: %s" "$from" "$cmd"
send "$cmd" send "$cmd"
;; ;;
@ -523,6 +575,11 @@ hook_post_PRIVMSG_control_panel() {
reload) reload)
export IN_SOCK=$in_sock OUT_SOCK=$out_sock LOG_FD=$log DEV=$dev export IN_SOCK=$in_sock OUT_SOCK=$out_sock LOG_FD=$log DEV=$dev
export RELOAD_TO=$to TRIGGER=$trigger LOG_LEVEL=$level export RELOAD_TO=$to TRIGGER=$trigger LOG_LEVEL=$level
export NICK=$nick IDENT=$ident
if [[ -v host ]]; then
export HOST=$host
fi
if [[ $tls = yes ]]; then if [[ $tls = yes ]]; then
export SOCK_DIR=$sock_dir export SOCK_DIR=$sock_dir