1 var util
= require('util'),
2 EventBinder
= require('./eventbinder.js');
4 var IrcUser = function (irc_connection
, nick
) {
5 this.irc_connection
= irc_connection
;
12 whoisuser
: onWhoisUser
,
13 whoisaway
: onWhoisAway
,
14 whoisoperator
: onWhoisOperator
,
15 whoischannels
: onWhoisChannels
,
16 whoismodes
: onWhoisModes
,
17 whoisidle
: onWhoisIdle
,
18 whoisregnick
: onWhoisRegNick
,
19 whoisserver
: onWhoisServer
,
20 whoishost
: onWhoisHost
,
21 whoissecure
: onWhoisSecure
,
22 whoisaccount
: onWhoisAccount
,
23 endofwhois
: onWhoisEnd
,
25 endofwhowas
: onWhoWasEnd
,
26 wasnosuchnick
: onWasNoSuchNick
,
28 ctcp_response
: onCtcpResponse
,
30 ctcp_request
: onCtcpRequest
,
33 EventBinder
.bindIrcEvents('user ' + this.nick
, this.irc_events
, this, irc_connection
);
37 module
.exports
= IrcUser
;
40 IrcUser
.prototype.dispose = function () {
41 EventBinder
.unbindIrcEvents('user ' + this.nick
, this.irc_events
, this.irc_connection
);
42 this.irc_connection
= undefined;
46 function onNick(event
) {
47 this.irc_connection
.clientEvent('nick', {
50 hostname
: event
.hostname
,
51 newnick
: event
.newnick
,
55 // TODO: uncomment when using an IrcUser per nick
56 //EventBinder.unbindIrcEvents('user ' + this.nick, this.irc_events, irc_connection);
57 //this.nick = event.newnick;
58 //EventBinder.bindIrcEvents('user ' + this.nick, this.irc_events, this, irc_connection);
61 function onAway(event
) {
62 this.irc_connection
.clientEvent('away', {
69 function onQuit(event
) {
70 this.irc_connection
.clientEvent('quit', {
73 hostname
: event
.hostname
,
74 message
: event
.message
,
79 function onWhoisUser(event
) {
80 this.irc_connection
.clientEvent('whois', {
89 function onWhoisAway(event
) {
90 this.irc_connection
.clientEvent('whois', {
92 away_reason
: event
.reason
,
97 function onWhoisServer(event
) {
98 this.irc_connection
.clientEvent('whois', {
100 irc_server
: event
.irc_server
,
101 server_info
: event
.server_info
,
106 function onWhoisOperator(event
) {
107 this.irc_connection
.clientEvent('whois', {
114 function onWhoisChannels(event
) {
115 this.irc_connection
.clientEvent('whois', {
122 function onWhoisModes(event
) {
123 this.irc_connection
.clientEvent('whois', {
130 function onWhoisIdle(event
) {
131 this.irc_connection
.clientEvent('whois', {
134 logon
: event
.logon
|| undefined,
139 function onWhoisRegNick(event
) {
140 this.irc_connection
.clientEvent('whois', {
147 function onWhoisHost(event
) {
148 this.irc_connection
.clientEvent('whois', {
155 function onWhoisSecure(event
) {
156 this.irc_connection
.clientEvent('whois', {
158 msg
: 'Using a secure connection',
163 function onWhoisAccount(event
) {
164 this.irc_connection
.clientEvent('whois', {
166 msg
: 'Logged in as ' + event
.account
,
171 function onWhoisEnd(event
) {
172 this.irc_connection
.clientEvent('whois', {
179 function onWhoWas(event
) {
180 this.irc_connection
.clientEvent('whowas', {
184 real_name
: event
.real_name
,
189 function onWasNoSuchNick(event
) {
190 this.irc_connection
.clientEvent('whowas', {
196 function onWhoWasEnd(event
) {
197 this.irc_connection
.clientEvent('whowas', {
203 function onNotice(event
) {
204 this.irc_connection
.clientEvent('notice', {
205 from_server
: event
.from_server
,
208 hostname
: event
.hostname
,
209 target
: event
.target
,
215 function onCtcpResponse(event
) {
216 this.irc_connection
.clientEvent('ctcp_response', {
219 hostname
: event
.hostname
,
220 channel
: event
.channel
,
226 function onPrivmsg(event
) {
229 global
.modules
.emit('irc message', {
230 connection
: this.irc_connection
,
234 that
.irc_connection
.clientEvent('msg', {
237 hostname
: event
.hostname
,
238 channel
: event
.channel
,
245 function onCtcpRequest(event
) {
246 this.irc_connection
.clientEvent('ctcp_request', {
249 hostname
: event
.hostname
,
250 target
: event
.target
,
257 function onMode(event
) {
258 this.irc_connection
.clientEvent('mode', {
259 target
: event
.target
,