Move the binding into new prototype object
[KiwiIRC.git] / server / irc / channel.js
CommitLineData
2a8d2d5f
JA
1var util = require('util'),
2 Binder = require('./binder.js');
b1fa8101
D
3
4function IrcChannel(irc_connection, name) {
a9833d9c
D
5 this.irc_connection = irc_connection;
6 this.name = name;
ffbbc70f 7
2a8d2d5f
JA
8 this.scope = 'channel:' + name;
9 Binder.call(this);
10
a9833d9c 11 this.members = [];
059f4918 12 this.ban_list_buffer = [];
a9833d9c 13}
b1fa8101 14
2a8d2d5f
JA
15util.inherits(IrcChannel, Binder);
16
17module.exports = IrcChannel;
18
b1fa8101 19
a9833d9c
D
20IrcChannel.prototype.dispose = function (){
21 this.unbindEvents();
22 this.irc_connection = undefined;
23};
b1fa8101 24
ffbbc70f 25
2a8d2d5f
JA
26IrcChannel.prototype.irc_events = {
27 join: onJoin,
28 part: onPart,
29 kick: onKick,
30 quit: onQuit,
31 privmsg: onMsg,
32 notice: onNotice,
33 ctcp_request: onCtcpRequest,
34 ctcp_response: onCtcpResponse,
35 topic: onTopic,
36 nicklist: onNicklist,
37 nicklistEnd: onNicklistEnd,
38 banlist: onBanList,
39 banlist_end: onBanListEnd,
40 topicsetby: onTopicSetby
b1fa8101
D
41};
42
43
a9833d9c
D
44function onJoin(event) {
45 this.irc_connection.sendIrcCommand('join', {
46 channel: this.name,
47 nick: event.nick,
48 ident: event.ident,
49 hostname: event.hostname,
50 });
51
52 // If we've just joined this channel then request get a nick list
b1fa8101
D
53 if (event.nick === this.irc_connection.nick) {
54 this.irc_connection.write('NAMES ' + channel);
55 }
56};
57
58
a9833d9c
D
59function onPart(event) {
60 this.irc_connection.sendIrcCommand('part', {
ffbbc70f
D
61 nick: event.nick,
62 ident: event.ident,
63 hostname: event.hostname,
64 channel: this.name,
65 message: event.message
66 });
a9833d9c
D
67
68 this.dispose();
ffbbc70f 69};
b1fa8101 70
ffbbc70f 71
a9833d9c
D
72function onKick(event) {
73 this.irc_connection.sendIrcCommand('kick', {
f4ec5774 74 kicked: event.kicked, // Nick of the kicked
ffbbc70f
D
75 nick: event.nick, // Nick of the kicker
76 ident: event.ident,
77 hostname: event.hostname,
78 channel: this.name,
79 message: event.message
80 });
a9833d9c
D
81
82 this.dispose();
ffbbc70f 83};
b1fa8101
D
84
85
a9833d9c
D
86function onQuit(event) {
87 this.irc_connection.sendIrcCommand('quit', {
ffbbc70f
D
88 nick: event.nick,
89 ident: event.ident,
90 hostname: event.hostname,
91 message: event.message
92 });
a9833d9c
D
93
94 this.dispose();
ffbbc70f
D
95};
96
97
a9833d9c
D
98function onMsg(event) {
99 this.irc_connection.sendIrcCommand('msg', {
ffbbc70f
D
100 nick: event.nick,
101 ident: event.ident,
102 hostname: event.hostname,
103 channel: this.name,
104 msg: event.message
105 });
106};
107
108
a9833d9c
D
109function onNotice(event) {
110 this.irc_connection.sendIrcCommand('msg', {
ffbbc70f
D
111 nick: event.nick,
112 ident: event.ident,
113 hostname: event.hostname,
114 channel: this.name,
115 msg: event.trailing
116 });
117};
118
119
a9833d9c
D
120function onCtcpRequest(event) {
121 this.irc_connection.sendIrcCommand('ctcp_request', {
ffbbc70f
D
122 nick: event.nick,
123 ident: event.ident,
124 hostname: event.hostname,
125 target: event.target,
126 type: event.type,
127 msg: event.msg
128 });
129};
130
131
a9833d9c
D
132function onCtcpResponse(event) {
133 this.irc_connection.sendIrcCommand('ctcp_response', {
e2752476
D
134 nick: event.nick,
135 ident: event.ident,
136 hostname: event.hostname,
137 target: event.target,
138 type: event.type,
139 msg: event.msg
140 });
141};
142
143
ffbbc70f 144// TODO: Split event.users into batches of 50
a9833d9c
D
145function onNicklist(event) {
146 this.irc_connection.sendIrcCommand('userlist', {
ffbbc70f
D
147 users: event.users,
148 channel: this.name
149 });
150};
151
152
a9833d9c
D
153function onNicklistEnd(event) {
154 this.irc_connection.sendIrcCommand('userlist_end', {
ffbbc70f
D
155 users: event.users,
156 channel: this.name
157 });
158};
159
f4ec5774 160
a9833d9c
D
161function onTopic(event) {
162 this.irc_connection.sendIrcCommand('topic', {
f4ec5774
D
163 nick: event.nick,
164 channel: this.name,
165 topic: event.topic
166 });
167};
168
059f4918
JA
169
170function onBanList(event) {
171 this.ban_list_buffer.push(event);
172};
173
174function onBanListEnd(event) {
175 var that = this;
176 this.ban_list_buffer.forEach(function (ban) {
177 that.irc_connection.clientEvent('banlist', ban);
178 });
179 this.ban_list_buffer = [];
180};
181
182function onTopic(event) {
183 this.irc_connection.clientEvent('topic', {
184 channel: event.channel,
185 topic: event.topic
186 });
187};
188
189function onTopicSetBy(event) {
190 this.irc_connection.clientEvent('topicsetby', {
191 nick: event.nick,
192 channel: event.channel,
193 when: event.when
194 });
195};
196
197
b1fa8101
D
198/*
199server:event
200server:*
201channel:#channel:event
202channel:*:event
203user:event
204user:*
205
b1fa8101 206Server disconnected:
a9833d9c
D
207 server:disconnect
208 server:*
b1fa8101
D
209
210Joining channel #kiwiirc:
a9833d9c
D
211 channel:#kiwiirc:join
212 channel:*:join
b1fa8101
D
213
214Channel message:
a9833d9c
D
215 channel:#kiwiirc:privmsg
216 channel:*:privmsg
b1fa8101
D
217
218Private message:
a9833d9c
D
219 user:privmsg
220 user:*
b1fa8101 221*/