Commit | Line | Data |
---|---|---|
692163ca JA |
1 | var IrcUser = function (irc_connection, nick) {\r |
2 | this.irc_connection = irc_connection;\r | |
3 | this.nick = nick;\r | |
4 | };\r | |
5 | \r | |
6 | module.exports = IrcUser;\r | |
7 | \r | |
c28e31d9 | 8 | IrcUser.prototype.bindEvents = function () {\r |
692163ca JA |
9 | var that = this;\r |
10 | \r | |
11 | // If we havent generated an event listing yet, do so now\r | |
12 | if (!this.irc_events) {\r | |
13 | this.irc_events = {\r | |
14 | nick: onNick,\r | |
15 | away: onAway,\r | |
16 | quit: onKick,\r | |
17 | whoisuser: onWhoisUser,\r | |
18 | whoisoperator: onWhoisOperator,\r | |
19 | whoischannels: onWhoisChannels,\r | |
20 | whoismodes: onWhoisModes,\r | |
21 | whoisidle: onWhoisIdle,\r | |
22 | whoisregnick: onRegNick,\r | |
23 | endofwhois: onEhoisEnd,\r | |
24 | notice: onNotice,\r | |
25 | ctcp_response: onCtcpResponse,\r | |
26 | privmsg: onPrivmsg,\r | |
27 | ctcp_request: onCtcpRequest\r | |
28 | };\r | |
29 | }\r | |
30 | \r | |
31 | this.irc_events.forEach(function (fn, event_name, irc_events) {\r | |
32 | // Bind the event to `that` context, storing it with the event listing\r | |
33 | if (!irc_events[event_name].bound_fn) {\r | |
34 | irc_events[event_name].bound_fn = fn.bind(that);\r | |
35 | }\r | |
36 | \r | |
37 | this.irc_connection.on('user:' + this.nick + ':' + event_name, irc_events[event_name].bound_fn);\r | |
38 | });\r | |
39 | };\r | |
40 | \r | |
41 | \r | |
c28e31d9 | 42 | IrcUser.prototype.unbindEvents = function () {\r |
692163ca JA |
43 | this.irc_events.forEach(function(fn, event_name, irc_events) {\r |
44 | if (irc_events[event_name].bound_fn) {\r | |
45 | this.irc_connection.removeListener('user:' + this.nick + ':' + event_name, irc_events[event_name].bound_fn);\r | |
46 | }\r | |
47 | });\r | |
48 | };\r | |
49 | \r | |
092fae2f | 50 | function onNick(event) {\r |
692163ca JA |
51 | this.irc_connection.clientEvent('nick', {\r |
52 | nick: event.nick,\r | |
53 | ident: event.ident,\r | |
54 | hostname: event.hostname,\r | |
55 | newnick: event.newnick\r | |
56 | });\r | |
57 | };\r | |
58 | \r | |
092fae2f | 59 | function onAway(event) {\r |
692163ca JA |
60 | this.irc_connection.clientEvent('away', {\r |
61 | nick: event.nick,\r | |
62 | msg: event.msg\r | |
63 | });\r | |
64 | };\r | |
65 | \r | |
092fae2f | 66 | function onQuit(event) {\r |
692163ca JA |
67 | this.irc_connection.clientEvent('quit', {\r |
68 | nick: event.nick,\r | |
69 | ident: event.ident,\r | |
70 | hostname: event.hostname,\r | |
71 | message: event.trailing\r | |
72 | });\r | |
73 | };\r | |
74 | \r | |
092fae2f | 75 | function onWhoisUser(event) {\r |
692163ca JA |
76 | this.irc_connection.clientEvent('whois', {\r |
77 | nick: event.nick,\r | |
78 | ident: event.ident,\r | |
79 | host: event.host,\r | |
80 | msg: event.msg,\r | |
81 | end: false\r | |
82 | });\r | |
83 | };\r | |
84 | \r | |
092fae2f | 85 | function onWhoisServer(event) {\r |
692163ca JA |
86 | this.irc_connection.clientEvent('whois', {\r |
87 | nick: event.nick,\r | |
88 | irc_server: event.irc_server,\r | |
89 | end: false\r | |
90 | });\r | |
91 | };\r | |
92 | \r | |
092fae2f | 93 | function onWhoisOperator(event) {\r |
692163ca JA |
94 | this.irc_connection.clientEvent('whois', {\r |
95 | nick: event.nick,\r | |
96 | msg: event.msg,\r | |
97 | end: false\r | |
98 | });\r | |
99 | };\r | |
100 | \r | |
092fae2f | 101 | function onWhoisChannels(event) {\r |
692163ca JA |
102 | this.irc_connection.clientEvent('whois', {\r |
103 | nick: event.nick,\r | |
104 | chans: event.chans,\r | |
105 | end: false\r | |
106 | });\r | |
107 | };\r | |
108 | \r | |
092fae2f | 109 | function onWhoisModes(event) {\r |
692163ca JA |
110 | this.irc_connection.clientEvent('whois', {\r |
111 | nick: event.nick,\r | |
112 | msg: event.msg,\r | |
113 | end: false\r | |
114 | });\r | |
115 | };\r | |
116 | \r | |
092fae2f | 117 | function onWhoisUser(event) {\r |
692163ca JA |
118 | this.irc_connection.clientEvent('whois', {\r |
119 | nick: event.nick,\r | |
120 | idle: event.idle,\r | |
121 | logon: event.logon || undefined,\r | |
122 | end: false\r | |
123 | });\r | |
124 | };\r | |
125 | \r | |
092fae2f | 126 | function onWhoisRegNick(event) {\r |
692163ca JA |
127 | this.irc_connection.clientEvent('whois', {\r |
128 | nick: event.nick,\r | |
129 | msg: event.msg,\r | |
130 | end: false\r | |
131 | });\r | |
132 | };\r | |
133 | \r | |
092fae2f | 134 | function onWhoisEnd(event) {\r |
692163ca JA |
135 | this.irc_connection.clientEvent('whois', {\r |
136 | nick: event.nick,\r | |
137 | msg: event.msg,\r | |
138 | end: true\r | |
139 | });\r | |
140 | };\r | |
141 | \r | |
092fae2f | 142 | function onNotice(event) {\r |
692163ca JA |
143 | this.irc_connection.clientEvent('notice', {\r |
144 | nick: event.nick,\r | |
145 | ident: event.ident,\r | |
146 | hostname: event.hostname,\r | |
147 | target: event.target,\r | |
148 | msg: event.msg\r | |
149 | });\r | |
150 | };\r | |
151 | \r | |
092fae2f | 152 | function onCtcpResponse(event) {\r |
692163ca JA |
153 | this.irc_connection.clientEvent('ctcp_response', {\r |
154 | nick: event.nick,\r | |
155 | ident: event.ident,\r | |
156 | hostname: event.hostname,\r | |
157 | channel: event.channel,\r | |
158 | msg: event.msg\r | |
159 | });\r | |
160 | };\r | |
161 | \r | |
092fae2f | 162 | function onPrivmsg(event) {\r |
692163ca JA |
163 | this.irc_connection.clientEvent('privmsg', {\r |
164 | nick: event.nick,\r | |
165 | ident: event.ident,\r | |
166 | hostname: event.hostname,\r | |
167 | channel: event.channel,\r | |
168 | msg: event.msg\r | |
169 | });\r | |
170 | };\r | |
171 | \r | |
092fae2f | 172 | function onCtcpRequest(event) {\r |
692163ca JA |
173 | this.irc_connection.clientEvent('ctcp_request', {\r |
174 | nick: event.nick,\r | |
175 | ident: event.ident,\r | |
176 | hostname: event.hostname,\r | |
177 | target: event.target,\r | |
178 | type: event.type,\r | |
179 | msg: event.msg\r | |
180 | });\r | |
181 | };\r |