From 9ae95752ad6038527a48bc4cecd086d3a4bd04fc Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Mon, 12 Aug 2024 02:51:34 -0700 Subject: [PATCH] Update mesh_bot.py --- mesh_bot.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index d665cb1..275ec69 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -45,15 +45,14 @@ def auto_response(message, snr, rssi, hop, message_from_id, channel_number, devi cmds = [] # list to hold the commands found in the message for key in command_handler: if key in message_lower: - if message_lower.index(key) == 0: - cmds += [key,] - else: - cmds += [key,] + cmds.append('key', key, 'index', message_lower.index(key)) if len(cmds) > 0: + # sort the commands by index + cmds.sort(key=lambda x: x[3]) logger.debug(f"System: Bot Detected: {cmds}") # run the last command found in the message - bot_response = command_handler[cmds[-1]]() + bot_response = command_handler[cmds[0]]() # wait a 700ms to avoid message collision from lora-ack time.sleep(0.7)