1 var util
= require('util'),
2 EventBinder
= require('./eventbinder.js'),
3 IrcUser
= require('./user.js');
5 var IrcChannel = function(irc_connection
, name
) {
6 this.irc_connection
= irc_connection
;
10 this.ban_list_buffer
= [];
12 // Listen for events on the IRC connection
20 ctcp_request
: onCtcpRequest
,
21 ctcp_response
: onCtcpResponse
,
24 userlist_end
: onNicklistEnd
,
26 banlist_end
: onBanListEnd
,
27 topicsetby
: onTopicSetBy
,
30 EventBinder
.bindIrcEvents('channel ' + this.name
, this.irc_events
, this, irc_connection
);
34 module
.exports
= IrcChannel
;
37 IrcChannel
.prototype.dispose = function (){
38 EventBinder
.unbindIrcEvents('channel ' + this.name
, this.irc_events
, this.irc_connection
);
39 this.irc_connection
= undefined;
44 function onJoin(event
) {
45 this.irc_connection
.clientEvent('join', {
49 hostname
: event
.hostname
,
53 // If we've just joined this channel then request get a nick list
54 if (event
.nick
=== this.irc_connection
.nick
) {
55 this.irc_connection
.write('NAMES ' + this.name
);
60 function onPart(event
) {
61 this.irc_connection
.clientEvent('part', {
64 hostname
: event
.hostname
,
66 message
: event
.message
,
72 function onKick(event
) {
73 this.irc_connection
.clientEvent('kick', {
74 kicked
: event
.kicked
, // Nick of the kicked
75 nick
: event
.nick
, // Nick of the kicker
77 hostname
: event
.hostname
,
79 message
: event
.message
,
85 function onQuit(event
) {
86 this.irc_connection
.clientEvent('quit', {
89 hostname
: event
.hostname
,
90 message
: event
.message
,
96 function onMsg(event
) {
97 this.irc_connection
.clientEvent('msg', {
100 hostname
: event
.hostname
,
108 function onNotice(event
) {
109 this.irc_connection
.clientEvent('notice', {
110 from_server
: event
.from_server
,
113 hostname
: event
.hostname
,
114 target
: event
.target
,
121 function onCtcpRequest(event
) {
122 this.irc_connection
.clientEvent('ctcp_request', {
125 hostname
: event
.hostname
,
126 target
: event
.target
,
134 function onCtcpResponse(event
) {
135 this.irc_connection
.clientEvent('ctcp_response', {
138 hostname
: event
.hostname
,
139 target
: event
.target
,
147 // TODO: Split event.users into batches of 50
148 function onNicklist(event
) {
149 this.irc_connection
.clientEvent('userlist', {
153 // TODO: uncomment when using an IrcUser per nick
154 //updateUsersList.call(this, event.users);
158 function onNicklistEnd(event
) {
159 this.irc_connection
.clientEvent('userlist_end', {
163 // TODO: uncomment when using an IrcUser per nick
164 //updateUsersList.call(this, event.users);
167 function updateUsersList(users
) {
170 users
.forEach(function (user
) {
171 if (!that
.irc_connection
.irc_users
[user
.nick
]) {
172 that
.irc_connection
.irc_users
[user
.nick
] = new IrcUser(that
.irc_connection
, user
.nick
);
179 function onTopic(event
) {
180 this.irc_connection
.clientEvent('topic', {
189 function onBanList(event
) {
190 this.ban_list_buffer
.push(event
);
193 function onBanListEnd(event
) {
195 this.ban_list_buffer
.forEach(function (ban
) {
196 that
.irc_connection
.clientEvent('banlist', ban
);
198 this.ban_list_buffer
= [];
201 function onTopic(event
) {
202 this.irc_connection
.clientEvent('topic', {
203 channel
: event
.channel
,
208 function onTopicSetBy(event
) {
209 this.irc_connection
.clientEvent('topicsetby', {
211 channel
: event
.channel
,
216 function onMode(event
) {
217 this.irc_connection
.clientEvent('mode', {
218 target
: event
.target
,