Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix length issues when sending long messages #142

Closed
wants to merge 4 commits into from

4 participants

@qsheets

Fixes missing message parts when sending long PRIVMSG lines (incl. ACTIONs). Also, maintains 'userhost' string through nick and host mask changes.

@qsheets qsheets Fix length issues when sending long messages
Fixes missing message parts when sending long PRIVMSG lines (incl.
ACTIONs). Also, maintains 'userhost' string through nick and host mask
changes.
fa15d40
@martynsmith
Owner

This looks okay, but it seems it won't merge cleanly now, if you could tidy that up I'm happy to merge.

As an aside, I think it'd be quite nice perhaps if you detected multiple lines for an action and at least logged some sort of warning (e.g. "You tried to send an action with multiple lines, only the first was used").

@apeiron
Collaborator

Hey @qsheets, would you be able to fix this pull req so it can be merged, or possibly look at mine (#268) and see if you can determine which you think works better? I'm obviously biased towards mine but I want input from you too.

@jirwin
Collaborator

Closing this as #268 was merged.

@jirwin jirwin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 24, 2013
  1. @qsheets

    Fix length issues when sending long messages

    qsheets authored
    Fixes missing message parts when sending long PRIVMSG lines (incl.
    ACTIONs). Also, maintains 'userhost' string through nick and host mask
    changes.
Commits on Sep 7, 2013
  1. @qsheets
  2. @qsheets
  3. @qsheets

    Minor Formatting

    qsheets authored
    Tabs to spaces
This page is out of date. Refresh to see the latest.
Showing with 46 additions and 16 deletions.
  1. +7 −6 docs/API.rst
  2. +4 −0 lib/codes.js
  3. +35 −10 lib/irc.js
View
13 docs/API.rst
@@ -32,7 +32,7 @@ Client
sasl: false,
stripColors: false,
channelPrefixes: "&#",
- messageSplit: 512
+ messageLength: 512
}
`secure` (SSL connection) can be a true value or an object (the kind of object
@@ -51,14 +51,15 @@ Client
Set `sasl` to true to enable SASL support. You'll also want to set `nick`,
`userName`, and `password` for authentication.
+ `messageLength` sets the character length at which messages sent with `msg` will
+ be split into multiple messages. This value should not be changed unless the
+ server explicitly indicates another value.
+
`stripColors` removes mirc colors (0x03 followed by one or two ascii
numbers for foreground,background) and ircII "effect" codes (0x02
bold, 0x1f underline, 0x16 reverse, 0x0f reset) from the entire
message before parsing it and passing it along.
- `messageSplit` will split up large messages sent with the `say` method
- into multiple messages of length fewer than `messageSplit` characters.
-
Setting `autoConnect` to false prevents the Client from connecting on
instantiation. You will need to call `connect()` on the client instance::
@@ -356,7 +357,7 @@ Events
.. js:data:: '+mode'
- `function (channel, by, mode, argument, message) { }`
+ `function (channel, by, mode, argument, message) { }`
Emitted when a mode is added to a user or channel. `channel` is the channel
which the mode is being set on/in. `by` is the user setting the mode. `mode`
@@ -368,7 +369,7 @@ Events
.. js:data:: '-mode'
- `function (channel, by, mode, argument, message) { }`
+ `function (channel, by, mode, argument, message) { }`
Emitted when a mode is removed from a user or channel. `channel` is the channel
which the mode is being set on/in. `by` is the user setting the mode. `mode`
View
4 lib/codes.js
@@ -335,6 +335,10 @@ module.exports = { // {{{
"name" : "rpl_nousers",
"type" : "reply"
},
+ "396" : {
+ "name" : "rpl_hosthidden",
+ "type" : "reply"
+ },
"401" : {
"name" : "err_nosuchnick",
"type" : "error"
View
45 lib/irc.js
@@ -51,9 +51,13 @@ function Client(server, nick, opt) {
sasl: false,
stripColors: false,
channelPrefixes: "&#",
- messageSplit: 512
+ messageLength: 512
};
-
+
+ // All lines end with CR-LF (2 chars) plus 2 chars for
+ // server provided padding to be safe.
+ self.opt.messageLength -= 4;
+
// Features supported by the server
// (initial values are RFC 1459 defaults. Zeros signify
// no default or unlimited value)
@@ -100,6 +104,7 @@ function Client(server, nick, opt) {
// (normally this is because you chose something too long and
// the server has shortened it
self.nick = message.args[0];
+ self.whois(self.nick, self._setUserhost);
self.emit('registered', message);
break;
case "rpl_myinfo":
@@ -263,9 +268,11 @@ function Client(server, nick, opt) {
});
break;
case "NICK":
- if ( message.nick == self.nick )
+ if ( message.nick == self.nick ) {
// the user just changed their own nick
self.nick = message.args[0];
+ self.userhost = self.nick+'!'+self.userhost.split('!')[1];
+ }
if ( self.opt.debug )
util.log("NICK: " + message.nick + " changes nick to " + message.args[0]);
@@ -285,6 +292,9 @@ function Client(server, nick, opt) {
// old nick, new nick, channels
self.emit('nick', message.nick, message.args[0], channels, message);
break;
+ case "rpl_hosthidden":
+ self.userhost = self.userhost.split('@')[0]+'@'+message.args[1];
+ break;
case "rpl_motdstart":
self.motd = message.args[1] + "\n";
break;
@@ -784,18 +794,19 @@ Client.prototype.part = function(channel, message, callback) { // {{{
}
if (message) {
- this.send('PART', channel, message);
+ this.send('PART', channel, message);
} else {
- this.send('PART', channel);
+ this.send('PART', channel);
}
} // }}}
Client.prototype.say = function(target, text) { // {{{
var self = this;
if (typeof text !== 'undefined') {
+ var messageSplit = self.opt.messageLength - (12 + target.length + self.userhost.length);
text.toString().split(/\r?\n/).filter(function(line) {
return line.length > 0;
}).forEach(function(line) {
- var r = new RegExp(".{1," + self.opt.messageSplit + "}", "g");
+ var r = new RegExp(".{1," + messageSplit + "}", "g");
while ((messagePart = r.exec(line)) != null) {
self.send('PRIVMSG', target, messagePart[0]);
self.emit('selfMessage', target, messagePart[0]);
@@ -803,14 +814,25 @@ Client.prototype.say = function(target, text) { // {{{
});
}
} // }}}
-Client.prototype.action = function(channel, text) { // {{{
+Client.prototype.action = function(target, text) { // {{{
var self = this;
if (typeof text !== 'undefined') {
- text.toString().split(/\r?\n/).filter(function(line) {
+ var messageSplit = self.opt.messageLength - (21 + target.length + self.userhost.length);
+ var line = text.toString().split(/\r?\n/).filter(function(line) {
return line.length > 0;
- }).forEach(function(line) {
- self.say(channel, '\u0001ACTION ' + line + '\u0001');
});
+
+ // It would be odd to continue an action over multiple lines as
+ // only the first would appear as an actual action. So that is
+ // all we are sending.
+ if (line[0]) {
+ if (line[1]) {
+ util.log("\033[01;31mWARNING: Action over multiple lines, only first line used.\033[0m");
+ }
+ var r = new RegExp(".{1," + messageSplit + "}");
+ line = r.exec(line[0])[0];
+ self.msg(target, '\1ACTION ' + line + '\1');
+ }
}
} // }}}
Client.prototype.notice = function(target, text) { // {{{
@@ -845,6 +867,9 @@ Client.prototype._clearWhoisData = function(nick) { // {{{
delete this._whoisData[nick];
return data;
} // }}}
+Client.prototype._setUserhost = function(info) { // {{{
+ this.userhost = info.nick+'!'+info.user+'@'+info.host;
+} // }}}
Client.prototype._handleCTCP = function(from, to, text, type, message) {
text = text.slice(1)
text = text.slice(0, text.indexOf('\1'))
Something went wrong with that request. Please try again.