diff --git a/config.template b/config.template index e94c846..e5c2063 100644 --- a/config.template +++ b/config.template @@ -351,7 +351,7 @@ surveyRecordLocation=True responseDelay = 2.2 # delay in seconds for splits in messages to avoid message collision /throttling splitDelay = 2.5 -# message chunk size for sending at high success rate, chunkr allows exceeding by 3 characters +# message chunk size in charcters, chunkr allows exceeding by 3 characters MESSAGE_CHUNK_SIZE = 160 # Request Acknowledgement of message OTA wantAck = False diff --git a/mesh_bot.py b/mesh_bot.py index c25ca8e..ae7d280 100755 --- a/mesh_bot.py +++ b/mesh_bot.py @@ -1089,8 +1089,6 @@ def handle_messages(message, deviceID, channel_number, msg_history, publicChanne response = "" header = "📨Messages:" # Calculate safe byte limit (account for header and some overhead) - # Meshtastic has ~237 byte limit, use conservative 200 bytes for message content - max_bytes = 200 header_bytes = len(header.encode('utf-8')) available_bytes = max_bytes - header_bytes diff --git a/modules/bbstools.py b/modules/bbstools.py index b83ad89..2a9aafa 100644 --- a/modules/bbstools.py +++ b/modules/bbstools.py @@ -96,13 +96,15 @@ def bbs_post_message(subject, message, fromNode): if str(fromNode) in bbs_ban_list: logger.warning(f"System: Naughty node {fromNode}, tried to post a message: {subject}, {message} and was dropped.") return "Message posted. ID is: " + str(messageID) - + # validate message length isnt three times the MESSAGE_CHUNK_SIZE + if len(message) > (3 * MESSAGE_CHUNK_SIZE): + return "Message too long, max length is " + str(3 * MESSAGE_CHUNK_SIZE) + " characters." # validate not a duplicate message for msg in bbs_messages: if msg[1].strip().lower() == subject.strip().lower() and msg[2].strip().lower() == message.strip().lower(): messageID = msg[0] return "Message posted. ID is: " + str(messageID) - + # validate its not overlength by keeping in chunker limit # append the message to the list bbs_messages.append([messageID, subject, message, fromNode]) logger.info(f"System: NEW Message Posted, subject: {subject}, message: {message} from {fromNode}") @@ -153,6 +155,14 @@ def bbs_post_dm(toNode, message, fromNode): if str(fromNode) in bbs_ban_list: logger.warning(f"System: Naughty node {fromNode}, tried to post a message: {message} and was dropped.") return "DM Posted for node " + str(toNode) + + # validate message length isnt three times the MESSAGE_CHUNK_SIZE + if len(message) > (3 * MESSAGE_CHUNK_SIZE): + return "Message too long, max length is " + str(3 * MESSAGE_CHUNK_SIZE) + " characters." + # validate not a duplicate message + for msg in bbs_dm: + if msg[0] == int(toNode) and msg[1].strip().lower() == message.strip().lower(): + return "DM Posted for node " + str(toNode) # append the message to the list bbs_dm.append([int(toNode), message, int(fromNode)]) diff --git a/modules/settings.py b/modules/settings.py index 82de6cf..e3eb75b 100644 --- a/modules/settings.py +++ b/modules/settings.py @@ -31,6 +31,7 @@ seenNodes = [] # list to hold the last seen nodes surveyTracker, tictactoeTracker, hamtestTracker, hangmanTracker, golfTracker, mastermindTracker, vpTracker, blackjackTracker, lemonadeTracker, dwPlayerTracker = ([], [], [], [], [], [], [], [], [], []) cmdHistory = [] # list to hold the command history for lheard and history commands msg_history = [] # list to hold the message history for the messages command +max_bytes = 200 # Meshtastic has ~237 byte limit, use conservative 200 bytes for message content # Read the config file, if it does not exist, create basic config file config = configparser.ConfigParser() @@ -384,7 +385,7 @@ try: # messaging settings responseDelay = config['messagingSettings'].getfloat('responseDelay', 0.7) # default 0.7 splitDelay = config['messagingSettings'].getfloat('splitDelay', 0) # default 0 - MESSAGE_CHUNK_SIZE = config['messagingSettings'].getint('MESSAGE_CHUNK_SIZE', 160) # default 160 + MESSAGE_CHUNK_SIZE = config['messagingSettings'].getint('MESSAGE_CHUNK_SIZE', 160) # default 160 chars wantAck = config['messagingSettings'].getboolean('wantAck', False) # default False maxBuffer = config['messagingSettings'].getint('maxBuffer', 200) # default 200 enableHopLogs = config['messagingSettings'].getboolean('enableHopLogs', False) # default False