/source/eggdrop/wiki.lsl |
@@ -1,5 +1,5 @@ |
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2016 - License: CC BY 2.0 // |
// Copyright (C) Wizardry and Steamworks 2016 - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
// |
// A wiki module that can memorize strings and recall them by path. |
@@ -7,11 +7,11 @@ |
/////////////////////////////////////////////////////////////////////////// |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) Wizardry and Steamworks 2014 - License: CC BY 2.0 // |
// Copyright (C) Wizardry and Steamworks 2014 - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
integer wasIsAlNum(string a) { |
if(a == "") return FALSE; |
integer x = llBase64ToInteger("AAAA" + |
integer x = llBase64ToInteger("AAAA" + |
llStringToBase64(llGetSubString(a, 0, 0))); |
return (x >= 65 && x <= 90) || (x >= 97 && x <= 122) || |
(x >= 48 && x <= 57); |
@@ -28,9 +28,9 @@ |
if(i != -1) return llList2String(a, 2*i+1); |
return ""; |
} |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2013 Wizardry and Steamworks - License: CC BY 2.0 // |
// Copyright (C) 2013 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
string wasKeyValueEncode(list data) { |
list k = llList2ListStrided(data, 0, -1, 2); |
@@ -45,7 +45,7 @@ |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
// escapes a string in conformance with RFC1738 |
string wasURLEscape(string i) { |
@@ -69,7 +69,7 @@ |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
list wasCSVToList(string csv) { |
list l = []; |
@@ -108,7 +108,7 @@ |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
string wasListToCSV(list l) { |
list v = []; |
@@ -116,18 +116,18 @@ |
string a = llDumpList2String( |
llParseStringKeepNulls( |
llList2String( |
l, |
l, |
0 |
), |
["\""], |
), |
["\""], |
[] |
), |
"\"\"" |
); |
if(llParseStringKeepNulls( |
a, |
a, |
[" ", ",", "\n", "\""], [] |
) != |
) != |
(list) a |
) a = "\"" + a + "\""; |
v += a; |
@@ -137,7 +137,7 @@ |
} |
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: CC BY 2.0 // |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
// unescapes a string in conformance with RFC1738 |
string wasURLUnescape(string i) { |
@@ -146,15 +146,15 @@ |
llParseString2List( |
llDumpList2String( |
llParseString2List( |
i, |
["+"], |
i, |
["+"], |
[] |
), |
), |
" " |
), |
["%0D%0A"], |
), |
["%0D%0A"], |
[] |
), |
), |
"\n" |
) |
); |
@@ -162,8 +162,6 @@ |
|
// configuration data |
string configuration = ""; |
// callback URL |
string URL = ""; |
// store message over state. |
string path = ""; |
string data = ""; |
@@ -181,7 +179,7 @@ |
llOwnerSay("[Wiki] Got configuration..."); |
configuration = message; |
action = "create"; |
state url; |
state trampoline; |
} |
timer() { |
llOwnerSay("[Wiki] Requesting configuration..."); |
@@ -191,8 +189,8 @@ |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
@@ -202,28 +200,18 @@ |
} |
} |
|
state url { |
state trampoline { |
state_entry() { |
// DEBUG |
llOwnerSay("[Wiki] Requesting URL..."); |
llRequestURL(); |
} |
http_request(key id, string method, string body) { |
if(method != URL_REQUEST_GRANTED) return; |
URL = body; |
// DEBUG |
llOwnerSay("[Wiki] Got URL."); |
|
if(action == "create") { |
statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + |
wasKeyValueGet("wiki table", configuration) + |
statement = wasURLEscape("CREATE TABLE IF NOT EXISTS \"" + |
wasKeyValueGet("wiki table", configuration) + |
"\" (path text unique collate nocase, data text)"); |
state query; |
} |
|
|
if(action == "get") { |
statement = wasURLEscape("SELECT data FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
wasKeyValueGet("wiki table", configuration) + |
"\" WHERE path=:path"); |
parameters = wasURLEscape( |
wasListToCSV( |
@@ -235,11 +223,11 @@ |
); |
state query; |
} |
|
|
if(action == "set") { |
if(data == "") { |
statement = wasURLEscape("DELETE FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
statement = wasURLEscape("DELETE FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"\" WHERE path=:path"); |
parameters = wasURLEscape( |
wasListToCSV( |
@@ -252,7 +240,7 @@ |
state query; |
} |
statement = wasURLEscape("REPLACE INTO \"" + |
wasKeyValueGet("wiki table", configuration) + |
wasKeyValueGet("wiki table", configuration) + |
"\" (path, data) VALUES (:path, :data)"); |
parameters = wasURLEscape( |
wasListToCSV( |
@@ -266,13 +254,13 @@ |
); |
state query; |
} |
|
|
if(action == "dir") { |
if(path == "/") { |
path = ""; |
statement = wasURLEscape( |
"SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"SELECT DISTINCT SUBSTR(path, 1, LENGTH(path) - LENGTH(LTRIM(SUBSTR(path,2), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"\" WHERE path LIKE '/%' LIMIT " + |
wasKeyValueGet("wiki results limit", configuration) |
); |
@@ -279,8 +267,8 @@ |
state query; |
} |
statement = wasURLEscape( |
"SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"SELECT DISTINCT SUBSTR(REPLACE(path, :base, ''),1, LENGTH(REPLACE(path, :base, '')) - LENGTH(LTRIM(REPLACE(path, :base, ''), 'abcdefghijklmnopqrstuvwxyz'))) AS path FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"\" WHERE path LIKE :path LIMIT " + |
wasKeyValueGet("wiki results limit", configuration) |
); |
@@ -290,7 +278,7 @@ |
"path", |
wasURLEscape(path + "/" + "%"), |
"base", |
wasURLEscape("/" + |
wasURLEscape("/" + |
llDumpList2String( |
llParseString2List( |
path, |
@@ -298,7 +286,7 @@ |
[] |
), |
"/" |
) + |
) + |
"/" |
) |
] |
@@ -306,7 +294,7 @@ |
); |
state query; |
} |
|
|
if(action == "find") { |
if(data == "") { |
data = "Command requires two parameters: a path followed by a search term."; |
@@ -313,10 +301,10 @@ |
state tell; |
} |
if(path == "/") |
path = ""; |
path = ""; |
statement = wasURLEscape( |
"SELECT DISTINCT path FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"SELECT DISTINCT path FROM \"" + |
wasKeyValueGet("wiki table", configuration) + |
"\" WHERE path LIKE :path AND ( data LIKE :data OR path LIKE :data ) COLLATE NOCASE LIMIT " + |
wasKeyValueGet("wiki search limit", configuration) |
); |
@@ -332,7 +320,7 @@ |
); |
state query; |
} |
|
|
// DEBUG |
llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); |
llResetScript(); |
@@ -341,8 +329,8 @@ |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
@@ -358,35 +346,38 @@ |
// We only care about notifications now. |
if(id != "notification") |
return; |
|
|
// This script only processes group notifications. |
if(wasKeyValueGet("type", message) != "group") |
if(wasKeyValueGet("type", message) != "group" || |
(wasKeyValueGet("type", message) == "group" && |
wasURLUnescape(wasKeyValueGet("group", message)) != |
wasKeyValueGet("group", configuration))) |
return; |
|
|
// Get the sent message. |
data = wasURLUnescape( |
wasKeyValueGet( |
"message", |
"message", |
message |
) |
); |
|
|
// Check if this is an eggdrop command. |
if(llGetSubString(data, 0, 0) != |
if(llGetSubString(data, 0, 0) != |
wasKeyValueGet("command", configuration)) |
return; |
|
|
// Check if the command matches the current module. |
list command = llParseString2List(data, [" "], []); |
if(llList2String(command, 0) != |
if(llList2String(command, 0) != |
wasKeyValueGet("command", configuration) + "wiki") |
return; |
|
|
// Remove command. |
command = llDeleteSubList(command, 0, 0); |
|
|
// Check for supported sub-commands. |
if(llList2String(command, 0) != "set" && |
if(llList2String(command, 0) != "set" && |
llList2String(command, 0) != "get" && |
llList2String(command, 0) != "dir" && |
llList2String(command, 0) != "find") { |
@@ -393,27 +384,27 @@ |
data = "Subcommands are: get, set, dir or find"; |
state tell; |
} |
|
|
// Get the sub-command and store it as a jump state. |
action = llList2String(command, 0); |
|
|
// Remove sub-command. |
command = llDeleteSubList(command, 0, 0); |
|
|
// Get the path parts. |
list path_parts = llParseString2List( |
llList2String(command, 0), ["/"], [] |
); |
|
|
// Dump the path and store it over states. |
path = llStringTrim( |
llDumpList2String( |
path_parts, |
path_parts, |
"/" |
), |
), |
STRING_TRIM |
); |
|
|
if(path != "") { |
integer i = llStringLength(path) - 1; |
do { |
@@ -424,24 +415,23 @@ |
} |
} while(--i > -1); |
} |
|
|
path = "/" + path; |
|
|
// Remove path. |
command = llDeleteSubList(command, 0, 0); |
|
|
// Dump the rest of the message. |
data = llDumpList2String(command, " "); |
|
// Get an URL. |
state url; |
|
state trampoline; |
} |
on_rez(integer num) { |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
@@ -456,35 +446,44 @@ |
"command", "database", |
"group", wasURLEscape( |
wasKeyValueGet( |
"group", |
"group", |
configuration |
) |
), |
"password", wasURLEscape( |
wasKeyValueGet( |
"password", |
"password", |
configuration |
) |
), |
"SQL", statement, |
"data", parameters, |
"callback", wasURLEscape(URL) |
"callback", wasURLEscape( |
wasKeyValueGet( |
"URL", |
configuration |
) |
) |
] |
); |
|
// GC - none of these are needed anymore. |
statement = ""; |
parameters = ""; |
|
// Message length check. |
if(llStringLength(message) > 1023) { |
data = "Message length exceeded 1023 characters."; |
state tell; |
} |
|
// DEBUG |
llOwnerSay("[Wiki] Executing action: " + action); |
llInstantMessage( |
wasKeyValueGet( |
"corrade", |
"corrade", |
configuration |
), |
), |
message |
); |
// GC |
@@ -491,13 +490,14 @@ |
message = ""; |
llSetTimerEvent(60); |
} |
http_request(key id, string method, string body) { |
llHTTPResponse(id, 200, "OK"); |
llReleaseURL(URL); |
if(wasKeyValueGet("command", body) != "database" || |
wasKeyValueGet("success", body) != "True") { |
link_message(integer sender, integer num, string body, key id) { |
// Only process callbacks for the database command. |
if(id != "callback" || wasKeyValueGet("command", body) != "database") |
return; |
|
if(wasKeyValueGet("success", body) != "True") { |
// DEBUG |
llOwnerSay("[Wiki] Unable query database: " + |
llOwnerSay("[Wiki] Unable query database: " + |
wasURLUnescape( |
wasKeyValueGet("error", body) |
) |
@@ -504,9 +504,8 @@ |
); |
state listen_group; |
} |
|
|
// Process actions. |
|
if(action == "set") { |
if(data == "") { |
data = "Deleted from " + path; |
@@ -554,16 +553,16 @@ |
), |
"" |
); |
|
|
if(data == "") { |
data = "Sorry, that path contains no data."; |
state tell; |
} |
|
|
data = path + ": " + data; |
state tell; |
} |
|
|
if(action == "dir") { |
list paths = llList2ListStrided( |
llDeleteSubList( |
@@ -579,35 +578,35 @@ |
-1, |
2 |
); |
|
|
if(llGetListLength(paths) == 0) { |
data = "Sorry, that path contains no sub-paths."; |
state tell; |
} |
|
|
// Eliminate path component. |
if(path == "/") |
path = ""; |
|
|
list sibling = []; |
do { |
// Get the path part. |
string part = llList2String(paths, 0); |
|
|
// Remove the path component. |
string child = llStringTrim( |
llDumpList2String( |
llParseString2List( |
part, |
[path, "/"], |
[path, "/"], |
[] |
), |
"/" |
), |
STRING_TRIM |
|
|
); |
|
|
integer i = llSubStringIndex(child, "/"); |
if(i == -1) { |
sibling += path + "/" + child; |
@@ -619,24 +618,23 @@ |
@continue_dir; |
paths = llDeleteSubList(paths, 0, 0); |
} while(llGetListLength(paths) != 0); |
|
|
data = llList2CSV(sibling); |
// GC |
sibling = []; |
|
|
state tell; |
} |
|
|
// Don't announce creating table. |
if(action == "create") |
state listen_group; |
|
|
// DEBUG |
llOwnerSay("[Wiki] Jump table corrupted, please contact creator..."); |
state listen_group; |
} |
timer() { |
llReleaseURL(URL); |
state listen_group; |
} |
on_rez(integer num) { |
@@ -643,8 +641,8 @@ |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
@@ -660,21 +658,21 @@ |
llOwnerSay("[Wiki] Sending to group."); |
llInstantMessage( |
wasKeyValueGet( |
"corrade", |
"corrade", |
configuration |
), |
), |
wasKeyValueEncode( |
[ |
"command", "tell", |
"group", wasURLEscape( |
wasKeyValueGet( |
"group", |
"group", |
configuration |
) |
), |
"password", wasURLEscape( |
wasKeyValueGet( |
"password", |
"password", |
configuration |
) |
), |