Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Emit +mode and -mode on mode changes #71

Merged
merged 1 commit into from
Dec 19, 2011
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions docs/API.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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) { }`
Expand Down
11 changes: 10 additions & 1 deletion lib/irc.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
});
Expand Down