enhanceChunkr

better logic?
This commit is contained in:
SpudGunMan
2024-12-06 12:59:46 -08:00
parent 92e1e3168e
commit 41d8758969
2 changed files with 23 additions and 6 deletions
+1 -1
View File
@@ -158,7 +158,7 @@ news_file_path = news.txt
responseDelay = 0.7
# delay in seconds for splits in messages to avoid message collision
splitDelay = 0.0
# message chunk size for sending at high success rate
# message chunk size for sending at high success rate, chunkr allows exceeding by 3 characters
MESSAGE_CHUNK_SIZE = 160
# Request Acknowledgement of message OTA
wantAck = False
+22 -5
View File
@@ -427,22 +427,39 @@ def messageChunker(message):
else:
# split the part into chunks
current_chunk = ''
sentences = part.split('. ')
sentences = []
sentence = ''
for char in part:
sentence += char
if char in '.!?':
sentences.append(sentence.strip())
sentence = ''
if sentence:
sentences.append(sentence.strip())
for sentence in sentences:
sentence = sentence.strip()
sentence = sentence.replace(' ', ' ')
# remove empty sentences
if not sentence:
continue
# remove junk sentences and append to the previous sentence this may exceed the MESSAGE_CHUNK_SIZE by 3
if len(sentence) < 4:
if current_chunk:
current_chunk += ' ' + sentence
else:
current_chunk = sentence
continue
# if sentence is too long, split it by words
if len(current_chunk) + len(sentence) > MESSAGE_CHUNK_SIZE:
message_list.append(current_chunk)
if current_chunk:
message_list.append(current_chunk)
current_chunk = sentence
else:
if current_chunk:
current_chunk += ' '
current_chunk += sentence
current_chunk += ' ' + sentence
else:
current_chunk = sentence
if current_chunk:
message_list.append(current_chunk)