Skip to content

Commit f019562

Browse files
authored
Merge pull request #385 from LinuxMercedes/message-split
Respect opt.messageSplit when calculating message length
2 parents 7468a39 + ddbacc6 commit f019562

3 files changed

Lines changed: 37 additions & 1 deletion

File tree

lib/irc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1066,7 +1066,7 @@ Client.prototype.notice = function(target, text) {
10661066

10671067
Client.prototype._speak = function(kind, target, text) {
10681068
var self = this;
1069-
var maxLength = this.maxLineLength - target.length;
1069+
var maxLength = Math.min(this.maxLineLength - target.length, this.opt.messageSplit);
10701070
if (typeof text !== 'undefined') {
10711071
text.toString().split(/\r?\n/).filter(function(line) {
10721072
return line.length > 0;

test/data/fixtures.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,5 +183,15 @@
183183
"input": "abcdefghijklmnopqrstuvwxyz",
184184
"result": ["abcdefghijklmnopqrstuvwxyz"]
185185
}
186+
],
187+
"_speak": [
188+
{
189+
"length": 30,
190+
"expected": 10
191+
},
192+
{
193+
"length": 7,
194+
"expected": 1
195+
}
186196
]
187197
}

test/test-irc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,3 +104,29 @@ test ('splitting of long lines with no maxLength defined.', function(t) {
104104
});
105105
mock.close();
106106
});
107+
108+
test ('opt.messageSplit used when set', function(t) {
109+
var port = 6667;
110+
var mock = testHelpers.MockIrcd(port, 'utf-8', false);
111+
var client = new irc.Client('localhost', 'testbot', {
112+
secure: false,
113+
selfSigned: true,
114+
port: port,
115+
retryCount: 0,
116+
debug: true,
117+
messageSplit: 10
118+
});
119+
120+
var group = testHelpers.getFixtures('_speak');
121+
t.plan(group.length);
122+
group.forEach(function(item) {
123+
client.maxLineLength = item.length;
124+
client._splitLongLines = function(words, maxLength, destination) {
125+
t.equal(maxLength, item.expected);
126+
return [words];
127+
}
128+
client._speak('kind', 'target', 'test message');
129+
});
130+
131+
mock.close();
132+
});

0 commit comments

Comments
 (0)