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
,
31 EventBinder
.bindIrcEvents('channel ' + this.name
, this.irc_events
, this, irc_connection
);
35 module
.exports
= IrcChannel
;
38 IrcChannel
.prototype.dispose = function (){
39 EventBinder
.unbindIrcEvents('channel ' + this.name
, this.irc_events
, this.irc_connection
);
40 this.irc_connection
= undefined;
45 function onJoin(event
) {
46 this.irc_connection
.clientEvent('join', {
50 hostname
: event
.hostname
,
56 function onPart(event
) {
57 this.irc_connection
.clientEvent('part', {
60 hostname
: event
.hostname
,
62 message
: event
.message
,
68 function onKick(event
) {
69 this.irc_connection
.clientEvent('kick', {
70 kicked
: event
.kicked
, // Nick of the kicked
71 nick
: event
.nick
, // Nick of the kicker
73 hostname
: event
.hostname
,
75 message
: event
.message
,
81 function onQuit(event
) {
82 this.irc_connection
.clientEvent('quit', {
85 hostname
: event
.hostname
,
86 message
: event
.message
,
92 function onMsg(event
) {
93 this.irc_connection
.clientEvent('msg', {
96 hostname
: event
.hostname
,
104 function onNotice(event
) {
105 this.irc_connection
.clientEvent('notice', {
106 from_server
: event
.from_server
,
109 hostname
: event
.hostname
,
110 target
: event
.target
,
117 function onCtcpRequest(event
) {
118 this.irc_connection
.clientEvent('ctcp_request', {
121 hostname
: event
.hostname
,
122 target
: event
.target
,
130 function onCtcpResponse(event
) {
131 this.irc_connection
.clientEvent('ctcp_response', {
134 hostname
: event
.hostname
,
135 target
: event
.target
,
143 // TODO: Split event.users into batches of 50
144 function onNicklist(event
) {
145 this.irc_connection
.clientEvent('userlist', {
149 // TODO: uncomment when using an IrcUser per nick
150 //updateUsersList.call(this, event.users);
154 function onNicklistEnd(event
) {
155 this.irc_connection
.clientEvent('userlist_end', {
159 // TODO: uncomment when using an IrcUser per nick
160 //updateUsersList.call(this, event.users);
163 function updateUsersList(users
) {
166 users
.forEach(function (user
) {
167 if (!that
.irc_connection
.irc_users
[user
.nick
]) {
168 that
.irc_connection
.irc_users
[user
.nick
] = new IrcUser(that
.irc_connection
, user
.nick
);
175 function onTopic(event
) {
176 this.irc_connection
.clientEvent('topic', {
185 function onChannelInfo(event
) {
186 // Channel info event may contain 1 of several types of info,
187 // including creation time, modes. So just pipe the event
188 // right through to the client
189 this.irc_connection
.clientEvent('channel_info', event
);
193 function onBanList(event
) {
194 this.ban_list_buffer
.push(event
);
197 function onBanListEnd(event
) {
198 this.irc_connection
.clientEvent('banlist', {
200 bans
: this.ban_list_buffer
203 this.ban_list_buffer
= [];
206 function onTopic(event
) {
207 this.irc_connection
.clientEvent('topic', {
208 channel
: event
.channel
,
213 function onTopicSetBy(event
) {
214 this.irc_connection
.clientEvent('topicsetby', {
216 channel
: event
.channel
,
221 function onMode(event
) {
222 this.irc_connection
.clientEvent('mode', {
223 target
: event
.target
,