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
This commit is contained in:
SpudGunMan
2025-10-22 12:31:25 -07:00
parent c3ea07fde5
commit 290695327d
2 changed files with 34 additions and 17 deletions
+12 -2
View File
@@ -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."
+22 -15
View File
@@ -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):