Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Emit +mode and -mode on mode changes #71

Merged
merged 1 commit into from

2 participants

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 22, 2011
  1. @alexwhitman
This page is out of date. Refresh to see the latest.
Showing with 34 additions and 1 deletion.
  1. +24 −0 docs/API.rst
  2. +10 −1 lib/irc.js
View
24 docs/API.rst
@@ -281,6 +281,30 @@ Events
Emitted when the client recieves an `/invite`. See the `raw` event for details
on the `message` object.
+.. js:data:: '+mode'
+
+ `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`
+ is the single character mode indentifier. If the mode is being set on a user,
+ `argument` is the nick of the user. If the mode is being set on a channel,
+ `argument` is the argument to the mode. If a channel mode doesn't have any
+ arguments, `argument` will be 'undefined'. See the `raw` event for details
+ on the `message` object.
+
+.. js:data:: '-mode'
+
+ `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`
+ is the single character mode indentifier. If the mode is being set on a user,
+ `argument` is the nick of the user. If the mode is being set on a channel,
+ `argument` is the argument to the mode. If a channel mode doesn't have any
+ arguments, `argument` will be 'undefined'. See the `raw` event for details
+ on the `message` object.
+
.. js:data:: 'whois'
`function (info) { }`
View
11 lib/irc.js
@@ -143,23 +143,32 @@ function Client(server, nick, opt) {
if ( adding ) {
if ( channel.users[user].indexOf(self.prefixForMode[mode]) === -1 )
channel.users[user] += self.prefixForMode[mode];
+
+ self.emit('+mode', message.args[0], message.nick, mode, user, message);
}
else {
channel.users[user] = channel.users[user].replace(self.prefixForMode[mode], '');
+ self.emit('-mode', message.args[0], message.nick, mode, user, message);
}
}
else {
var modeArg;
// channel modes
- if ( mode.match(/^[bkl]$/) )
+ if ( mode.match(/^[bkl]$/) ) {
modeArg = modeArgs.shift();
+ if ( modeArg.length === 0 )
+ modeArg = undefined;
+ }
// TODO - deal nicely with channel modes that take args
if ( adding ) {
if ( channel.mode.indexOf(mode) === -1 )
channel.mode += mode;
+
+ self.emit('+mode', message.args[0], message.nick, mode, modeArg, message);
}
else {
channel.mode = channel.mode.replace(mode, '');
+ self.emit('-mode', message.args[0], message.nick, mode, modeArg, message);
}
}
});
Something went wrong with that request. Please try again.