Fixed a bug with irc parsing.

This commit is contained in:
Storm Dragon
2025-10-25 01:38:14 -04:00
parent d684623974
commit d32baa66ba
2 changed files with 17 additions and 0 deletions

5
bot.sh
View File

@@ -267,6 +267,11 @@ while true; do
;;
# run when a message is seen
*PRIVMSG*)
# Only process if this is a user message (contains ! for hostmask)
if [[ ! "$result" =~ :[^!]+!.*PRIVMSG ]]; then
continue
fi
who="${result%%!*}"
who="${who:1}"
from="${result#*#}"

View File

@@ -12,6 +12,18 @@ channelName="$2"
shift 2
message="$*"
# Sanitize username (extract just the nickname, max 30 chars per IRC RFC)
# Remove any IRC protocol remnants, hostmask info, etc.
name="${name%%!*}" # Remove hostmask if present
name="${name%%[[:space:]]*}" # Remove any trailing data
name="${name//[^a-zA-Z0-9_\[\]\{\}\\|\^-]/}" # Only allow valid IRC nick chars
name="${name:0:30}" # Limit to max IRC nickname length
# If name is empty or invalid after sanitization, skip
if [[ -z "$name" ]]; then
exit 0
fi
# Sanitize channel name (remove any IRC protocol remnants)
channelName="${channelName%%[[:space:]]*}"
channelName="${channelName//[^a-zA-Z0-9#_-]/}"