Fixed reminder for real this time.

This commit is contained in:
Storm Dragon
2025-10-25 02:49:15 -04:00
parent 6f6f7159c1
commit 5af965e528

View File

@@ -2,9 +2,11 @@
[ -f functions.sh ] && source functions.sh [ -f functions.sh ] && source functions.sh
userNick="$1" userNick="$1"
shift chan="$2"
chan="$1" # $3 contains the entire argument string (e.g., "30s hello world")
shift # We need to split it into time and message
# shellcheck disable=SC2086
set -- $3 # Intentionally unquoted to split into separate words
time="$1" time="$1"
shift shift
@@ -46,18 +48,26 @@ if [[ -z "$*" ]]; then
exit 0 exit 0
fi fi
msg "$chan" "ok, $userNick, reminder in $time." # Convert message to array for easier parsing
reminderMessage="$*" # shellcheck disable=SC2206
msgArray=($*)
targetNick="$userNick" # Default target is the person who set the reminder
# Handle 'tell' syntax for targeting other users # Handle 'tell' syntax for targeting other users
if [[ "$reminderMessage" =~ ^[Tt]ell[[:space:]]+ ]]; then if [[ "${msgArray[0],,}" == "tell" ]]; then
targetNick="$(echo "${reminderMessage#[T|t]ell }" | cut -d ' ' -f1)" # Extract target nickname (second element, strip trailing punctuation)
# Validate nick doesn't contain invalid characters extractedNick="${msgArray[1]}"
if [[ "$targetNick" =~ ^[a-zA-Z0-9_\[\]\{\}\\|\`\^\-]+$ ]]; then extractedNick="${extractedNick%:}"
userNick="$targetNick" extractedNick="${extractedNick%,}"
reminderMessage="${reminderMessage#[Tt]ell }"
reminderMessage="${reminderMessage#* }" # Set target and rebuild message without "tell nickname"
fi targetNick="$extractedNick"
# Rebuild message from element 2 onward
reminderMessage="${msgArray[*]:2}"
else
reminderMessage="$*"
fi fi
sleep "$timeInSeconds" && msg "$chan" "$userNick: $reminderMessage" & msg "$chan" "ok, $userNick, reminder in $time."
sleep "$timeInSeconds" && msg "$chan" "$targetNick: $reminderMessage" &