diff --git a/irc3/__init__.py b/irc3/__init__.py index 2cd5fe7..f4ec938 100644 --- a/irc3/__init__.py +++ b/irc3/__init__.py @@ -225,14 +225,20 @@ def _send(self, data): def privmsg(self, target, message, nowait=False): """send a privmsg to target""" if message: - messages = utils.split_message(message, self.config.max_length) - if isinstance(target, DCCChat): + is_dcc = isinstance(target, DCCChat) + prefix = '' if is_dcc else 'PRIVMSG %s :' % target + messages = utils.split_message( + message, + self.config.max_length, + prefix=prefix, + ) + if is_dcc: for message in messages: target.send_line(message) elif target: f = None for message in messages: - f = self.send_line('PRIVMSG %s :%s' % (target, message), + f = self.send_line(prefix + message, nowait=nowait) return f @@ -243,14 +249,20 @@ def action(self, target, message, nowait=False): def notice(self, target, message, nowait=False): """send a notice to target""" if message: - messages = utils.split_message(message, self.config.max_length) - if isinstance(target, DCCChat): + is_dcc = isinstance(target, DCCChat) + prefix = '' if is_dcc else 'NOTICE %s :' % target + messages = utils.split_message( + message, + self.config.max_length, + prefix=prefix, + ) + if is_dcc: for message in messages: - target.action(message) + target.send_line(message) elif target: f = None for message in messages: - f = self.send_line('NOTICE %s :%s' % (target, message), + f = self.send_line(prefix + message, nowait=nowait) return f diff --git a/irc3/utils.py b/irc3/utils.py index 4f158f8..13d05a9 100644 --- a/irc3/utils.py +++ b/irc3/utils.py @@ -164,8 +164,9 @@ def tagdict(self): STRIPPED_CHARS = '\t ' -def split_message(message, max_length): +def split_message(message, max_length, prefix=''): """Split long messages""" + max_length = max_length - len(prefix) if len(message) > max_length: for message in textwrap.wrap(message, max_length): yield message diff --git a/tests/test_bot.py b/tests/test_bot.py index 6d14cf5..d8d7505 100644 --- a/tests/test_bot.py +++ b/tests/test_bot.py @@ -41,7 +41,7 @@ def test_message(self): self.assertSent(['PRIVMSG gawel :\x01ACTION does a cool action\x01']) def test_long_message(self): - bot = self.callFTU(max_length=8) + bot = self.callFTU(max_length=23) message = 'How you doing?' bot.privmsg('gawel', message) self.assertSent([