mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-07-01 23:41:14 +02:00
Update mesh-bot.py
This commit is contained in:
+17
-12
@@ -76,7 +76,7 @@ def auto_response(message, snr, rssi, hop, message_from_id):
|
||||
elif "solar" in message.lower():
|
||||
bot_response = drap_xray_conditions() + "\n" + solar_conditions()
|
||||
elif "lheard" in message.lower():
|
||||
bot_response = "Last 5 nodes heard: " + str(get_node_list())
|
||||
bot_response = "Last 5 nodes heard:\n" + str(get_node_list())
|
||||
elif "whereami" in message.lower():
|
||||
location = get_node_location(message_from_id)
|
||||
where = where_am_i(str(location[0]),str(location[1]))
|
||||
@@ -210,28 +210,33 @@ def get_name_from_number(number, type='long'):
|
||||
return name
|
||||
|
||||
def get_node_list():
|
||||
#checks nodeDB on device and returns a list of the last 5 nodes heard
|
||||
node_list = []
|
||||
short_node_list = []
|
||||
if interface.nodes:
|
||||
for node in interface.nodes.values():
|
||||
#ignore own
|
||||
if node['num'] != myNodeNum:
|
||||
node_name = get_name_from_number(node['num'])
|
||||
snr = node.get('snr', 0)
|
||||
|
||||
# issue where lastHeard is not always present
|
||||
last_heard = node.get('lastHeard', 0)
|
||||
|
||||
item = (node_name,last_heard)
|
||||
#make a list of nodes with last heard time and SNR
|
||||
item = (node_name, last_heard, snr)
|
||||
node_list.append(item)
|
||||
|
||||
node_list.sort(key=lambda x: x[1], reverse=True)
|
||||
#print (f"Node List: {node_list[:5]}\n")
|
||||
#return only the last 5 nodes
|
||||
nice_node_list = [x[0] for x in node_list[:5]]
|
||||
return nice_node_list
|
||||
|
||||
# make a nice list for the user
|
||||
for x in node_list[:5]:
|
||||
short_node_list.append(f"{x[0]} SNR:{x[2]}")
|
||||
|
||||
return "\n".join(short_node_list)
|
||||
|
||||
else:
|
||||
node_list.append("Nothing heard")
|
||||
return node_list
|
||||
return "Error Processing Node List"
|
||||
|
||||
def get_node_location(number):
|
||||
#Get the location of a node by its number from nodeDB on device
|
||||
@@ -275,20 +280,20 @@ def send_message(message, ch, nodeid):
|
||||
if nodeid == 0:
|
||||
#Send to channel
|
||||
print (f"{log_timestamp()} System: Sending Multi-Chunk: {m} To: Channel:{ch}")
|
||||
interface.sendText(text=m,channelIndex=ch)
|
||||
interface.sendText(text=m, channelIndex=ch)
|
||||
else:
|
||||
#Send to DM
|
||||
print (f"{log_timestamp()} System: Sending Multi-Chunk: {m} To: {get_name_from_number(nodeid)}")
|
||||
interface.sendText(text=m,channelIndex=ch,destinationId=nodeid)
|
||||
interface.sendText(text=m,channelIndex=ch, destinationId=nodeid)
|
||||
else: #message is less than 160 characters
|
||||
if nodeid == 0:
|
||||
#Send to channel
|
||||
print (f"{log_timestamp()} System: Sending: {message} To: Channel:{ch}")
|
||||
interface.sendText(text=message,channelIndex=ch)
|
||||
interface.sendText(text=message, channelIndex=ch)
|
||||
else:
|
||||
#Send to DM
|
||||
print (f"{log_timestamp()} System: Sending: {message} To: {get_name_from_number(nodeid)}")
|
||||
interface.sendText(text=message,channelIndex=ch,destinationId=nodeid)
|
||||
interface.sendText(text=message, channelIndex=ch, destinationId=nodeid)
|
||||
|
||||
|
||||
def exit_handler(signum, frame):
|
||||
|
||||
Reference in New Issue
Block a user