diff --git a/README.md b/README.md index 1237fe3..9ac8a29 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ The feature-rich bot requires the internet for full functionality. These respond Along with network testing, this bot has a lot of other features, like simple mail messaging you can leave for another device, and when that device is seen, it can send the mail as a DM. -The bot is also capable of using dual radio/nodes, so you can monitor two networks at the same time and send messages to nodes using the same `bbspost @nodeNumber #message` function. There is a small message board to fit in the constraints of Meshtastic for posting bulletin messages with `bbspost $subject #message`. +The bot is also capable of using dual radio/nodes, so you can monitor two networks at the same time and send messages to nodes using the same `bbspost @nodeNumber #message` or `bbspost @nodeShportName #message` function. There is a small message board to fit in the constraints of Meshtastic for posting bulletin messages with `bbspost $subject #message`. The bot will report on anyone who is getting close to the device if in a remote location. @@ -26,7 +26,7 @@ Any messages that are over 160 characters are chunked into 160 message bytes to - `bbshelp` returns the following - `bbslist` list the messages by ID and subject - `bbsread` read a message example use: `bbsread #1` - - `bbspost` post a message to public board or send a DM example use: `bbspost $subject #message, or bbspost @nodeNumber #message` + - `bbspost` post a message to public board or send a DM example use: `bbspost $subject #message, or bbspost @nodeNumber #message or bbspost @nodeShportName #message` - `bbsdelete` delete a message example use: `bbsdelete #4` - Other functions - `whereami` returns the address of location of sender if known @@ -145,8 +145,12 @@ pip install geopy pip install maidenhead pip install beautifulsoup4 pip install dadjokes +``` +The following is needed for open-meteo use +``` pip install openmeteo_requests pip install retry_requests +pip install numpy ``` To enable emoji in the Debian console, install the fonts `sudo apt-get install fonts-noto-color-emoji` diff --git a/mesh_bot.py b/mesh_bot.py index e53e6c1..4c2e609 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -92,16 +92,16 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi elif "wxc" in message.lower() or "wx" in message.lower(): location = get_node_location(message_from_id, deviceID) if use_meteo_wxApi and not "wxc" in message.lower() and not use_metric: - logger.debug(f"System: Returning Open-Meteo API for weather imperial") + logger.debug(f"System: Bot Returning Open-Meteo API for weather imperial") weather = get_wx_meteo(str(location[0]),str(location[1])) elif use_meteo_wxApi: - logger.debug(f"System: Returning Open-Meteo API for weather metric") + logger.debug(f"System: Bot Returning Open-Meteo API for weather metric") weather = get_wx_meteo(str(location[0]),str(location[1]),1) elif not use_meteo_wxApi and "wxc" in message.lower() or use_metric: - logger.debug(f"System: Returning NOAA API for weather metric") + logger.debug(f"System: Bot Returning NOAA API for weather metric") weather = get_weather(str(location[0]),str(location[1]),1) else: - logger.debug(f"System: Returning NOAA API for weather imperial") + logger.debug(f"System: Bot Returning NOAA API for weather imperial") weather = get_weather(str(location[0]),str(location[1])) bot_response = weather elif "joke" in message.lower(): @@ -124,13 +124,21 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi elif "@" in message and not "example:" in message: toNode = message.split("@")[1].split("#")[0] toNode = toNode.rstrip() + # if toNode is a string look for short name and convert to number + if toNode.isalpha(): + toNode = get_num_from_short_name(toNode, deviceID) + if toNode == 0: + bot_response = "Node not found " + message.split("@")[1].split("#")[0] + return bot_response + else: + logger.debug(f"System: bbspost, name lookup found: {toNode}") if "#" in message: body = message.split("#")[1] bot_response = bbs_post_dm(toNode, body, message_from_id) else: - bot_response = "example: bbspost @nodeNumber #message" + bot_response = "example: bbspost @nodeNumber/ShortName #message" elif not "example:" in message: - bot_response = "example: bbspost $subject #message, or bbspost @nodeNumber #message" + bot_response = "example: bbspost $subject #message, or bbspost @node #message" elif "bbsread" in message.lower(): # Check if the user added a message number to the message diff --git a/modules/system.py b/modules/system.py index 8f5d8d9..9b2d2d2 100644 --- a/modules/system.py +++ b/modules/system.py @@ -153,6 +153,19 @@ def get_name_from_number(number, type='long', nodeInt=1): name = str(decimal_to_hex(number)) # If name not found, use the ID as string return name return number + +def get_num_from_short_name(short_name, nodeInt=1): + # 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}") + if nodeInt == 1: + for node in interface1.nodes.values(): + if str(short_name.lower()) == node['user']['shortName'].lower(): + return node['num'] + if nodeInt == 2: + for node in interface2.nodes.values(): + if str(short_name.lower()) == node['user']['shortName'].lower(): + return node['num'] + return 0 def get_node_list(nodeInt=1): # Get a list of nodes on the device diff --git a/requirements.txt b/requirements.txt index 3f98692..c6b205a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,4 +8,5 @@ maidenhead beautifulsoup4 dadjokes openmeteo_requests -retry_requests \ No newline at end of file +retry_requests +numpy \ No newline at end of file