-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfreenode.jsmod
More file actions
263 lines (197 loc) · 7.62 KB
/
Copy pathfreenode.jsmod
File metadata and controls
263 lines (197 loc) · 7.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
/* ***** BEGIN LICENSE BLOCK *****
* Version: GNU GPL 3.0
*
* The contents of this file are subject to the
* GNU General Public License Version 3.0; you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
* http://www.gnu.org/licenses/gpl.html
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
* ***** END LICENSE BLOCK ***** */
(function freenodeModule($D, $A) {
this.name = this.constructor.name;
var $MD = $D[this.name];
var _cs = new CallScheduler;
this.moduleApi = {
SetChannelAccessLevel: function(channel, nick, level) void $A.Privmsg( getData($MD.chanServ), 'ACCESS '+channel+' ADD '+nick+' '+level ),
// LinkNick: function( nickname, password ) void $A.Privmsg( getData($MD.nickServ), 'LINK '+nickname+' '+password ),
RenameLink: function( newNick, password ) StartAsyncProc( new function() {
var nickServ = getData($MD.nickServ);
var [status, hostWhois] = yield function(callback) $A.Whois(getData($D.nick), callback);
if ( status != OK || !hostWhois.isIdentified )
return;
$A.Nick( newNick );
$A.Privmsg( nickServ, 'REGISTER '+password );
$A.Privmsg( nickServ, 'LINK '+hostWhois.nick+' '+password );
}),
// Syntax: ACCESS <channel> LIST [FULL|mask]
AccessInfo: function( channel, OnReply ) _cs.Add( function() {
var result = [], timeoutId, events = {ircMsg:{}}, startMarker = RandomNumber(8);
$A.AddModuleListener(events);
function End(status, reply) { // response OR timeout
$A.RemoveModuleListener(events);
io.RemoveTimeout(timeoutId);
_cs.Next();
OnReply(status, reply);
}
events.ircMsg.NOTICE = function( tmp, command, from, to, msg ) {
if ( msg.indexOf(startMarker) != -1 ) // the message do not contains the sync key ( -NickServ- Unknown command [<startMarker>] )
return;
events.ircMsg.NOTICE = function( tmp, command, from, to, msg ) {
if ( from != getData($MD.chanServ) || to != getData($D.nick) )
return;
if ( msg.indexOf('is not registered') != -1 ) {
End(NOTFOUND);
return;
}
if ( msg.indexOf('End of list') != -1 ) {
End(OK, result);
return;
}
var match = /^([0-9]+) +([0-9]+) +([^ ]+) +(.*?) *$/(msg);
match && result.push( MakeObj( { num:1, level:2, hostmask:3, time:4 }, match ) );
// End(BADRESPONSE);
}
}
$A.Privmsg( getData($MD.chanServ), [startMarker, 'ACCESS '+channel+' LIST'], function() {
timeoutId = io.AddTimeout( getData($MD.maxServiceBotReply), function() End(TIMEOUT) );
});
}),
// Syntax: INFO <channel>
ChanInfo: function( channel, OnReply ) _cs.Add( function() {
var result = NewDataObj(), timeoutId, events = {ircMsg:{}}, startMarker = RandomNumber(8), endMarker = RandomNumber(8);
$A.AddModuleListener(events);
function End(status, reply) { // response OR timeout
$A.RemoveModuleListener(events);
io.RemoveTimeout(timeoutId);
_cs.Next();
OnReply(status, reply);
}
events.ircMsg.NOTICE = function( tmp, command, from, to, msg ) {
if ( msg.indexOf(startMarker) == -1 ) // the message do not contains the sync key ( -NickServ- Unknown command [<startMarker>] )
return;
events.ircMsg.NOTICE = function( tmp, command, from, to, msg ) {
if ( msg.indexOf(endMarker) == -1 ) {
End(OK, result);
return;
}
if ( from != getData($MD.chanServ) || to != getData($D.nick) )
return;
if ( msg.indexOf('is not registered') != -1 ) {
End(NOTFOUND);
return;
}
var [field, data] = LTrim(msg).split(': ',2);
switch ( field ) {
case 'Channel':
result.channel = data;
break;
case 'Contact':
result.Contact = StrBefore(data,' ');
result.isContactOnline = (data.indexOf('ONLINE') != -1);
break;
case 'Registered':
result.registered = data;
break;
case 'Topic':
result.topic = data;
break;
case 'Contact URI':
result.contactUri = data;
break;
case 'Options':
result.options = data.split(', ');
break;
case 'Mode Lock': // (TBD) find a better end-of-ChanInfo marker
result.modeLock = data;
break;
}
}
}
$A.Privmsg( getData($MD.chanServ), [startMarker, 'INFO '+channel, endMarker], function() {
timeoutId = io.AddTimeout( getData($MD.maxServiceBotReply), function() End(TIMEOUT) );
});
}),
// Syntax: ACCESS <channel> LIST [FULL|mask]
NickInfo: function( channel, OnReply ) _cs.Add( function() {
var result = NewDataObj(), timeoutId, events = {ircMsg:{}}, startMarker = RandomNumber(8), endMarker = RandomNumber(8);
$A.AddModuleListener(events);
function End(status, reply) { // response OR timeout
$A.RemoveModuleListener(events);
io.RemoveTimeout(timeoutId);
_cs.Next();
OnReply(status, reply);
}
events.ircMsg.NOTICE = function( tmp, command, from, to, msg ) {
if ( msg.indexOf(startMarker) != -1 ) // the message do not contains the sync key ( -NickServ- Unknown command [<startMarker>] )
return;
events.ircMsg.NOTICE = function( tmp, command, from, to, msg ) {
if ( msg.indexOf(endMarker) != -1 ) {// the message do not contains the sync key ( -NickServ- Unknown command [<syncBegin>] )
End(OK, result);
return;
}
if ( from != getData($MD.nickServ) || to != getData($D.nick) )
return;
if ( msg.indexOf('is not registered') != -1 ) {
End(NOTFOUND);
return;
}
var [field, data] = LTrim(msg).split(': ',2);
switch ( field ) {
case 'Nickname':
result.nick = StrBefore(data,' ');
result.isOnline = (data.indexOf('ONLINE') != -1);
break;
case 'Registered':
result.registred = data;
break;
case 'Last Seen':
result.lastSeen = data;
break;
case 'Last Seen Address':
result.lastSeenAddress = data;
break;
case 'Last Seen Quit Msg':
result.lastSeenQuitMsg = data;
break;
case 'Email Address':
result.emailAddress = data;
break;
case 'UIN':
result.UIN = data;
break;
case 'Nickname Options': // (TBD) find a better end-of-NickInfo marker
result.nicknameOptions = data.split(', ');
break;
}
}
}
$A.Privmsg( getData($MD.nickServ), [startMarker, 'INFO '+nick, endMarker], function() {
timeoutId = io.AddTimeout( getData($MD.maxServiceBotReply), function() End(TIMEOUT) );
});
})
} // moduleApi
this.stateListener = [
{
set: function(s) s.STATE_IRC_INTERACTIVE && s.DefaultModule && s.STATE_IRC_HAS_GOOD_NICK,
reset: False, // state never resets
trigger: function(polarity) {
if ( hasData($MD.password) ) {
var password = getData($MD.password);
$A.Privmsg( getData($MD.nickServ), 'IDENTIFY '+password );
$A.Privmsg( getData($MD.nickServ), 'REGISTER '+password );
if ( hasData($MD.mainNick) )
$A.Privmsg( getData($MD.nickServ), 'LINK '+getData($MD.mainNick)+' '+password );
}
}
}
] // stateListener
})
/*
freenode modes:
http://freenode.net/using_the_network.shtml
// $A.Send('CAPAB IDENTIFY-MSG'); // ask the server to prefix all messages with '+' if the nick is resistred
*/