IrcChannel + IrcCommands topic event
[KiwiIRC.git] / server / irc / channel.js
1
2 function IrcChannel(irc_connection, name) {
3 var that = this;
4
5 this.irc_connection = irc_connection;
6 this.name = name;
7
8 // Helper for binding listeners
9 function bindEvent(event, fn) {
10 irc_connection.on('channel:' + name + ':' + event, function () {
11 fn.apply(that, arguments);
12 });
13 }
14
15 bindEvent('join', this.onJoin);
16 bindEvent('part', this.onPart);
17 bindEvent('kick', this.onKick);
18 bindEvent('quit', this.onQuit);
19
20 bindEvent('privmsg', this.onMsg);
21 bindEvent('notice', this.onNotice);
22 bindEvent('ctcp_request', this.onCtcpRequest);
23 bindEvent('ctcp_response', this.onCtcpResponse);
24
25 bindEvent('topic', this.onTopic)
26
27 bindEvent('nicklist', this.onNicklist);
28 bindEvent('nicklistEnd', this.onNicklistEnd);
29 }
30
31
32 IrcChannel.prototype.clientEvent = function (event_name, event) {
33 event.server = this.irc_connection.con_num;
34 this.irc_connection.state.sendIrcCommand(event_name, event);
35 };
36
37
38 IrcChannel.prototype.onJoin = function (event) {
39 this.clientEvent('join', {
40 channel: this.name,
41 nick: event.nick,
42 ident: event.ident,
43 hostname: event.hostname,
44 });
45
46 // If we've just joined this channel then requesr=t get a nick list
47 if (event.nick === this.irc_connection.nick) {
48 this.irc_connection.write('NAMES ' + channel);
49 }
50 };
51
52
53 IrcChannel.prototype.onPart = function (event) {
54 this.clientEvent('part', {
55 nick: event.nick,
56 ident: event.ident,
57 hostname: event.hostname,
58 channel: this.name,
59 message: event.message
60 });
61 };
62
63
64 IrcChannel.prototype.onKick = function (event) {
65 this.client.sendIrcCommand('kick', {
66 kicked: event.kicked, // Nick of the kicked
67 nick: event.nick, // Nick of the kicker
68 ident: event.ident,
69 hostname: event.hostname,
70 channel: this.name,
71 message: event.message
72 });
73 };
74
75
76 IrcChannel.prototype.onQuit = function (event) {
77 this.clientEvent('quit', {
78 nick: event.nick,
79 ident: event.ident,
80 hostname: event.hostname,
81 message: event.message
82 });
83 };
84
85
86 IrcChannel.prototype.onMsg = function (event) {
87 this.clientEvent('msg', {
88 nick: event.nick,
89 ident: event.ident,
90 hostname: event.hostname,
91 channel: this.name,
92 msg: event.message
93 });
94 };
95
96
97 IrcChannel.prototype.onNotice = function (event) {
98 this.clientEvent('msg', {
99 nick: event.nick,
100 ident: event.ident,
101 hostname: event.hostname,
102 channel: this.name,
103 msg: event.trailing
104 });
105 };
106
107
108 IrcChannel.prototype.onCtcpRequest = function (event) {
109 this.clientEvent('ctcp_request', {
110 nick: event.nick,
111 ident: event.ident,
112 hostname: event.hostname,
113 target: event.target,
114 type: event.type,
115 msg: event.msg
116 });
117 };
118
119
120 IrcChannel.prototype.onCtcpResponse = function (event) {
121 this.clientEvent('ctcp_response', {
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
132 // TODO: Split event.users into batches of 50
133 IrcChannel.prototype.onNicklist = function (event) {
134 this.clientEvent('userlist', {
135 users: event.users,
136 channel: this.name
137 });
138 };
139
140
141 IrcChannel.prototype.onNicklistEnd = function (event) {
142 this.clientEvent('userlist_end', {
143 users: event.users,
144 channel: this.name
145 });
146 };
147
148
149 IrcChannel.prototype.onTopic = function (event) {
150 this.clientEvent('topic', {
151 nick: event.nick,
152 channel: this.name,
153 topic: event.topic
154 });
155 };
156
157 /*
158 server:event
159 server:*
160 channel:#channel:event
161 channel:*:event
162 user:event
163 user:*
164
165 Server disconnected:
166 server:disconnect
167 server:*
168
169 Joining channel #kiwiirc:
170 channel:#kiwiirc:join
171 channel:*:join
172
173 Channel message:
174 channel:#kiwiirc:privmsg
175 channel:*:privmsg
176
177 Private message:
178 user:privmsg
179 user:*
180 */