From 45c912a0d62270bd770a3639a7095e28b1eaf74f Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:19:50 -0700 Subject: [PATCH 1/9] Update mesh_bot.py --- mesh_bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesh_bot.py b/mesh_bot.py index 81e2ac1..e62f324 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -25,7 +25,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n # Command List default_commands = { "ping": lambda: handle_ping(message, hop, snr, rssi, isDM), - "pong": lambda: "\n PING!! 🏓", + "pong": lambda: "PING!! 🏓", "motd": lambda: handle_motd(message, message_from_id, isDM), "bbshelp": bbs_help, "wxalert": lambda: handle_wxalert(message_from_id, deviceID, message), From a0a2c60e63520200135e88655d70cb17aef15bda Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:25:29 -0700 Subject: [PATCH 2/9] Update mesh_bot.py --- mesh_bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index e62f324..c8dce63 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -25,7 +25,7 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n # Command List default_commands = { "ping": lambda: handle_ping(message, hop, snr, rssi, isDM), - "pong": lambda: "PING!! 🏓", + "pong": lambda: "🏓PING!!", "motd": lambda: handle_motd(message, message_from_id, isDM), "bbshelp": bbs_help, "wxalert": lambda: handle_wxalert(message_from_id, deviceID, message), @@ -105,7 +105,7 @@ def handle_ping(message, hop, snr, rssi, isDM): msg = "" if "ping" in message.lower(): - msg = "🏓 PONG \n" + msg = "🏓PONG, " elif "test" in message.lower() or "testing" in message.lower(): msg = random.choice(["🎙 Testing 1,2,3\n", "🎙 Testing\n",\ "🎙 Testing, testing\n",\ From b7a3e7014c7ddf851a74eab1135e6811cd28e119 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:26:42 -0700 Subject: [PATCH 3/9] Update mesh_bot.py --- mesh_bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index c8dce63..e2182b2 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -107,12 +107,12 @@ def handle_ping(message, hop, snr, rssi, isDM): if "ping" in message.lower(): msg = "🏓PONG, " elif "test" in message.lower() or "testing" in message.lower(): - msg = random.choice(["🎙 Testing 1,2,3\n", "🎙 Testing\n",\ - "🎙 Testing, testing\n",\ - "🎙 Ah-wun, ah-two...\n", "🎙 Is this thing on?\n",\ - "🎙 Roger that\n",]) + msg = random.choice(["🎙Testing 1,2,3\n", "🎙Testing\n",\ + "🎙Testing, testing\n",\ + "🎙Ah-wun, ah-two...\n", "🎙 Is this thing on?\n",\ + "🎙Roger that\n",]) elif "ack" in message.lower(): - msg = random.choice(["✋ACK-ACK!\n", "Ack to you!\n"]) + msg = random.choice(["✋ACK-ACK!\n", "✋Ack to you!\n"]) else: msg = "" From 0e35c891c44f269d000e1296c1b4063806146760 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:29:54 -0700 Subject: [PATCH 4/9] Update mesh_bot.py --- mesh_bot.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index e2182b2..6078db2 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -144,22 +144,16 @@ def handle_motd(message, message_from_id, isDM): # admin help via DM if "?" in message and isDM and isAdmin: msg = "Message of the day, set with 'motd $ HelloWorld!'" - # non-admin help via DM elif "?" in message and isDM and not isAdmin: - msg = "Message of the day, set by Admin." + # non-admin help via DM + msg = "Message of the day" elif "$" in message and isAdmin: motd = message.split("$")[1] MOTD = motd.rstrip() logger.debug(f"System: {message_from_id} changed MOTD: {MOTD}") msg = "MOTD changed to: " + MOTD - # just return the MOTD for non-DM - elif "?" in message: - logger.debug(f"System: {message_from_id} requested MOTD: {MOTD} isAdmin: {isAdmin}") - msg = "MOTD: " + MOTD else: - logger.debug(f"System: {message_from_id} requested MOTD: {MOTD} isAdmin: {isAdmin}") msg = "MOTD: " + MOTD - return msg def handle_wxalert(message_from_id, deviceID, message): From 95e6bc120e80910e4df6783f989e348da0d156d4 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:32:34 -0700 Subject: [PATCH 5/9] Update mesh_bot.py --- mesh_bot.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 6078db2..70dd6c9 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -171,14 +171,13 @@ def handle_wxalert(message_from_id, deviceID, message): def handle_wiki(message, isDM): # location = get_node_location(message_from_id, deviceID) + msg = "Wikipedia search function. \nUsage example:wiki: travelling gnome" if "wiki:" in message.lower(): search = message.split(":")[1] search = search.strip() if search: return get_wikipedia_summary(search) return "Please add a search term example:wiki: travelling gnome" - elif "?" in message and isDM: - msg = "Wikipedia search function. \nUsage example:wiki: travelling gnome" return msg # Runtime Variables for LLM From f628a5e7ef7a44b1a2ce0ef80a5333265b8228fd Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:56:56 -0700 Subject: [PATCH 6/9] Update mesh_bot.py --- mesh_bot.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 70dd6c9..7403614 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -100,17 +100,17 @@ def auto_response(message, snr, rssi, hop, pkiStatus, message_from_id, channel_n def handle_ping(message, hop, snr, rssi, isDM): if "?" in message and isDM: - return message.split("?")[0].title() + " command returns SNR and RSSI, or hopcount from your message. Try adding e.g. @place or #1/3 to your message" + return message.split("?")[0].title() + " command returns SNR and RSSI, or hopcount from your message. Try adding e.g. @place or #tag" msg = "" if "ping" in message.lower(): msg = "🏓PONG, " elif "test" in message.lower() or "testing" in message.lower(): - msg = random.choice(["🎙Testing 1,2,3\n", "🎙Testing\n",\ - "🎙Testing, testing\n",\ - "🎙Ah-wun, ah-two...\n", "🎙 Is this thing on?\n",\ - "🎙Roger that\n",]) + msg = random.choice(["🎙Testing 1,2,3\n", "🎙Testing, ",\ + "🎙Testing, testing, ",\ + "🎙Ah-wun, ah-two... ", "🎙Is this thing on? ",\ + "🎙Roger that! ",]) elif "ack" in message.lower(): msg = random.choice(["✋ACK-ACK!\n", "✋Ack to you!\n"]) else: From e8fa0036e255351ba84c35268762fe5d482edfd8 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 17:57:05 -0700 Subject: [PATCH 7/9] Update mesh_bot.py --- mesh_bot.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index 7403614..f43d8c3 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -171,13 +171,13 @@ def handle_wxalert(message_from_id, deviceID, message): def handle_wiki(message, isDM): # location = get_node_location(message_from_id, deviceID) - msg = "Wikipedia search function. \nUsage example:wiki: travelling gnome" + msg = "Wikipedia search function. \nUsage example:📲wiki: travelling gnome" if "wiki:" in message.lower(): search = message.split(":")[1] search = search.strip() if search: return get_wikipedia_summary(search) - return "Please add a search term example:wiki: travelling gnome" + return "Please add a search term example:📲wiki: travelling gnome" return msg # Runtime Variables for LLM From 27150218986bc54a4c0a15cea92b049e38e838a0 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 18:02:52 -0700 Subject: [PATCH 8/9] Update README.md --- README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 8eed04e..cd904fd 100644 --- a/README.md +++ b/README.md @@ -48,11 +48,11 @@ Any messages that are over 160 characters are chunked into 160 message bytes to - `lheard` returns the last 5 heard nodes with SNR, can also use `sitrep` - `history` returns the last commands ran by user(s) - `cmd` returns the list of commands (the help message) -- Games - - `lemonstand` plays the classic Lemonade Stand Finance game via DM - - `dopewars` plays the classic drug trader game via DM - - `blackjack` BlackJack - - `videopoker` Video Poker +- Games - via DM + - `lemonstand` plays the classic Lemonade Stand Finance + - `dopewars` plays the classic drug trader + - `blackjack` BlackJack, Casino 21 + - `videopoker` Video Poker, basic 5 card hold ## pong_bot.sh Stripped-down bot, mostly around for archive purposes. The mesh-bot enhanced modules can be disabled by config to disable features. From a7f07afc14d2576d433b44cca9cf6b5079ab4cf3 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Thu, 26 Sep 2024 18:13:58 -0700 Subject: [PATCH 9/9] consolidateTime --- mesh_bot.py | 36 ++++++++---------------------------- modules/system.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/mesh_bot.py b/mesh_bot.py index f43d8c3..8f2b396 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -543,22 +543,12 @@ def handle_lheard(message, nodeid, deviceID, isDM): if interface2_enabled: bot_response += " P2:" + str(chutil2) + "%" + "/" + str(airUtilTx2) + "%" # convert uptime to minutes, hours, or days - if uptimeSeconds > 0 or uptimeSeconds2 > 0: - uptimeSeconds = round(uptimeSeconds / 60) - uptimeSeconds2 = round(uptimeSeconds2 / 60) - designator = "m" - if uptimeSeconds > 60 or uptimeSeconds2 > 60: - uptimeSeconds = round(uptimeSeconds / 60) - uptimeSeconds2 = round(uptimeSeconds2 / 60) - designator = "h" - if uptimeSeconds > 24 or uptimeSeconds2 > 24: - uptimeSeconds = round(uptimeSeconds / 24) - uptimeSeconds2 = round(uptimeSeconds2 / 24) - designator = "d" + uptimeSeconds = getPrettyTime(uptimeSeconds) + uptimeSeconds2 = getPrettyTime(uptimeSeconds2) # add uptime and battery info to the bot response - bot_response += "\nUptime:" + str(uptimeSeconds) + designator + bot_response += "\nUptime:" + str(uptimeSeconds) if interface2_enabled: - bot_response += f" P2:" + {uptimeSeconds2} + {designator} + bot_response += f" P2:" + {uptimeSeconds2} if not batteryLevel == 101: bot_response += f" Bat: {batteryLevel}% Volt: {voltage}" if interface2_enabled and not batteryLevel2 == 101: @@ -580,13 +570,8 @@ def handle_history(message, nodeid, deviceID, isDM, lheard=False): # show the last commands from the user to the bot elif not lheard: for i in range(len(cmdHistory)): - prettyTime = round((time.time() - cmdHistory[i]['time']) / 600) * 5 - if prettyTime < 60: - prettyTime = str(prettyTime) + "m" - elif prettyTime < 1440: - prettyTime = str(round(prettyTime/60)) + "h" - else: - prettyTime = str(round(prettyTime/1440)) + "d" + cmdTime = round((time.time() - cmdHistory[i]['time']) / 600) * 5 + prettyTime = getPrettyTime(cmdTime) # history display output if nodeid in bbs_admin_list and cmdHistory[i]['nodeID'] not in lheardCmdIgnoreNode: @@ -606,13 +591,8 @@ def handle_history(message, nodeid, deviceID, isDM, lheard=False): else: # sort the cmdHistory list by time, return the username and time into a new list which used for display for i in range(len(cmdHistory)): - prettyTime = round((time.time() - cmdHistory[i]['time']) / 600) * 5 - if prettyTime < 60: - prettyTime = str(prettyTime) + "m" - elif prettyTime < 1440: - prettyTime = str(round(prettyTime/60)) + "h" - else: - prettyTime = str(round(prettyTime/1440)) + "d" + cmdTime = round((time.time() - cmdHistory[i]['time']) / 600) * 5 + prettyTime = getPrettyTime(cmdTime) if cmdHistory[i]['nodeID'] not in lheardCmdIgnoreNode: # add line to a new list for display diff --git a/modules/system.py b/modules/system.py index 27b2c88..dbfd19b 100644 --- a/modules/system.py +++ b/modules/system.py @@ -586,6 +586,23 @@ def get_wikipedia_summary(search_term): return summary +def getPrettyTime(seconds): + # convert unix time to minutes, hours, or days, or years for simple display + designator = "s" + if seconds > 0: + seconds = round(seconds / 60) + designator = "m" + if seconds > 60: + seconds = round(seconds / 60) + designator = "h" + if seconds > 24: + seconds = round(seconds / 24) + designator = "d" + if seconds > 365: + seconds = round(seconds / 365) + designator = "y" + return str(seconds) + designator + def messageTrap(msg): # 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