function IrcChannel(irc_connection, name) {
+ var that = this;
+
this.irc_connection = irc_connection;
this.name = name;
// Helper for binding listeners
function bindEvent(event, fn) {
- irc_connection.on('channel:' + name + ':' + event, fn);
+ irc_connection.on('channel:' + name + ':' + event, function () {
+ fn.apply(that, arguments);
+ });
}
bindEvent('join', this.onJoin);
bindEvent('privmsg', this.onMsg);
bindEvent('notice', this.onNotice);
bindEvent('ctcp', this.onCtcp);
+
+ bindEvent('nicklist', this.onNicklist);
+ bindEvent('nicklistEnd', this.onNicklistEnd);
}
-// TODO: Move this into irc_connection
-ircChannel.prototype.clientEvent = function (event_name, event) {
+IrcChannel.prototype.clientEvent = function (event_name, event) {
event.server = this.irc_connection.con_num;
- this.client.sendIrcCommand(event_name, event);
+ this.irc_connection.state.sendIrcCommand(event_name, event);
};
IrcChannel.prototype.onJoin = function (event) {
this.clientEvent('join', {
channel: this.name,
- nick: command.nick,
- ident: command.ident,
- hostname: command.hostname,
+ nick: event.nick,
+ ident: event.ident,
+ hostname: event.hostname,
});
// If we've just joined this channel then requesr=t get a nick list
};
-IrcChannel.prototype.removeUser = function (event) {
- type = type || 'part';
+IrcChannel.prototype.onPart = function (event) {
+ this.clientEvent('part', {
+ nick: event.nick,
+ ident: event.ident,
+ hostname: event.hostname,
+ channel: this.name,
+ message: event.message
+ });
+};
- this.emit('')
-}
+
+IrcChannel.prototype.onKick = function (event) {
+ this.client.sendIrcCommand('kick', {
+ kicked: event.params[1], // Nick of the kicked
+ nick: event.nick, // Nick of the kicker
+ ident: event.ident,
+ hostname: event.hostname,
+ channel: this.name,
+ message: event.message
+ });
+};
+IrcChannel.prototype.onQuit = function (event) {
+ this.clientEvent('quit', {
+ nick: event.nick,
+ ident: event.ident,
+ hostname: event.hostname,
+ message: event.message
+ });
+};
+
+
+IrcChannel.prototype.onMsg = function (event) {
+ this.clientEvent('msg', {
+ server: this.con_num,
+ nick: event.nick,
+ ident: event.ident,
+ hostname: event.hostname,
+ channel: this.name,
+ msg: event.message
+ });
+};
+
+
+IrcChannel.prototype.onNotice = function (event) {
+ this.clientEvent('msg', {
+ server: this.con_num,
+ nick: event.nick,
+ ident: event.ident,
+ hostname: event.hostname,
+ channel: this.name,
+ msg: event.trailing
+ });
+};
+
+
+IrcChannel.prototype.onCtcp = function (event) {
+ this.clientEvent('ctcp_request', {
+ nick: event.nick,
+ ident: event.ident,
+ hostname: event.hostname,
+ target: event.target,
+ type: event.type,
+ msg: event.msg
+ });
+};
+
+
+// TODO: Split event.users into batches of 50
+IrcChannel.prototype.onNicklist = function (event) {
+ this.clientEvent('userlist', {
+ users: event.users,
+ channel: this.name
+ });
+};
+
+
+IrcChannel.prototype.onNicklistEnd = function (event) {
+ this.clientEvent('userlist_end', {
+ users: event.users,
+ channel: this.name
+ });
+};
+
/*
server:event
server:*
user:event
user:*
-
Server disconnected:
server:disconnect
server:*
Private message:
user:privmsg
user:*
-
*/
\ No newline at end of file
channel = command.params[0];
}
- this.client.sendIrcCommand('join', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: channel});
-
- if (command.nick === this.nick) {
- this.irc_connection.write('NAMES ' + channel);
- }
+ this.irc_connection.emit('channel:' + channel + ':join');
},
'PART': function (command) {
this.client.sendIrcCommand('part', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], message: command.trailing});
} else if (command.trailing.substr(1, 10) === 'CLIENTINFO') {
this.irc_connection.write('NOTICE ' + command.nick + ' :' + String.fromCharCode(1) + 'CLIENTINFO SOURCE VERSION TIME' + String.fromCharCode(1));
} else {
- this.client.sendIrcCommand('ctcp_request', {
- server: this.con_num,
+ this.irc_connection.emit('channel:' + command.params[0] + ':ctcp', {
nick: command.nick,
ident: command.ident,
hostname: command.hostname,
});
}
} else {
- //{nick: msg.nick, ident: msg.ident, hostname: msg.hostname, channel: msg.params.trim(), msg: msg.trailing}
- this.client.sendIrcCommand('msg', {server: this.con_num, nick: command.nick, ident: command.ident, hostname: command.hostname, channel: command.params[0], msg: command.trailing});
+ this.irc_connection.emit('channel:' + command.params[0] + ':privmsg', {
+ nick: command.nick,
+ ident: command.ident,
+ hostname: command.hostname,
+ channel: command.params[0],
+ msg: command.trailing
+ });
}
},
'CAP': function (command) {