corrade-lsl-templates – Blame information for rev 42
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
42 | office | 1 | /////////////////////////////////////////////////////////////////////////// |
2 | // Copyright (C) Wizardry and Steamworks 2018 - License: GNU GPLv3 // |
||
3 | /////////////////////////////////////////////////////////////////////////// |
||
4 | // |
||
5 | // A reminders module for Corrade Eggdrop. |
||
6 | // |
||
7 | /////////////////////////////////////////////////////////////////////////// |
||
8 | |||
9 | /////////////////////////////////////////////////////////////////////////// |
||
10 | // Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
||
11 | /////////////////////////////////////////////////////////////////////////// |
||
12 | string wasKeyValueGet(string k, string data) { |
||
13 | if(llStringLength(data) == 0) return ""; |
||
14 | if(llStringLength(k) == 0) return ""; |
||
15 | list a = llParseStringKeepNulls(data, ["&", "="], []); |
||
16 | integer i = llListFindList(llList2ListStrided(a, 0, -1, 2), [ k ]); |
||
17 | if(i != -1) return llList2String(a, 2*i+1); |
||
18 | return ""; |
||
19 | } |
||
20 | |||
21 | /////////////////////////////////////////////////////////////////////////// |
||
22 | // Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
||
23 | /////////////////////////////////////////////////////////////////////////// |
||
24 | string wasKeyValueEncode(list data) { |
||
25 | list k = llList2ListStrided(data, 0, -1, 2); |
||
26 | list v = llList2ListStrided(llDeleteSubList(data, 0, 0), 0, -1, 2); |
||
27 | data = []; |
||
28 | do { |
||
29 | data += llList2String(k, 0) + "=" + llList2String(v, 0); |
||
30 | k = llDeleteSubList(k, 0, 0); |
||
31 | v = llDeleteSubList(v, 0, 0); |
||
32 | } while(llGetListLength(k) != 0); |
||
33 | return llDumpList2String(data, "&"); |
||
34 | } |
||
35 | |||
36 | /////////////////////////////////////////////////////////////////////////// |
||
37 | // Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
||
38 | /////////////////////////////////////////////////////////////////////////// |
||
39 | // http://was.fm/secondlife/wanderer |
||
40 | vector wasCirclePoint(float radius) { |
||
41 | float x = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
||
42 | float y = llPow(-1, 1 + (integer) llFrand(2)) * llFrand(radius*2); |
||
43 | if(llPow(x,2) + llPow(y,2) <= llPow(radius,2)) |
||
44 | return <x, y, 0>; |
||
45 | return wasCirclePoint(radius); |
||
46 | } |
||
47 | |||
48 | /////////////////////////////////////////////////////////////////////////// |
||
49 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
50 | /////////////////////////////////////////////////////////////////////////// |
||
51 | // escapes a string in conformance with RFC1738 |
||
52 | string wasURLEscape(string i) { |
||
53 | string o = ""; |
||
54 | do { |
||
55 | string c = llGetSubString(i, 0, 0); |
||
56 | i = llDeleteSubString(i, 0, 0); |
||
57 | if(c == "") jump continue; |
||
58 | if(c == " ") { |
||
59 | o += "+"; |
||
60 | jump continue; |
||
61 | } |
||
62 | if(c == "\n") { |
||
63 | o += "%0D" + llEscapeURL(c); |
||
64 | jump continue; |
||
65 | } |
||
66 | o += llEscapeURL(c); |
||
67 | @continue; |
||
68 | } while(i != ""); |
||
69 | return o; |
||
70 | } |
||
71 | |||
72 | /////////////////////////////////////////////////////////////////////////// |
||
73 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
74 | /////////////////////////////////////////////////////////////////////////// |
||
75 | list wasCSVToList(string csv) { |
||
76 | list l = []; |
||
77 | list s = []; |
||
78 | string m = ""; |
||
79 | do { |
||
80 | string a = llGetSubString(csv, 0, 0); |
||
81 | csv = llDeleteSubString(csv, 0, 0); |
||
82 | if(a == ",") { |
||
83 | if(llList2String(s, -1) != "\"") { |
||
84 | l += m; |
||
85 | m = ""; |
||
86 | jump continue; |
||
87 | } |
||
88 | m += a; |
||
89 | jump continue; |
||
90 | } |
||
91 | if(a == "\"" && llGetSubString(csv, 0, 0) == a) { |
||
92 | m += a; |
||
93 | csv = llDeleteSubString(csv, 0, 0); |
||
94 | jump continue; |
||
95 | } |
||
96 | if(a == "\"") { |
||
97 | if(llList2String(s, -1) != a) { |
||
98 | s += a; |
||
99 | jump continue; |
||
100 | } |
||
101 | s = llDeleteSubList(s, -1, -1); |
||
102 | jump continue; |
||
103 | } |
||
104 | m += a; |
||
105 | @continue; |
||
106 | } while(csv != ""); |
||
107 | // postcondition: length(s) = 0 |
||
108 | return l + m; |
||
109 | } |
||
110 | |||
111 | /////////////////////////////////////////////////////////////////////////// |
||
112 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
113 | /////////////////////////////////////////////////////////////////////////// |
||
114 | string wasListToCSV(list l) { |
||
115 | list v = []; |
||
116 | do { |
||
117 | string a = llDumpList2String( |
||
118 | llParseStringKeepNulls( |
||
119 | llList2String( |
||
120 | l, |
||
121 | |||
122 | ), |
||
123 | ["\""], |
||
124 | [] |
||
125 | ), |
||
126 | "\"\"" |
||
127 | ); |
||
128 | if(llParseStringKeepNulls( |
||
129 | a, |
||
130 | [" ", ",", "\n", "\""], [] |
||
131 | ) != |
||
132 | (list) a |
||
133 | ) a = "\"" + a + "\""; |
||
134 | v += a; |
||
135 | l = llDeleteSubList(l, 0, 0); |
||
136 | } while(l != []); |
||
137 | return llDumpList2String(v, ","); |
||
138 | } |
||
139 | |||
140 | /////////////////////////////////////////////////////////////////////////// |
||
141 | // Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
||
142 | /////////////////////////////////////////////////////////////////////////// |
||
143 | // unescapes a string in conformance with RFC1738 |
||
144 | string wasURLUnescape(string i) { |
||
145 | return llUnescapeURL( |
||
146 | llDumpList2String( |
||
147 | llParseString2List( |
||
148 | llDumpList2String( |
||
149 | llParseString2List( |
||
150 | i, |
||
151 | ["+"], |
||
152 | [] |
||
153 | ), |
||
154 | " " |
||
155 | ), |
||
156 | ["%0D%0A"], |
||
157 | [] |
||
158 | ), |
||
159 | "\n" |
||
160 | ) |
||
161 | ); |
||
162 | } |
||
163 | |||
164 | // configuration data |
||
165 | string configuration = ""; |
||
166 | // store message over state. |
||
167 | string src_firstname = ""; |
||
168 | string src_lastname = ""; |
||
169 | string dst_firstname = ""; |
||
170 | string dst_lastname = ""; |
||
171 | string text = ""; |
||
172 | string group = ""; |
||
173 | string data = ""; |
||
174 | |||
175 | // recent list of avatars |
||
176 | list recent_firstnames = []; |
||
177 | list recent_lastnames = []; |
||
178 | |||
179 | // the action to execute |
||
180 | string action = ""; |
||
181 | // holds SQL statements and parameters |
||
182 | string statement = ""; |
||
183 | string parameters = ""; |
||
184 | |||
185 | default { |
||
186 | state_entry() { |
||
187 | llOwnerSay("[Reminders] Starting module..."); |
||
188 | llSetTimerEvent(10); |
||
189 | } |
||
190 | link_message(integer sender, integer num, string message, key id) { |
||
191 | if(id != "configuration") return; |
||
192 | llOwnerSay("[Reminders] Got configuration..."); |
||
193 | configuration = message; |
||
194 | action = "create"; |
||
195 | state trampoline; |
||
196 | } |
||
197 | timer() { |
||
198 | llOwnerSay("[Reminders] Requesting configuration..."); |
||
199 | llMessageLinked(LINK_THIS, 0, "configuration", NULL_KEY); |
||
200 | } |
||
201 | on_rez(integer num) { |
||
202 | llResetScript(); |
||
203 | } |
||
204 | changed(integer change) { |
||
205 | if((change & CHANGED_INVENTORY) || |
||
206 | (change & CHANGED_REGION_START) || |
||
207 | (change & CHANGED_OWNER)) { |
||
208 | llResetScript(); |
||
209 | } |
||
210 | } |
||
211 | state_exit() { |
||
212 | llSetTimerEvent(0); |
||
213 | } |
||
214 | } |
||
215 | |||
216 | |||
217 | state trampoline { |
||
218 | state_entry() { |
||
219 | if(action == "create") { |
||
220 | statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + |
||
221 | wasKeyValueGet("reminders table", configuration) + |
||
222 | "\" (message TEXT(1023), name TEXT(35), src_firstname TEXT(31), src_lastname TEXT(31), dst_firstname TEXT(31), dst_lastname TEXT(31))"); |
||
223 | state query; |
||
224 | } |
||
225 | |||
226 | if(action == "search") { |
||
227 | statement = wasURLEscape("SELECT * FROM \"" + |
||
228 | wasKeyValueGet("reminders table", configuration) + |
||
229 | "\" WHERE name=:group AND dst_firstname=:firstname AND dst_lastname=:lastname LIMIT 1"); |
||
230 | parameters = wasURLEscape( |
||
231 | wasListToCSV( |
||
232 | [ |
||
233 | "group", |
||
234 | wasURLEscape( |
||
235 | wasKeyValueGet( |
||
236 | "group", |
||
237 | configuration |
||
238 | ) |
||
239 | ), |
||
240 | "firstname", |
||
241 | wasURLEscape(dst_firstname), |
||
242 | "lastname", |
||
243 | wasURLEscape(dst_lastname) |
||
244 | ] |
||
245 | ) |
||
246 | ); |
||
247 | |||
248 | state query; |
||
249 | } |
||
250 | |||
251 | if(action == "commit") { |
||
252 | statement = wasURLEscape("INSERT INTO \"" + |
||
253 | wasKeyValueGet("reminders table", configuration) + |
||
254 | "\" (name, dst_firstname, dst_lastname, src_firstname, src_lastname, message) VALUES (:name, :dst_firstname, :dst_lastname, :src_firstname, :src_lastname, :message)"); |
||
255 | parameters = wasURLEscape( |
||
256 | wasListToCSV( |
||
257 | [ |
||
258 | "name", |
||
259 | wasURLEscape( |
||
260 | wasKeyValueGet( |
||
261 | "group", |
||
262 | configuration |
||
263 | ) |
||
264 | ), |
||
265 | "dst_firstname", |
||
266 | wasURLEscape(dst_firstname), |
||
267 | "dst_lastname", |
||
268 | wasURLEscape(dst_lastname), |
||
269 | "src_firstname", |
||
270 | wasURLEscape(src_firstname), |
||
271 | "src_lastname", |
||
272 | wasURLEscape(src_lastname), |
||
273 | "message", wasURLEscape(text) |
||
274 | ] |
||
275 | ) |
||
276 | ); |
||
277 | |||
278 | state query; |
||
279 | } |
||
280 | |||
281 | if(action == "remove") { |
||
282 | statement = wasURLEscape("DELETE FROM \"" + |
||
283 | wasKeyValueGet("reminders table", configuration) + |
||
284 | "\" WHERE name=:name AND src_firstname=:src_firstname AND src_lastname=:src_lastname AND dst_firstname=:dst_firstname AND dst_lastname=:dst_lastname AND message=:message"); |
||
285 | parameters = wasURLEscape( |
||
286 | wasListToCSV( |
||
287 | [ |
||
288 | "name", |
||
289 | wasURLEscape( |
||
290 | wasKeyValueGet( |
||
291 | "group", |
||
292 | configuration |
||
293 | ) |
||
294 | ), |
||
295 | "src_firstname", |
||
296 | wasURLEscape(src_firstname), |
||
297 | "src_lastname", |
||
298 | wasURLEscape(src_lastname), |
||
299 | "dst_firstname", |
||
300 | wasURLEscape(dst_firstname), |
||
301 | "dst_lastname", |
||
302 | wasURLEscape(dst_lastname), |
||
303 | "message", |
||
304 | wasURLEscape(text) |
||
305 | ] |
||
306 | ) |
||
307 | ); |
||
308 | state query; |
||
309 | } |
||
310 | |||
311 | // DEBUG |
||
312 | llOwnerSay("[Reminders] Jump table corrupted, please contact vendor..."); |
||
313 | llResetScript(); |
||
314 | } |
||
315 | on_rez(integer num) { |
||
316 | llResetScript(); |
||
317 | } |
||
318 | changed(integer change) { |
||
319 | if((change & CHANGED_INVENTORY) || |
||
320 | (change & CHANGED_REGION_START) || |
||
321 | (change & CHANGED_OWNER)) { |
||
322 | llResetScript(); |
||
323 | } |
||
324 | } |
||
325 | } |
||
326 | |||
327 | state query { |
||
328 | state_entry() { |
||
329 | // Check messge length. |
||
330 | string message = wasKeyValueEncode( |
||
331 | [ |
||
332 | "command", "database", |
||
333 | "group", wasURLEscape( |
||
334 | wasKeyValueGet( |
||
335 | "group", |
||
336 | configuration |
||
337 | ) |
||
338 | ), |
||
339 | "password", wasURLEscape( |
||
340 | wasKeyValueGet( |
||
341 | "password", |
||
342 | configuration |
||
343 | ) |
||
344 | ), |
||
345 | "SQL", statement, |
||
346 | "data", parameters, |
||
347 | "callback", wasURLEscape( |
||
348 | wasKeyValueGet( |
||
349 | "URL", |
||
350 | configuration |
||
351 | ) |
||
352 | ) |
||
353 | ] |
||
354 | ); |
||
355 | |||
356 | // GC - none of these are needed anymore. |
||
357 | statement = ""; |
||
358 | parameters = ""; |
||
359 | |||
360 | // DEBUG |
||
361 | llOwnerSay("[Reminders] Executing action: " + action); |
||
362 | llInstantMessage( |
||
363 | wasKeyValueGet( |
||
364 | "corrade", |
||
365 | configuration |
||
366 | ), |
||
367 | message |
||
368 | ); |
||
369 | // GC |
||
370 | message = ""; |
||
371 | llSetTimerEvent(60); |
||
372 | } |
||
373 | link_message(integer sender, integer num, string body, key id) { |
||
374 | // Only process callbacks for the database command. |
||
375 | if(id != "callback" || wasKeyValueGet("command", body) != "database") |
||
376 | return; |
||
377 | |||
378 | if(wasKeyValueGet("success", body) != "True") { |
||
379 | // DEBUG |
||
380 | llOwnerSay("[Reminders] Unable query database: " + |
||
381 | wasURLUnescape( |
||
382 | wasKeyValueGet("error", body) |
||
383 | ) |
||
384 | ); |
||
385 | state listen_group; |
||
386 | } |
||
387 | |||
388 | // Process actions. |
||
389 | if(action == "create") { |
||
390 | llOwnerSay("[Reminders] Database created!"); |
||
391 | state listen_group; |
||
392 | } |
||
393 | |||
394 | if(action == "search") { |
||
395 | list result = wasCSVToList( |
||
396 | wasURLUnescape( |
||
397 | wasKeyValueGet("data", body) |
||
398 | ) |
||
399 | ); |
||
400 | |||
401 | // DEBUG |
||
402 | //llOwnerSay(llDumpList2String(result, ",")); |
||
403 | |||
404 | // 12 CSV cells, 6 fields + 6 results |
||
405 | if(llGetListLength(result) != 12) { |
||
406 | // DEBUG |
||
407 | llOwnerSay("[Reminders] No reminders for: " + dst_firstname + " " + dst_lastname); |
||
408 | state search_trampoline; |
||
409 | } |
||
410 | |||
411 | data = llList2String( |
||
412 | result, |
||
413 | llListFindList(result, ["data"]) + 1 |
||
414 | ); |
||
415 | |||
416 | src_firstname = llList2String( |
||
417 | result, |
||
418 | llListFindList(result, ["src_firstname"]) + 1 |
||
419 | ); |
||
420 | |||
421 | src_lastname = llList2String( |
||
422 | result, |
||
423 | llListFindList(result, ["src_lastname"]) + 1 |
||
424 | ); |
||
425 | |||
426 | dst_firstname = llList2String( |
||
427 | result, |
||
428 | llListFindList(result, ["dst_firstname"]) + 1 |
||
429 | ); |
||
430 | |||
431 | dst_lastname = llList2String( |
||
432 | result, |
||
433 | llListFindList(result, ["dst_lastname"]) + 1 |
||
434 | ); |
||
435 | |||
436 | text = llList2String( |
||
437 | result, |
||
438 | llListFindList(result, ["message"]) + 1 |
||
439 | ); |
||
440 | |||
441 | // Build data to be sent. |
||
442 | data = dst_firstname + |
||
443 | " " + |
||
444 | dst_lastname + |
||
445 | ": " + |
||
446 | text + |
||
447 | " " + |
||
448 | "[" + |
||
449 | src_firstname + |
||
450 | " " + |
||
451 | src_lastname + |
||
452 | "]"; |
||
453 | |||
454 | // DEBUG |
||
455 | //llOwnerSay("BODY: " + wasURLUnescape(body)); |
||
456 | //llOwnerSay("DATA: " + wasURLUnescape(data)); |
||
457 | |||
458 | state remind; |
||
459 | } |
||
460 | |||
461 | if(action == "commit") { |
||
462 | data = "Reminder for " + dst_firstname + " " + dst_lastname + " stored."; |
||
463 | state tell; |
||
464 | } |
||
465 | |||
466 | if(action == "remove") { |
||
467 | // DEBUG |
||
468 | llOwnerSay("[Reminders] Reminder removed for " + dst_firstname + " " + dst_lastname); |
||
469 | |||
470 | state search_trampoline; |
||
471 | } |
||
472 | |||
473 | // Don't announce creating table. |
||
474 | if(action == "create") |
||
475 | state listen_group; |
||
476 | |||
477 | // DEBUG |
||
478 | llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); |
||
479 | state listen_group; |
||
480 | } |
||
481 | timer() { |
||
482 | // DEBUG |
||
483 | llOwnerSay("[Reminders] Query timed out..."); |
||
484 | state listen_group; |
||
485 | } |
||
486 | on_rez(integer num) { |
||
487 | llResetScript(); |
||
488 | } |
||
489 | changed(integer change) { |
||
490 | if((change & CHANGED_INVENTORY) || |
||
491 | (change & CHANGED_REGION_START) || |
||
492 | (change & CHANGED_OWNER)) { |
||
493 | llResetScript(); |
||
494 | } |
||
495 | } |
||
496 | state_exit() { |
||
497 | llSetTimerEvent(0); |
||
498 | } |
||
499 | } |
||
500 | |||
501 | state listen_group { |
||
502 | state_entry() { |
||
503 | // DEBUG |
||
504 | llOwnerSay("[Reminders] Waiting for group messages."); |
||
505 | } |
||
506 | timer() { |
||
507 | if(!llGetListLength(recent_firstnames) || |
||
508 | !llGetListLength(recent_lastnames)) |
||
509 | return; |
||
510 | |||
511 | // DEBUG |
||
512 | llOwnerSay("[Reminders] Starting reminders sweep..."); |
||
513 | |||
514 | // jump to process the recents list |
||
515 | state search_trampoline; |
||
516 | } |
||
517 | link_message(integer sender, integer num, string message, key id) { |
||
518 | // We only care about notifications now. |
||
519 | if(id != "notification") |
||
520 | return; |
||
521 | |||
522 | // This script only processes group notifications. |
||
523 | if(wasKeyValueGet("type", message) != "group" || |
||
524 | (wasKeyValueGet("type", message) == "group" && |
||
525 | wasURLUnescape(wasKeyValueGet("group", message)) != |
||
526 | wasKeyValueGet("group", configuration))) |
||
527 | return; |
||
528 | |||
529 | // Get the message sender. |
||
530 | src_firstname = wasURLUnescape( |
||
531 | wasKeyValueGet( |
||
532 | "firstname", |
||
533 | message |
||
534 | ) |
||
535 | ); |
||
536 | |||
537 | src_lastname = wasURLUnescape( |
||
538 | wasKeyValueGet( |
||
539 | "lastname", |
||
540 | message |
||
541 | ) |
||
542 | ); |
||
543 | |||
544 | // Add the agent to the recents list. |
||
545 | if(llListFindList(recent_firstnames, (list)src_firstname) == -1 && |
||
546 | llListFindList(recent_lastnames, (list)src_lastname) == -1) { |
||
547 | recent_firstnames += src_firstname; |
||
548 | recent_lastnames += src_lastname; |
||
549 | } |
||
550 | |||
551 | // alarm 5 |
||
552 | llSetTimerEvent(10); |
||
553 | |||
554 | // Get the sent message. |
||
555 | data = wasURLUnescape( |
||
556 | wasKeyValueGet( |
||
557 | "message", |
||
558 | message |
||
559 | ) |
||
560 | ); |
||
561 | |||
562 | // Check if this is an eggdrop command. |
||
563 | if(llGetSubString(data, 0, 0) != |
||
564 | wasKeyValueGet("command", configuration)) |
||
565 | return; |
||
566 | |||
567 | // Check if the command matches the current module. |
||
568 | list command = llParseString2List(data, [" "], []); |
||
569 | if(llList2String(command, 0) != |
||
570 | wasKeyValueGet("command", configuration) + "remind") |
||
571 | return; |
||
572 | |||
573 | // Remove command. |
||
574 | command = llDeleteSubList(command, 0, 0); |
||
575 | |||
576 | // Retrieve the first and last name to remind. |
||
577 | dst_firstname = llList2String(command, 0); |
||
578 | command = llDeleteSubList(command, 0, 0); |
||
579 | dst_lastname = llList2String(command, 0); |
||
580 | command = llDeleteSubList(command, 0, 0); |
||
581 | |||
582 | if(llStringLength(dst_firstname) == 0 || |
||
583 | llStringLength(dst_lastname) == 0) { |
||
584 | data = "Invalid avatar name, please use the full username!"; |
||
585 | state tell; |
||
586 | } |
||
587 | |||
588 | // Retrieve the message to remind of. |
||
589 | text = llDumpList2String(command, " "); |
||
590 | if(llStringLength(message) == 0) { |
||
591 | data = "No message to remind of supplied. . ."; |
||
592 | state tell; |
||
593 | } |
||
594 | |||
595 | state validate; |
||
596 | } |
||
597 | on_rez(integer num) { |
||
598 | llResetScript(); |
||
599 | } |
||
600 | changed(integer change) { |
||
601 | if((change & CHANGED_INVENTORY) || |
||
602 | (change & CHANGED_REGION_START) || |
||
603 | (change & CHANGED_OWNER)) { |
||
604 | llResetScript(); |
||
605 | } |
||
606 | } |
||
607 | state_exit() { |
||
608 | llSetTimerEvent(0); |
||
609 | } |
||
610 | } |
||
611 | |||
612 | state validate { |
||
613 | state_entry() { |
||
614 | // DEBUG |
||
615 | llOwnerSay("[Reminders] Searching for agent."); |
||
616 | llInstantMessage( |
||
617 | wasKeyValueGet( |
||
618 | "corrade", |
||
619 | configuration |
||
620 | ), |
||
621 | wasKeyValueEncode( |
||
622 | [ |
||
623 | "command", "getmembers", |
||
624 | "group", wasURLEscape( |
||
625 | wasKeyValueGet( |
||
626 | "group", |
||
627 | configuration |
||
628 | ) |
||
629 | ), |
||
630 | "password", wasURLEscape( |
||
631 | wasKeyValueGet( |
||
632 | "password", |
||
633 | configuration |
||
634 | ) |
||
635 | ), |
||
636 | "sift", wasURLEscape( |
||
637 | wasListToCSV( |
||
638 | [ |
||
639 | "match", |
||
640 | wasURLEscape("(?i),?\"([^\",$]*" + dst_firstname + " " + dst_lastname + "[^\",$]*)\",?") |
||
641 | ] |
||
642 | ) |
||
643 | ), |
||
644 | "callback", wasURLEscape( |
||
645 | wasKeyValueGet( |
||
646 | "URL", |
||
647 | configuration |
||
648 | ) |
||
649 | ) |
||
650 | ] |
||
651 | ) |
||
652 | ); |
||
653 | llSetTimerEvent(60); |
||
654 | } |
||
655 | link_message(integer sender, integer num, string body, key id) { |
||
656 | // Only process callbacks for the database command. |
||
657 | if(id != "callback" || wasKeyValueGet("command", body) != "getmembers") |
||
658 | return; |
||
659 | |||
660 | if(wasKeyValueGet("success", body) != "True") { |
||
661 | // DEBUG |
||
662 | llOwnerSay("[Reminders] Unable to get members: " + |
||
663 | wasURLUnescape( |
||
664 | wasKeyValueGet("error", body) |
||
665 | ) |
||
666 | ); |
||
667 | state listen_group; |
||
668 | } |
||
669 | |||
670 | // Dump the members to a list. |
||
671 | list members = wasCSVToList( |
||
672 | wasURLUnescape( |
||
673 | wasKeyValueGet("data", body) |
||
674 | ) |
||
675 | ); |
||
676 | |||
677 | list name = llParseString2List( |
||
678 | llList2String(members, 0), |
||
679 | [" "], |
||
680 | [] |
||
681 | ); |
||
682 | |||
683 | dst_firstname = llList2String(name, 0); |
||
684 | dst_lastname = llList2String(name, 1); |
||
685 | |||
686 | if(llStringLength(dst_firstname) == 0 || |
||
687 | llStringLength(dst_lastname) == 0) { |
||
688 | data = "Invalid avatar name, please use the full username!"; |
||
689 | state tell; |
||
690 | } |
||
691 | |||
692 | action = "commit"; |
||
693 | state trampoline; |
||
694 | } |
||
695 | timer() { |
||
696 | state listen_group; |
||
697 | } |
||
698 | on_rez(integer num) { |
||
699 | llResetScript(); |
||
700 | } |
||
701 | changed(integer change) { |
||
702 | if((change & CHANGED_INVENTORY) || |
||
703 | (change & CHANGED_REGION_START) || |
||
704 | (change & CHANGED_OWNER)) { |
||
705 | llResetScript(); |
||
706 | } |
||
707 | } |
||
708 | state_exit() { |
||
709 | llSetTimerEvent(0); |
||
710 | } |
||
711 | } |
||
712 | |||
713 | state search_trampoline { |
||
714 | state_entry() { |
||
715 | // pop |
||
716 | if(!llGetListLength(recent_firstnames) || |
||
717 | !llGetListLength(recent_lastnames)) { |
||
718 | state listen_group; |
||
719 | } |
||
720 | dst_firstname = llList2String(recent_firstnames, 0); |
||
721 | recent_firstnames = llDeleteSubList(recent_firstnames, 0, 0); |
||
722 | dst_lastname = llList2String(recent_lastnames, 0); |
||
723 | recent_lastnames = llDeleteSubList(recent_lastnames, 0, 0); |
||
724 | |||
725 | // wend |
||
726 | action = "search"; |
||
727 | state trampoline; |
||
728 | } |
||
729 | } |
||
730 | |||
731 | state remind { |
||
732 | state_entry() { |
||
733 | // DEBUG |
||
734 | llOwnerSay("[Reminders] Reminding..."); |
||
735 | llInstantMessage( |
||
736 | wasKeyValueGet( |
||
737 | "corrade", |
||
738 | configuration |
||
739 | ), |
||
740 | wasKeyValueEncode( |
||
741 | [ |
||
742 | "command", "tell", |
||
743 | "group", wasURLEscape( |
||
744 | wasKeyValueGet( |
||
745 | "group", |
||
746 | configuration |
||
747 | ) |
||
748 | ), |
||
749 | "password", wasURLEscape( |
||
750 | wasKeyValueGet( |
||
751 | "password", |
||
752 | configuration |
||
753 | ) |
||
754 | ), |
||
755 | "entity", "group", |
||
756 | "message", wasURLEscape(data) |
||
757 | ] |
||
758 | ) |
||
759 | ); |
||
760 | |||
761 | action = "remove"; |
||
762 | state trampoline; |
||
763 | } |
||
764 | } |
||
765 | |||
766 | state tell { |
||
767 | state_entry() { |
||
768 | // DEBUG |
||
769 | llOwnerSay("[Reminders] Sending to group."); |
||
770 | llInstantMessage( |
||
771 | wasKeyValueGet( |
||
772 | "corrade", |
||
773 | configuration |
||
774 | ), |
||
775 | wasKeyValueEncode( |
||
776 | [ |
||
777 | "command", "tell", |
||
778 | "group", wasURLEscape( |
||
779 | wasKeyValueGet( |
||
780 | "group", |
||
781 | configuration |
||
782 | ) |
||
783 | ), |
||
784 | "password", wasURLEscape( |
||
785 | wasKeyValueGet( |
||
786 | "password", |
||
787 | configuration |
||
788 | ) |
||
789 | ), |
||
790 | "entity", "group", |
||
791 | "message", wasURLEscape(data) |
||
792 | ] |
||
793 | ) |
||
794 | ); |
||
795 | state listen_group; |
||
796 | } |
||
797 | } |