rj1
about | log | files | refs | license
commit fd8c2d7a2bf6c3d9af82f745fd3e50dffd606c3e
parent 0a77ce3274bd4f063230483b40bafb4be10cc344
author: rj1 <[email protected]>
date:   Thu,  8 Dec 2022 00:52:38 -0600

split outgoing messages in a more readable format

Diffstat:
Mchatgpt-irc.py | 16+++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/chatgpt-irc.py b/chatgpt-irc.py @@ -201,15 +201,25 @@ async def main_loop(**options): prompt = " ".join(prompt) lines = chatgpt.prompt(prompt) - messages = [] + messages = [] for line in lines: if len(line) > 350: - messages.append(line[:350]) - messages.append(line[350:]) + words = line.split(' ') + current_message = '' + for word in words: + if len(current_message) + len(word) + 1 <= 350: + current_message += word + ' ' + else: + messages.append(current_message) + current_message = word + ' ' + messages.append(current_message) else: messages.append(line) + while "" in messages: + messages.remove("") + for i, message in enumerate(messages): if i == 0: message = f"{source}: {message}"