Break up PRIVMSG messages by maximum length

This commit is contained in:
Nick Chambers 2021-07-12 00:03:47 -05:00 committed by Nick Chambers
parent a7e443a8cb
commit 63a025e5be
1 changed files with 40 additions and 1 deletions

41
rowbot
View File

@ -414,7 +414,7 @@ on_sys_after_999_magic() {
on_sys_register_999_magic() {
if [[ ${config[chan]} ]]; then
irc_join "$chan"
irc_join "${config[chan]}"
fi
while true; do
@ -425,6 +425,15 @@ on_sys_register_999_magic() {
alarm_pid=$!
trap magic_annoyatron900 USR1
log_debug "process %d is being annoying" "$alarm_pid"
config[nick]=${msg_args[0]}
irc_who "${config[nick]}" %%uht,42
}
on_msg_354_magic() {
if (( msg_args[1] == 42 )); then
log_debug "received the identifying who"
config[ident]=${msg_args[2]} config[host]=${msg_args[3]}
fi
}
on_sys_exit_997_magic() {
@ -573,6 +582,10 @@ irc_on_353() {
log_info "members of %s: %s" "${msg_args[2]}" "${msg_args[3]}"
}
irc_on_354() {
log_debug "who: %s" "${msg_args[*]}"
}
irc_on_366() {
log_debug "%s: end of NAMES list" "${msg_args[1]}"
}
@ -623,10 +636,36 @@ irc_pong() {
net_send "PONG %s" "$1"
}
irc_privmsg() {
local msg=$2 msg_len
if [[ -v config[host] ]]; then
(( msg_len = 493 - (${#config[nick]} + ${#config[ident]} + ${#config[host]} + ${#1}) ))
log_debug "max message length is %d" "$msg_len"
while (( ${#msg} > msg_len )); do
net_send "PRIVMSG %s :"$'\xe2\x80\x8b'"%s" "$1" "${msg:0:$msg_len}"
log_info "<%s/%s> %s" "${config[nick]}" "$1" "${msg:0:$msg_len}"
msg=${msg:$msg_len}
done
fi
net_send "PRIVMSG %s :"$'\xe2\x80\x8b'"%s" "$1" "$msg"
log_info "<%s/%s> %s" "${config[nick]}" "$1" "$msg"
}
irc_user() {
net_send "USER %s 0 * :%s" "$1" "$2"
}
irc_who() {
if (( $# > 1 )); then
net_send "WHO %s %s" "$1" "$2"
else
net_send "WHO %s" "$1"
fi
}
###
# cleanup
###