diff --git a/botcmd.py b/botcmd.py index 66da556..7df6153 100644 --- a/botcmd.py +++ b/botcmd.py @@ -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()