From 53a2fb88b34141f5897baba35fd6721c64c92f46 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 4 Aug 2024 01:23:16 -0700 Subject: [PATCH] enhance --- mesh_bot.py | 2 +- modules/settings.py | 14 ++++++++------ modules/system.py | 15 ++++++++++++--- pong_bot.py | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index c795d2f..7008ebb 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -54,7 +54,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi bot_response = "No messages in history" elif "bbshelp" in message.lower(): bot_response = bbs_help() - elif "cmd" in message.lower(): + elif "cmd" in message.lower() or "cmd?" in message.lower(): bot_response = help_message elif "sun" in message.lower(): location = get_node_location(message_from_id, deviceID) diff --git a/modules/settings.py b/modules/settings.py index 4446980..226347d 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -3,7 +3,7 @@ import configparser # messages NO_DATA_NOGPS = "No location data: does your device have GPS?" ERROR_FETCHING_DATA = "error fetching data" -WELCOME_MSG = 'MeshBot, here for you like a friend who is not. Try sending: ping @foo or, cmd' +WELCOME_MSG = 'MeshBot, here for you like a friend who is not. Try sending: ping @foo or, cmd? for more' MOTD = 'Thanks for using MeshBOT! Have a good day!' NO_ALERTS = "No weather alerts found." @@ -11,13 +11,17 @@ NO_ALERTS = "No weather alerts found." MESSAGE_CHUNK_SIZE = 160 # message chunk size for sending at high success rate SITREP_NODE_COUNT = 3 # number of nodes to report in the sitrep msg_history = [] # message history for the store and forward feature -bbs_ban_list = [] # list of banned users -bbs_admin_list = [] # list of admin users -repeater_channels = [] # list of channels to listen on for repeater mode +bbs_ban_list = [] # list of banned users, imported from config +bbs_admin_list = [] # list of admin users, imported from config +repeater_channels = [] # list of channels to listen on for repeater mode, imported from config antiSpam = True # anti-spam feature to prevent flooding public channel ping_enabled = True # ping feature to respond to pings, ack's etc. sitrep_enabled = True # sitrep feature to respond to sitreps lastHamLibAlert = 0 # last alert from hamlib +max_retry_count1 = 4 # max retry count for interface 1 +max_retry_count2 = 4 # max retry count for interface 2 +retry_int1 = False +retry_int2 = False # Read the config file, if it does not exist, create basic config file config = configparser.ConfigParser() @@ -41,8 +45,6 @@ interface1_type = config['interface'].get('type', 'serial') port1 = config['interface'].get('port', '') hostname1 = config['interface'].get('hostname', '') mac1 = config['interface'].get('mac', '') -retry_int1 = False -retry_int2 = False # interface2 settings if 'interface2' in config: diff --git a/modules/system.py b/modules/system.py index 1066cc3..15d1ba0 100644 --- a/modules/system.py +++ b/modules/system.py @@ -10,7 +10,7 @@ import asyncio from modules.settings import * # Global Variables -trap_list = ("cmd",) # default trap list +trap_list = ("cmd","cmd?") # default trap list help_message = "CMD?:" asyncLoop = asyncio.new_event_loop() @@ -388,12 +388,13 @@ async def handleSignalWatcher(): pass async def retry_interface(nodeID=1): - global interface1, interface2, retry_int1, retry_int2 + global interface1, interface2, retry_int1, retry_int2, max_retry_count1, max_retry_count2 # retry connecting to the interface # add a check to see if the interface is already open or trying to open if nodeID==1: if interface1 is not None: retry_int1 = True + max_retry_count1 -= 1 try: interface1.close() except Exception as e: @@ -401,13 +402,21 @@ async def retry_interface(nodeID=1): if nodeID==2: if interface2 is not None: retry_int2 = True + max_retry_count2 -= 1 try: interface2.close() except Exception as e: print(f"{log_timestamp()} System: Error closing interface2: {e}") - # wait 15 seconds before retrying + print(f"{log_timestamp()} System: Retrying interface in 15 seconds") + if max_retry_count1 == 0: + print(f"{log_timestamp()} System: Max retry count reached for interface1") + exit_handler() + if max_retry_count2 == 0: + print(f"{log_timestamp()} System: Max retry count reached for interface2") + exit_handler() + # wait 15 seconds before retrying await asyncio.sleep(15) # retry the interface diff --git a/pong_bot.py b/pong_bot.py index 795e50a..5e99fc9 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -38,7 +38,7 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi bot_response = "MOTD Set to: " + MOTD else: bot_response = MOTD - elif "cmd" in message.lower(): + elif "cmd" in message.lower() or "cmd?" in message.lower(): bot_response = help_message elif "lheard" in message.lower() or "sitrep" in message.lower(): bot_response = "Last heard:\n" + str(get_node_list(1))