From 4d88aed0d87c7fd4d1c0090d6485e7a3ef61346b Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Fri, 31 Oct 2025 12:04:52 -0700 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit enhance echo with admin functions --- mesh_bot.py | 51 +++++++++++++++++++++++++++++++++++++---------- modules/README.md | 44 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+), 11 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index bd2457a..f1fcb82 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -390,11 +390,36 @@ def handle_motd(message, message_from_id, isDM): return msg def handle_echo(message, message_from_id, deviceID, isDM, channel_number): + # Check if user is admin + isAdmin = isNodeAdmin(message_from_id) + # Admin extended syntax: echo c= d= + if isAdmin and message.strip().lower().startswith("echo ") and not message.strip().endswith("?"): + msg_to_echo = message.split(" ", 1)[1] + target_channel = channel_number + target_device = deviceID + + # Split into words to find c= and d=, but preserve spaces in message + words = msg_to_echo.split() + new_words = [] + for w in words: + if w.startswith("c=") and w[2:].isdigit(): + target_channel = int(w[2:]) + elif w.startswith("d=") and w[2:].isdigit(): + target_device = int(w[2:]) + else: + new_words.append(w) + msg_to_echo = " ".join(new_words).strip() + + # Send echo to specified channel/device + send_message(msg_to_echo, target_channel, 0, target_device) + time.sleep(splitDelay) # throttle for 2x send + return f"🐬echoed to channel {target_channel} device {target_device}" + + # dev echoBinary off echoBinary = False if echoBinary: try: - #send_raw_bytes echo the data to the channel with synch word: port_num = 256 synch_word = b"echo:" parts = message.split("echo ", 1) @@ -403,25 +428,29 @@ def handle_echo(message, message_from_id, deviceID, isDM, channel_number): raw_bytes = synch_word + msg_to_echo.encode('utf-8') send_raw_bytes(message_from_id, raw_bytes, nodeInt=deviceID, channel=channel_number, portnum=port_num) return f"Sent binary echo message to {message_from_id} to {port_num} on channel {channel_number} device {deviceID}" - else: - return "Please provide a message to echo back to you. Example:echo Hello World" except Exception as e: logger.error(f"System: Echo Exception {e}") - return f"Sent binary echo message to {message_from_id} to {port_num} on channel {channel_number} device {deviceID}" - if "?" in message.lower(): - return "command returns your message back to you. Example:echo Hello World" - elif "echo " in message.lower(): - parts = message.lower().split("echo ", 1) + if "?" in message: + isAdmin = isNodeAdmin(message_from_id) + if isAdmin: + return ( + "Admin usage: echo c= d=\n" + "Example: echo Hello world c=1 d=2" + ) + return "command returns your message back to you. Example: echo Hello World" + + # process normal echo back to user + elif message.strip().lower().startswith("echo "): + parts = message.split("echo ", 1) if len(parts) > 1 and parts[1].strip() != "": echo_msg = parts[1] if channel_number != my_settings.echoChannel and not isDM: echo_msg = "@" + get_name_from_number(message_from_id, 'short', deviceID) + " " + echo_msg return echo_msg else: - return "Please provide a message to echo back to you. Example:echo Hello World" - else: - return "Please provide a message to echo back to you. Example:echo Hello World" + return "Please provide a message to echo back to you. Example: echo Hello World" + return "🐬echo.." def handle_wxalert(message_from_id, deviceID, message): if my_settings.use_meteo_wxApi: diff --git a/modules/README.md b/modules/README.md index 7d6ff1d..8354b49 100644 --- a/modules/README.md +++ b/modules/README.md @@ -1194,6 +1194,50 @@ enabled = True # QRZ Hello to new nodes qrz_hello_string = "send CMD or DM me for more info." # will be sent to all heard nodes once training = True # Training mode will not send the hello message to new nodes, use this to build up database ``` +| Command | Description | ✅ Works Off-Grid | +|--------------|-------------|------------------| +| `echo` | Echo string back. Admins can use `echo c= d=` to send to any channel/device. | ✅ | + +--- + +### Echo Command + +The `echo` command returns your message back to you. +**Admins** can use an extended syntax to send a message to any channel and device. + +#### Usage + +- **Basic Echo (all users):** + ``` + echo Hello World + ``` + Response: + ``` + Hello World + ``` + +- **Admin Extended Syntax:** + ``` + echo c= d= + ``` + Example: + ``` + echo Hello world c=1 d=2 + ``` + This will send "Hello world" to channel 1, device 2. + +#### Help + +- Send `echo?` for usage instructions. +- Admins will see this help message: + ``` + Admin usage: echo c= d= + Example: echo Hello world c=1 d=2 + ``` + +#### Notes +- Only admins can use the `c=` and `d=` override. +- If you omit `c=` and `d=`, the message is echoed back to your current channel/device. Happy meshing! \ No newline at end of file