Skip to content

Commit 24be97d

Browse files
committed
split messages into lines before splitting on words when sending a message
1 parent 1bbf58c commit 24be97d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

src/client.js

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -377,18 +377,24 @@ module.exports = class IrcClient extends EventEmitter {
377377
}
378378

379379
sendMessage(commandName, target, message) {
380-
var that = this;
381-
382-
// Maximum length of target + message we can send to the IRC server is 500 characters
383-
// but we need to leave extra room for the sender prefix so the entire message can
384-
// be sent from the IRCd to the target without being truncated.
385-
var blocks = [...lineBreak(message, { bytes: this.options.message_max_length, allowBreakingWords: true, allowBreakingGraphemes: true })];
386-
387-
blocks.forEach(function(block) {
388-
that.raw(commandName, target, block);
380+
let lines = message
381+
.split(/\r\n|\n|\r/)
382+
.filter(i=>i);
383+
384+
lines.forEach(line => {
385+
// Maximum length of target + message we can send to the IRC server is 500 characters
386+
// but we need to leave extra room for the sender prefix so the entire message can
387+
// be sent from the IRCd to the target without being truncated.
388+
let blocks = [
389+
...lineBreak(line, {
390+
bytes: this.options.message_max_length,
391+
allowBreakingWords: true,
392+
allowBreakingGraphemes: true,
393+
})
394+
];
395+
396+
blocks.forEach(block => this.raw(commandName, target, block));
389397
});
390-
391-
return blocks;
392398
}
393399

394400
say(target, message) {

0 commit comments

Comments
 (0)