#!/usr/bin/env bash [ -f functions.sh ] && source functions.sh user=$1 shift shift newNick="$1" # Validate that user is authorized if [[ ! "$user" =~ $allowList ]]; then exit 0 fi # Validate IRC nickname format (RFC 2812) # Nicknames can contain: a-z A-Z 0-9 _ - [ ] { } \ | ^ if [[ -z "$newNick" ]]; then msg "#$channel" "$user: Please provide a nickname." exit 0 fi if ! [[ "$newNick" =~ ^[a-zA-Z0-9_\[\]\{\}\\|\^-]+$ ]]; then msg "#$channel" "$user: Invalid nickname format. Only alphanumeric and _-[]{}\\|^ allowed." exit 0 fi if [[ ${#newNick} -gt 30 ]]; then msg "#$channel" "$user: Nickname too long (max 30 characters)." exit 0 fi # Change the nick ./modules/do/do.sh "$newNick" "#$channel" "does a magical gesture and turns into ${newNick}!" nick "$newNick" # Safely update config file - escape forward slashes for sed escapedNick="${newNick//\//\\/}" sed -i "s/^nick=.*/nick=\"${escapedNick}\"/" bot.cfg