From 290695327dabbf87afd3b6ff56a0363482ce5524 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 22 Oct 2025 12:31:25 -0700 Subject: [PATCH] enhance Ping with ping @NodeShortID you should be able to now ping @ and if its a node ID it will send a BBS mail with a joke in it @mesb1 thanks for idea https://github.com/SpudGunMan/meshing-around/issues/224 --- mesh_bot.py | 14 ++++++++++++-- modules/system.py | 37 ++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 17 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 42b93f6..e0c7999 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -268,11 +268,22 @@ def handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, chann if "@" in message: msg = msg + " @" + message.split("@")[1] type = type + " @" + message.split("@")[1] + + # check for ping to @nodeID and allow BBS DM + toNode = message.split("@")[1].strip().split(" ")[0] + toNode = get_num_from_short_name(toNode, deviceID) + if toNode and isinstance(toNode, int) and toNode != 0: + if bbs_enabled: + msg_result = None + logger.debug(f"System: Sending ping as BBS DM to @{toNode} from {get_name_from_number(message_from_id, 'short', deviceID)}") + msg_result = bbs_post_dm(toNode, f"Joke for you! {tell_joke()}", message_from_id) + # exit the function + return msg_result if msg_result else logger.warning(f"System: ping @nodeID detected but no BBS to send with, enable BBS in settings.ini") + elif "#" in message: msg = msg + " #" + message.split("#")[1] type = type + " #" + message.split("#")[1] - # check for multi ping request if " " in message: # if stop multi ping @@ -282,7 +293,6 @@ def handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, chann multiPingList.pop(i) msg = "🛑 auto-ping" - # if 3 or more entries (2 or more active), throttle the multi-ping for congestion if len(multiPingList) > 2: msg = "🚫⛔️ auto-ping, service busy. ⏳Try again soon." diff --git a/modules/system.py b/modules/system.py index bf6f0e4..ce8a1f8 100644 --- a/modules/system.py +++ b/modules/system.py @@ -512,24 +512,31 @@ def get_name_from_number(number, type='long', nodeInt=1): return name def get_num_from_short_name(short_name, nodeInt=1): + # First, search the specified interface interface = globals()[f'interface{nodeInt}'] - # Get the node number from the short name, converting all to lowercase for comparison (good practice?) - logger.debug(f"System: Getting Node Number from Short Name: {short_name} on Device: {nodeInt}") + logger.debug(f"System: Checking Node Number from Short Name: {short_name} on Device: {nodeInt}") for node in interface.nodes.values(): - #logger.debug(f"System: Checking Node: {node['user']['shortName']} against {short_name} for number {node['num']}") - if short_name == node['user']['shortName']: + if short_name == node['user']['shortName'] or str(short_name).lower() == node['user']['shortName'].lower(): return node['num'] - elif str(short_name.lower()) == node['user']['shortName'].lower(): - return node['num'] - else: - for int in range(1, 10): - if globals().get(f'interface{int}_enabled') and int != nodeInt: - other_interface = globals().get(f'interface{int}') - for node in other_interface.nodes.values(): - if short_name == node['user']['shortName']: - return node['num'] - elif str(short_name.lower()) == node['user']['shortName'].lower(): - return node['num'] + + # If not found, search all other enabled interfaces + for iface_num in range(1, 10): + if iface_num == nodeInt: + continue + if globals().get(f'interface{iface_num}_enabled'): + other_interface = globals().get(f'interface{iface_num}') + for node in other_interface.nodes.values(): + if short_name == node['user']['shortName'] or str(short_name).lower() == node['user']['shortName'].lower(): + logger.debug(f"System: Found Device:{iface_num} Node:{node['user']['shortName']}") + return node['num'] + + # !hex node IDs + if str(short_name).startswith("!"): + try: + return int(short_name[1:], 16) + except Exception: + pass + return 0 def get_node_list(nodeInt=1):