From d1415f9d865d8f101de3459008ee658a08f5f6f4 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Sun, 22 Sep 2024 23:56:27 -0700 Subject: [PATCH] enhance --- mesh_bot.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 6939fb1..36bc15b 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -495,9 +495,9 @@ def handle_history(nodeid, deviceID, lheard=False): # show the last commands from the user to the bot if not lheard: for i in range(len(cmdHistory)): - if i > 1: break # skip the first iteration + if i > 1: continue # skip the first iteration - prettyTime = round((time.time() - cmdHistory[i]['time']) / 600) * 10 + prettyTime = round((time.time() - cmdHistory[i]['time']) / 600) * 5 if prettyTime < 60: prettyTime = str(prettyTime) + "m" elif prettyTime < 1440: @@ -507,17 +507,16 @@ def handle_history(nodeid, deviceID, lheard=False): # history display output if nodeid in bbs_admin_list and not cmdHistory[i]['nodeID'] in lheardCmdIgnoreNode: - msg += f"{get_name_from_number(nodeid,'short',deviceID)}:cmd:{cmdHistory[i]['cmd']}@{prettyTime} ago. " + msg += f"{get_name_from_number(nodeid,'short',deviceID)}:cmd:{cmdHistory[i]['cmd']}/{prettyTime} ago. " elif cmdHistory[i]['nodeID'] == nodeid and not cmdHistory[i]['nodeID'] in lheardCmdIgnoreNode: - msg += f"{get_name_from_number(nodeid,'short',deviceID)}:cmd:{cmdHistory[i]['cmd']}@ {prettyTime} ago. " + msg += f"{get_name_from_number(nodeid,'short',deviceID)}:cmd:{cmdHistory[i]['cmd']}/{prettyTime} ago. " if i > 2: break # only show the last 3 commands else: # sort the cmdHistory list by time, return the username and time into a new list which used for display cmdHistorySorted = sorted(cmdHistory, key=lambda k: k['time'], reverse=True) buffer = [] for i in range(len(cmdHistorySorted)): - if i >1: break # skip the first iteration - prettyTime = round((time.time() - cmdHistory[i]['time']) / 600) * 10 + prettyTime = round((time.time() - cmdHistory[i]['time']) / 600) * 5 if prettyTime < 60: prettyTime = str(prettyTime) + "m" elif prettyTime < 1440: @@ -527,12 +526,14 @@ def handle_history(nodeid, deviceID, lheard=False): if not cmdHistorySorted[i]['nodeID'] in lheardCmdIgnoreNode: # add line to a new list for display - if get_name_from_number(nodeid, 'short', deviceID) not in buffer: - buffer.append([get_name_from_number(nodeid, 'short', deviceID), prettyTime]) + nodeName = get_name_from_number(cmdHistorySorted[i]['nodeID'], 'short', deviceID) + if nodeName not in buffer: + buffer.append((nodeName, prettyTime)) if i > 4: break # only show the last 4 users - # format the buffer list into a string for return - for line in buffer: - msg += f"{line[0]}@{line[1]} ago. " + + # format the buffer list into a string for return but skip the first line + for i in range(1, len(buffer)): + msg += f"{buffer[i][0]} seen {buffer[i][1]} ago. " return msg