Skip to content

Commit

Permalink
split messages into lines before splitting on words when sending a me…
Browse files Browse the repository at this point in the history
…ssage
  • Loading branch information
prawnsalad committed Feb 26, 2020
1 parent 1bbf58c commit 24be97d
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/client.js
Expand Up @@ -377,18 +377,24 @@ module.exports = class IrcClient extends EventEmitter {
}

sendMessage(commandName, target, message) {
var that = this;

// Maximum length of target + message we can send to the IRC server is 500 characters
// but we need to leave extra room for the sender prefix so the entire message can
// be sent from the IRCd to the target without being truncated.
var blocks = [...lineBreak(message, { bytes: this.options.message_max_length, allowBreakingWords: true, allowBreakingGraphemes: true })];

blocks.forEach(function(block) {
that.raw(commandName, target, block);
let lines = message
.split(/\r\n|\n|\r/)
.filter(i=>i);

lines.forEach(line => {
// Maximum length of target + message we can send to the IRC server is 500 characters
// but we need to leave extra room for the sender prefix so the entire message can
// be sent from the IRCd to the target without being truncated.
let blocks = [
...lineBreak(line, {
bytes: this.options.message_max_length,
allowBreakingWords: true,
allowBreakingGraphemes: true,
})
];

blocks.forEach(block => this.raw(commandName, target, block));
});

return blocks;
}

say(target, message) {
Expand Down

0 comments on commit 24be97d

Please sign in to comment.