1 var util
= require('util'),
2 EventBinder
= require('./eventbinder.js');
4 function IrcChannel(irc_connection
, name
) {
5 this.irc_connection
= irc_connection
;
9 this.ban_list_buffer
= [];
11 // Listen for events on the IRC connection
19 ctcp_request
: onCtcpRequest
,
20 ctcp_response
: onCtcpResponse
,
23 nicklistEnd
: onNicklistEnd
,
25 banlist_end
: onBanListEnd
,
26 topicsetby
: onTopicSetby
,
29 EventBinder
.bindIrcEvents('channel:' + this.name
, this.irc_events
, this, irc_connection
);
33 module
.exports
= IrcChannel
;
36 IrcChannel
.prototype.dispose = function (){
37 EventBinder
.unbindIrcEvents('channel:' + this.name
, this.irc_events
);
38 this.irc_connection
= undefined;
43 function onJoin(event
) {
44 this.irc_connection
.clientEvent('join', {
48 hostname
: event
.hostname
,
51 // If we've just joined this channel then request get a nick list
52 if (event
.nick
=== this.irc_connection
.nick
) {
53 this.irc_connection
.write('NAMES ' + channel
);
58 function onPart(event
) {
59 this.irc_connection
.clientEvent('part', {
62 hostname
: event
.hostname
,
64 message
: event
.message
71 function onKick(event
) {
72 this.irc_connection
.clientEvent('kick', {
73 kicked
: event
.kicked
, // Nick of the kicked
74 nick
: event
.nick
, // Nick of the kicker
76 hostname
: event
.hostname
,
78 message
: event
.message
85 function onQuit(event
) {
86 this.irc_connection
.clientEvent('quit', {
89 hostname
: event
.hostname
,
90 message
: event
.message
97 function onMsg(event
) {
98 this.irc_connection
.clientEvent('msg', {
101 hostname
: event
.hostname
,
108 function onNotice(event
) {
109 this.irc_connection
.clientEvent('msg', {
112 hostname
: event
.hostname
,
119 function onCtcpRequest(event
) {
120 this.irc_connection
.clientEvent('ctcp_request', {
123 hostname
: event
.hostname
,
124 target
: event
.target
,
131 function onCtcpResponse(event
) {
132 this.irc_connection
.clientEvent('ctcp_response', {
135 hostname
: event
.hostname
,
136 target
: event
.target
,
143 // TODO: Split event.users into batches of 50
144 function onNicklist(event
) {
145 this.irc_connection
.clientEvent('userlist', {
152 function onNicklistEnd(event
) {
153 this.irc_connection
.clientEvent('userlist_end', {
160 function onTopic(event
) {
161 this.irc_connection
.clientEvent('topic', {
169 function onBanList(event
) {
170 this.ban_list_buffer
.push(event
);
173 function onBanListEnd(event
) {
175 this.ban_list_buffer
.forEach(function (ban
) {
176 that
.irc_connection
.clientEvent('banlist', ban
);
178 this.ban_list_buffer
= [];
181 function onTopic(event
) {
182 this.irc_connection
.clientEvent('topic', {
183 channel
: event
.channel
,
188 function onTopicSetBy(event
) {
189 this.irc_connection
.clientEvent('topicsetby', {
191 channel
: event
.channel
,
196 function onMode(event
) {
197 this.irc_connection
.clientEvent('mode', {
198 target
: event
.target
,
208 channel:#channel:event
217 Joining channel #kiwiirc:
218 channel:#kiwiirc:join
222 channel:#kiwiirc:privmsg