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 @@ try: 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