From 276e4c3d09ee2bbdc7d5b67877e0d433778409e0 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Wed, 25 Sep 2024 16:38:27 -0700 Subject: [PATCH] ? trap --- mesh_bot.py | 10 ++++++++-- modules/system.py | 12 +++++++++++- 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 67418c0..c09eb71 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -48,7 +48,6 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n "bbsdelete": lambda: handle_bbsdelete(message, message_from_id), "messages": lambda: handle_messages(deviceID, channel_number, msg_history, publicChannel), "cmd": lambda: help_message, - "cmd?": lambda: help_message, "history": lambda: handle_history(message_from_id, deviceID), "sun": lambda: handle_sun(message_from_id, deviceID, channel_number), "hfcond": hf_band_conditions, @@ -67,8 +66,14 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n # set the command handler command_handler = default_commands cmds = [] # list to hold the commands found in the message + # check the message for commands words list, processed after system.messageTrap for key in command_handler: - if key in message_lower.split(' '): + word = message_lower.split(' ') + if key in word: + # append all the commands found in the message to the cmds list + cmds.append({'cmd': key, 'index': message_lower.index(key)}) + # check for commands with a question mark + if key + "?" in word: # append all the commands found in the message to the cmds list cmds.append({'cmd': key, 'index': message_lower.index(key)}) @@ -783,6 +788,7 @@ def onReceive(packet, interface): isDM = True # check if the message contains a trap word, DMs are always responded to if messageTrap(message_string): + # log the message to the message log logger.info(f"Device:{rxNode} Channel: {channel_number} " + CustomFormatter.green + f"Received DM: " + CustomFormatter.white + f"{message_string} " + CustomFormatter.purple +\ "From: " + CustomFormatter.white + f"{get_name_from_number(message_from_id, 'long', rxNode)}") # respond with DM diff --git a/modules/system.py b/modules/system.py index 8a99c5e..47be5a6 100644 --- a/modules/system.py +++ b/modules/system.py @@ -581,12 +581,22 @@ def get_wikipedia_summary(search_term): return summary def messageTrap(msg): - # Check if the message contains a trap word + # Check if the message contains a trap word, this is the first filter for listning to messages + # after this the message is passed to the command_handler in the bot.py which is switch case filter for applying word to function + + # Split Message on assumed words spaces m for m = msg.split(" ") + # t in trap_list, built by the config and system.py not the user message_list=msg.split(" ") for m in message_list: for t in trap_list: + # if word in message is in the trap list, return True if t.lower() == m.lower(): return True + # if no trap words found, run a search for near misses like ping? or cmd? + for m in message_list: + for t in range(len(trap_list)): + if m.endswith('?') and m[:-1].lower() == trap_list[t]: + return True return False def exit_handler():