diff --git a/mumblingherald b/mumblingherald index 7c2ab87c4339a6bd8f28bb8fb03358c9b02e2e54..612d7ccefb3ae79c991cc84c7a37385d9eee968d 100755 --- a/mumblingherald +++ b/mumblingherald @@ -19,6 +19,9 @@ MONITORED_CHANNELS=( "Room 5" ) +# Array to track users who have joined monitored channels +TRACKED_USERS=() + # Function to print debug messages if DEBUG is true log() { if ((DEBUG)); then @@ -146,6 +149,13 @@ parse_move_event() { # Check if this channel should be monitored if is_monitored_channel "$channel"; then log "*herald perks up* This movement requires my attention!" + + # Add user to tracked users array if not already present + if [[ ! " ${TRACKED_USERS[*]} " =~ \ $username\ ]]; then + TRACKED_USERS+=("$username") + log "*herald scribbles name in ledger* '$username' is now on my scroll of monitored souls" + fi + local join_msg join_msg=$(get_random_message JOIN_MESSAGES) local message="${join_msg//\{USERNAME\}/$username}" @@ -170,11 +180,28 @@ parse_disconnect_event() { local username="${BASH_REMATCH[1]}" log "*herald nods knowingly* '$username' has departed the realm entirely" - local leave_msg - leave_msg=$(get_random_message LEAVE_MESSAGES) - local message="${leave_msg//\{USERNAME\}/$username}" - echo "*herald notices someone's absence and sighs*" - send_notification "$message" + # Only announce departure if we were tracking this user + if [[ " ${TRACKED_USERS[*]} " =~ \ $username\ ]]; then + log "*herald checks ledger* Ah yes, '$username' was on my scroll. Time for a farewell..." + + # Remove user from tracked users array + local temp_array=() + for user in "${TRACKED_USERS[@]}"; do + if [[ "$user" != "$username" ]]; then + temp_array+=("$user") + fi + done + TRACKED_USERS=("${temp_array[@]}") + log "*herald crosses out name* '$username' removed from my scroll of monitored souls" + + local leave_msg + leave_msg=$(get_random_message LEAVE_MESSAGES) + local message="${leave_msg//\{USERNAME\}/$username}" + echo "*herald notices someone's absence and sighs*" + send_notification "$message" + else + log "*herald glances up briefly* '$username' departed, but they weren't on my sacred list anyway. *returns to scrolls*" + fi else log "*herald frowns* Disconnect event format puzzling. *grumbles about log formats* Line: $log_line" fi