#!/usr/bin/env bash [ -f functions.sh ] && source functions.sh userNick="$1" shift chan="$1" shift time="$1" shift # Validate time argument is provided if [[ -z "$time" ]]; then msg "$chan" "$userNick: Please provide a time (e.g., 30s, 5m, 1h)." exit 0 fi # Normalize time format if ! [[ "$time" =~ ^[0-9]+[HhMmSs]$ ]]; then time="${time}s" fi # Validate time is numeric if ! [[ "${time%[HhMmSs]}" =~ ^[0-9]+$ ]]; then msg "$chan" "$userNick: Time must be numeric (e.g., 30s, 5m, 1h)." exit 0 fi # Validate time is reasonable (max 24 hours) timeValue="${time%[HhMmSs]}" timeUnit="${time: -1}" case "${timeUnit,,}" in h) maxTime=24; timeInSeconds=$((timeValue * 3600)) ;; m) maxTime=1440; timeInSeconds=$((timeValue * 60)) ;; s) maxTime=86400; timeInSeconds=$timeValue ;; *) maxTime=86400; timeInSeconds=$timeValue ;; esac if [[ $timeValue -gt $maxTime ]]; then msg "$chan" "$userNick: Maximum time is 24 hours." exit 0 fi # Validate reminder message is provided if [[ -z "$*" ]]; then msg "$chan" "$userNick: Please provide a reminder message." exit 0 fi msg "$chan" "ok, $userNick, reminder in $time." reminderMessage="$@" # Handle 'tell' syntax for targeting other users if [[ "$reminderMessage" =~ ^[Tt]ell[[:space:]]+ ]]; then targetNick="$(echo "${reminderMessage#[T|t]ell }" | cut -d ' ' -f1)" # Validate nick doesn't contain invalid characters if [[ "$targetNick" =~ ^[a-zA-Z0-9_\[\]\{\}\\|\`\^\-]+$ ]]; then userNick="$targetNick" reminderMessage="${reminderMessage#[Tt]ell }" reminderMessage="${reminderMessage#* }" fi fi sleep "$timeInSeconds" && msg "$chan" "$userNick: $reminderMessage" &