Do line wrapping for long messages

This commit is contained in:
Juhani Krekelä 2019-05-06 14:13:13 +03:00
parent 6541323fa6
commit 55e27fd94e
1 changed files with 32 additions and 2 deletions

View File

@ -19,10 +19,40 @@ class GameLoop(threading.Thread):
threading.Thread.__init__(self)
def send(self, message):
self.irc.bot_response(self.irc_chan, message)
message_parts = message.encode().split(b' ')
line = []
line_len = 0
for part in message_parts:
if len(part) + line_len > 440:
self.irc.bot_response(self.irc_chan, b' '.join(line))
line = []
line_len = 0
line.append(part)
line_len += len(part) + 1
if len(line) > 0:
self.irc.bot_response(self.irc_chan, b' '.join(line))
def notice(self, recipient, message):
self.irc.send_raw(b'NOTICE %s :%s' % (recipient.encode(), message.encode()))
recipient = recipient.encode()
message_parts = message.encode().split(b' ')
line = []
line_len = 0
for part in message_parts:
if len(part) + line_len > 440:
self.irc.send_raw(b'NOTICE %s :%s' % (recipient, b' '.join(line)))
line = []
line_len = 0
line.append(part)
line_len += len(part) + 1
if len(line) > 0:
self.irc.send_raw(b'NOTICE %s :%s' % (recipient, b' '.join(line)))
def get_event(self):
event = self.chan.recv()