From e115f33d4735d6bca471aa9c18196afd7d4435c5 Mon Sep 17 00:00:00 2001 From: SpudGunMan Date: Fri, 13 Dec 2024 10:07:14 -0800 Subject: [PATCH] =?UTF-8?q?pingEnhancments=F0=9F=8F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit added autoPingInChannel = False # Allows auto-ping feature in a channel, False forces DM also added node short name to all channel ping --- config.template | 2 ++ mesh_bot.py | 47 +++++++++++++++++++++++++++------------------ modules/settings.py | 1 + pong_bot.py | 47 +++++++++++++++++++++++++++------------------ 4 files changed, 59 insertions(+), 38 deletions(-) diff --git a/config.template b/config.template index 75a7dd9..4d3abd9 100644 --- a/config.template +++ b/config.template @@ -25,6 +25,8 @@ port = /dev/ttyUSB0 [general] # if False will respond on all channels but the default channel respond_by_dm_only = True +# Allows auto-ping feature in a channel, False forces DM +autoPingInChannel = False # defaultChannel is the meshtastic default public channel, e.g. LongFast (if none use -1) defaultChannel = 0 # ignoreDefaultChannel, the bot will ignore the default channel set above diff --git a/mesh_bot.py b/mesh_bot.py index c58f528..cd13b6d 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -172,6 +172,7 @@ def handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, chann msg = msg + " #" + message.split("#")[1] type = type + " #" + message.split("#")[1] + # check for multi ping request if " " in message: # if stop multi ping @@ -181,27 +182,35 @@ def handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, chann multiPingList.pop(i) msg = "🛑 auto-ping" - # if 3 or more entries (2 or more active), throttle the multi-ping for congestion - if len(multiPingList) > 2: - msg = "🚫⛔️ auto-ping, service busy. ⏳Try again soon." - pingCount = -1 - else: - # set inital pingCount - try: - pingCount = int(message.split(" ")[1]) - if pingCount == 123 or pingCount == 1234: - pingCount = 1 - if pingCount > 51: - pingCount = 50 - except: + # disabled in channel + if autoPingInChannel and not isDM: + # if 3 or more entries (2 or more active), throttle the multi-ping for congestion + if len(multiPingList) > 2: + msg = "🚫⛔️ auto-ping, service busy. ⏳Try again soon." pingCount = -1 - - if pingCount > 1: - multiPingList.append({'message_from_id': message_from_id, 'count': pingCount + 1, 'type': type, 'deviceID': deviceID, 'channel_number': channel_number, 'startCount': pingCount}) - if type == "🎙TEST": - msg = f"🛜Initalizing BufferTest, using chunks of about {int(maxBuffer // pingCount)}, max length {maxBuffer} in {pingCount} messages" else: - msg = f"🚦Initalizing {pingCount} auto-ping" + # set inital pingCount + try: + pingCount = int(message.split(" ")[1]) + if pingCount == 123 or pingCount == 1234: + pingCount = 1 + if pingCount > 51: + pingCount = 50 + except: + pingCount = -1 + + if pingCount > 1: + multiPingList.append({'message_from_id': message_from_id, 'count': pingCount + 1, 'type': type, 'deviceID': deviceID, 'channel_number': channel_number, 'startCount': pingCount}) + if type == "🎙TEST": + msg = f"🛜Initalizing BufferTest, using chunks of about {int(maxBuffer // pingCount)}, max length {maxBuffer} in {pingCount} messages" + else: + msg = f"🚦Initalizing {pingCount} auto-ping" + else: + msg = "🔊AutoPing via DM only⛔️" + + # if not a DM add the username to the beginning of msg + if not isDM: + msg = get_name_from_number(message_from_id) + msg return msg diff --git a/modules/settings.py b/modules/settings.py index fbfc576..78de685 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -122,6 +122,7 @@ welcome_message = (f"{welcome_message}").replace('\\n', '\n') # allow for newlines in the welcome message motd_enabled = config['general'].getboolean('motdEnabled', True) MOTD = config['general'].get('motd', MOTD) + autoPingInChannel = config['general'].getboolean('autoPingInChannel', False) enableCmdHistory = config['general'].getboolean('enableCmdHistory', True) lheardCmdIgnoreNode = config['general'].get('lheardCmdIgnoreNode', '').split(',') whoami_enabled = config['general'].getboolean('whoami', True) diff --git a/pong_bot.py b/pong_bot.py index 4f98017..a603faa 100755 --- a/pong_bot.py +++ b/pong_bot.py @@ -90,6 +90,7 @@ def handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, chann msg = msg + " #" + message.split("#")[1] type = type + " #" + message.split("#")[1] + # check for multi ping request if " " in message: # if stop multi ping @@ -99,27 +100,35 @@ def handle_ping(message_from_id, deviceID, message, hop, snr, rssi, isDM, chann multiPingList.pop(i) msg = "🛑 auto-ping" - # if 3 or more entries (2 or more active), throttle the multi-ping for congestion - if len(multiPingList) > 2: - msg = "🚫⛔️ auto-ping, service busy. ⏳Try again soon." - pingCount = -1 - else: - # set inital pingCount - try: - pingCount = int(message.split(" ")[1]) - if pingCount == 123 or pingCount == 1234: - pingCount = 1 - if pingCount > 51: - pingCount = 50 - except: + # disabled in channel + if autoPingInChannel and not isDM: + # if 3 or more entries (2 or more active), throttle the multi-ping for congestion + if len(multiPingList) > 2: + msg = "🚫⛔️ auto-ping, service busy. ⏳Try again soon." pingCount = -1 - - if pingCount > 1: - multiPingList.append({'message_from_id': message_from_id, 'count': pingCount + 1, 'type': type, 'deviceID': deviceID, 'channel_number': channel_number, 'startCount': pingCount}) - if type == "🎙TEST": - msg = f"🛜Initalizing BufferTest, using chunks of about {int(maxBuffer // pingCount)}, max length {maxBuffer} in {pingCount} messages" else: - msg = f"🚦Initalizing {pingCount} auto-ping" + # set inital pingCount + try: + pingCount = int(message.split(" ")[1]) + if pingCount == 123 or pingCount == 1234: + pingCount = 1 + if pingCount > 51: + pingCount = 50 + except: + pingCount = -1 + + if pingCount > 1: + multiPingList.append({'message_from_id': message_from_id, 'count': pingCount + 1, 'type': type, 'deviceID': deviceID, 'channel_number': channel_number, 'startCount': pingCount}) + if type == "🎙TEST": + msg = f"🛜Initalizing BufferTest, using chunks of about {int(maxBuffer // pingCount)}, max length {maxBuffer} in {pingCount} messages" + else: + msg = f"🚦Initalizing {pingCount} auto-ping" + else: + msg = "🔊AutoPing via DM only⛔️" + + # if not a DM add the username to the beginning of msg + if not isDM: + msg = get_name_from_number(message_from_id) + msg return msg