From 26ca9599deee70146e4f47fb01547d90efbb6360 Mon Sep 17 00:00:00 2001 From: pdxlocations Date: Wed, 22 Oct 2025 08:38:16 -0700 Subject: [PATCH] Implement cooldown for traceroute command to prevent spamming; update UI state to track last traceroute time --- contact/ui/contact_ui.py | 16 +++++++++++++++- contact/ui/ui_state.py | 1 + 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/contact/ui/contact_ui.py b/contact/ui/contact_ui.py index 28262e6..29880bb 100644 --- a/contact/ui/contact_ui.py +++ b/contact/ui/contact_ui.py @@ -404,11 +404,25 @@ def handle_enter(input_text: str) -> str: def handle_ctrl_t(stdscr: curses.window) -> None: """Handle Ctrl + T key events to send a traceroute.""" + now = time.monotonic() + cooldown = 30.0 + remaining = cooldown - (now - ui_state.last_traceroute_time) + + if remaining > 0: + curses.curs_set(0) # Hide cursor + contact.ui.dialog.dialog( + "Traceroute Not Sent", f"Please wait {int(remaining)} seconds before sending another traceroute." + ) + curses.curs_set(1) # Show cursor again + handle_resize(stdscr, False) + return + send_traceroute() + ui_state.last_traceroute_time = now curses.curs_set(0) # Hide cursor contact.ui.dialog.dialog( f"Traceroute Sent To: {get_name_from_database(ui_state.node_list[ui_state.selected_node])}", - "Results will appear in messages window.\nNote: Traceroute is limited to once every 30 seconds.", + "Results will appear in messages window.", ) curses.curs_set(1) # Show cursor again handle_resize(stdscr, False) diff --git a/contact/ui/ui_state.py b/contact/ui/ui_state.py index 34f3c4c..291c5f5 100644 --- a/contact/ui/ui_state.py +++ b/contact/ui/ui_state.py @@ -26,6 +26,7 @@ class ChatUIState: selected_node: int = 0 current_window: int = 0 last_sent_time: float = 0.0 + last_traceroute_time: float = 0.0 selected_index: int = 0 start_index: List[int] = field(default_factory=lambda: [0, 0, 0])