mirror of
https://github.com/SpudGunMan/meshing-around.git
synced 2026-08-08 18:03:33 +02:00
enhanceChunkr
better logic?
This commit is contained in:
+1
-1
@@ -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
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user