/source/eggdrop/ai.lsl |
@@ -179,6 +179,8 @@ |
string URL = ""; |
// store message over state. |
string data = ""; |
string jump_table = ""; |
string messageHash = ""; |
|
default { |
state_entry() { |
@@ -189,7 +191,10 @@ |
if(id != "configuration") return; |
llOwnerSay("[AI] Got configuration..."); |
configuration = message; |
state listen_group; |
|
// Subscribe to MQTT messages. |
jump_table = "subscribe"; |
state url; |
} |
timer() { |
llOwnerSay("[AI] Requesting configuration..."); |
@@ -210,6 +215,135 @@ |
} |
} |
|
state url { |
state_entry() { |
// DEBUG |
llOwnerSay("[AI] Requesting URL..."); |
llRequestURL(); |
} |
http_request(key id, string method, string body) { |
if(method != URL_REQUEST_GRANTED) return; |
URL = body; |
|
// DEBUG |
llOwnerSay("[AI] Got URL..."); |
|
if(jump_table == "subscribe") |
state subscribe; |
if(jump_table == "publish") |
state publish; |
} |
on_rez(integer num) { |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
} |
} |
|
state subscribe { |
state_entry() { |
// DEBUG |
llOwnerSay("[AI] Subscribing to Corrade AI..."); |
llInstantMessage( |
wasKeyValueGet( |
"corrade", |
configuration |
), |
wasKeyValueEncode( |
[ |
"command", "MQTT", |
"group", wasURLEscape( |
wasKeyValueGet( |
"group", |
configuration |
) |
), |
"password", wasURLEscape( |
wasKeyValueGet( |
"password", |
configuration |
) |
), |
// Subscribe to Corrade AI |
"action", "subscribe", |
"id", wasURLEscape( |
wasKeyValueGet( |
"ai subscription", |
configuration |
) |
), |
// Corrade AI listening host. |
"host", wasURLEscape( |
wasKeyValueGet( |
"ai host", |
configuration |
) |
), |
// Corrade AI listening port. |
"port", wasURLEscape( |
wasKeyValueGet( |
"ai port", |
configuration |
) |
), |
// Corrade AI credentials. |
"username", wasURLEscape( |
wasKeyValueGet( |
"ai username", |
configuration |
) |
), |
"secret", wasURLEscape( |
wasKeyValueGet( |
"ai secret", |
configuration |
) |
), |
// Use the SIML module of Corrade AI. |
"topic", "SIML", |
// Send the result of the MQTT command to this URL. |
"callback", wasURLEscape(URL) |
] |
) |
); |
} |
|
http_request(key id, string method, string body) { |
llHTTPResponse(id, 200, "OK"); |
llReleaseURL(URL); |
if(wasKeyValueGet("command", body) != "MQTT" || |
wasKeyValueGet("success", body) != "True") { |
// DEBUG |
llOwnerSay("[AI] Unable to subscribe to MQTT topic: " + |
wasURLUnescape( |
wasKeyValueGet("error", body) |
) |
); |
llResetScript(); |
} |
|
state listen_group; |
} |
on_rez(integer num) { |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
} |
state_exit() { |
llSetTimerEvent(0); |
} |
} |
|
state listen_group { |
state_entry() { |
// DEBUG |
@@ -220,7 +354,7 @@ |
if(id != "notification") |
return; |
|
// This script only processes group notifications. |
// Listen to group message notifications. |
if(wasKeyValueGet("type", message) != "group") |
return; |
|
@@ -251,6 +385,7 @@ |
data = llDumpList2String(command, " "); |
|
// Get an URL. |
jump_table = "publish"; |
state url; |
} |
on_rez(integer num) { |
@@ -265,35 +400,13 @@ |
} |
} |
|
state url { |
state publish { |
state_entry() { |
// DEBUG |
llOwnerSay("[AI] Requesting URL..."); |
llRequestURL(); |
} |
http_request(key id, string method, string body) { |
if(method != URL_REQUEST_GRANTED) return; |
URL = body; |
// DEBUG |
llOwnerSay("[AI] Got URL..."); |
state version; |
} |
on_rez(integer num) { |
llResetScript(); |
} |
changed(integer change) { |
if((change & CHANGED_INVENTORY) || |
(change & CHANGED_REGION_START) || |
(change & CHANGED_OWNER)) { |
llResetScript(); |
} |
} |
} |
|
state version { |
state_entry() { |
// DEBUG |
llOwnerSay("[AI] Sending to AI for processing..."); |
|
messageHash = llSHA1String(data); |
|
llInstantMessage( |
wasKeyValueGet( |
"corrade", |
@@ -301,7 +414,7 @@ |
), |
wasKeyValueEncode( |
[ |
"command", "ai", |
"command", "MQTT", |
"group", wasURLEscape( |
wasKeyValueGet( |
"group", |
@@ -314,8 +427,48 @@ |
configuration |
) |
), |
"action", "process", |
"message", wasURLEscape(data), |
"action", "publish", |
// Corrade AI listening host. |
"host", wasURLEscape( |
wasKeyValueGet( |
"ai host", |
configuration |
) |
), |
// Corrade AI listening port. |
"port", wasURLEscape( |
wasKeyValueGet( |
"ai port", |
configuration |
) |
), |
// Corrade AI credentials. |
"username", wasURLEscape( |
wasKeyValueGet( |
"ai username", |
configuration |
) |
), |
"secret", wasURLEscape( |
wasKeyValueGet( |
"ai secret", |
configuration |
) |
), |
// Use the SIML module of Corrade AI. |
"topic", "SIML", |
"payload", wasURLEscape( |
wasKeyValueEncode( |
[ |
// The hash is an identifier that will allow responses from Corrade AI |
// for various messages to be distinguished. It can be any identifier |
// but a handy way of generating an identifier is to hash the message. |
"Hash", messageHash, |
// Note the double escaping! |
"Message", wasURLEscape(data) |
] |
) |
), |
"callback", wasURLEscape(URL) |
] |
) |
@@ -325,20 +478,63 @@ |
http_request(key id, string method, string body) { |
llHTTPResponse(id, 200, "OK"); |
llReleaseURL(URL); |
if(wasKeyValueGet("command", body) != "ai" || |
if(wasKeyValueGet("command", body) != "MQTT" || |
wasKeyValueGet("success", body) != "True") { |
// DEBUG |
llOwnerSay("[AI] Unable to get processed message: " + |
llOwnerSay("[AI] Unable to publish message: " + |
wasURLUnescape( |
wasKeyValueGet("error", body) |
wasKeyValueGet("data", body) |
) |
); |
state listen_group; |
} |
|
// Get the processed message. |
data = wasKeyValueGet("data", body); |
// DEBUG |
llOwnerSay("[AI] Message published successfully..."); |
} |
link_message(integer sender, integer num, string message, key id) { |
// We only care about notifications now. |
if(id != "notification") |
return; |
|
// Listen to MQTT messages. |
if(wasKeyValueGet("type", message) != "MQTT") |
return; |
|
// Get the sent message. |
data = wasURLUnescape( |
wasKeyValueGet( |
"payload", |
message |
) |
); |
|
string hash = wasURLUnescape( |
wasKeyValueGet( |
"Hash", |
data |
) |
); |
|
string serverMessage = wasURLUnescape( |
wasKeyValueGet( |
"ServerMessage", |
data |
) |
); |
|
// Skip generated messages that are not for the published message. |
if(hash != messageHash || |
serverMessage != "True") |
return; |
|
data = wasURLUnescape( |
wasKeyValueGet( |
"Message", |
data |
) |
); |
|
state tell; |
} |
timer() { |
@@ -385,7 +581,7 @@ |
) |
), |
"entity", "group", |
"message", data // message is already encoded |
"message", wasURLEscape(data) |
] |
) |
); |
/source/eggdrop/motd.lsl |
@@ -5,7 +5,7 @@ |
// A MOTD module for Corrade Eggdrop. |
// |
/////////////////////////////////////////////////////////////////////////// |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2014 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
@@ -32,7 +32,7 @@ |
} while(llGetListLength(k) != 0); |
return llDumpList2String(data, "&"); |
} |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2011 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
@@ -44,7 +44,7 @@ |
return <x, y, 0>; |
return wasCirclePoint(radius); |
} |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
@@ -68,7 +68,7 @@ |
} while(i != ""); |
return o; |
} |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
@@ -107,7 +107,7 @@ |
// postcondition: length(s) = 0 |
return l + m; |
} |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
@@ -136,7 +136,7 @@ |
} while(l != []); |
return llDumpList2String(v, ","); |
} |
|
|
/////////////////////////////////////////////////////////////////////////// |
// Copyright (C) 2015 Wizardry and Steamworks - License: GNU GPLv3 // |
/////////////////////////////////////////////////////////////////////////// |
@@ -160,7 +160,7 @@ |
) |
); |
} |
|
|
// configuration data |
string configuration = ""; |
// callback URL |
@@ -171,7 +171,7 @@ |
string group = ""; |
string data = ""; |
string jump_state = ""; |
|
|
default { |
state_entry() { |
llOwnerSay("[MOTD] Starting module..."); |
@@ -202,7 +202,7 @@ |
llSetTimerEvent(0); |
} |
} |
|
|
state url { |
state_entry() { |
// DEBUG |
@@ -224,7 +224,7 @@ |
state set; |
if(jump_state == "listen_group") |
state listen_group; |
|
|
// DEBUG |
llOwnerSay("[MOTD] Jump table corrupted, please contact creator..."); |
llResetScript(); |
@@ -240,11 +240,11 @@ |
} |
} |
} |
|
|
state create_database { |
state_entry() { |
// DEBUG |
llOwnerSay("[MOTD] Creating database."); |
llOwnerSay("[MOTD] Creating database: " + wasKeyValueGet("motd table", configuration)); |
llInstantMessage( |
wasKeyValueGet( |
"corrade", |
@@ -283,7 +283,12 @@ |
llOwnerSay("[MOTD] Unable modify database: " + |
wasURLUnescape( |
wasKeyValueGet("error", body) |
) + |
" " + |
wasURLUnescape( |
wasKeyValueGet("data", body) |
) |
|
); |
llResetScript(); |
} |
@@ -308,8 +313,8 @@ |
llSetTimerEvent(0); |
} |
} |
|
|
|
|
state listen_group { |
state_entry() { |
// DEBUG |
@@ -319,7 +324,7 @@ |
// We only care about notifications now. |
if(id != "notification") |
return; |
|
|
// Get the group. |
group = wasURLUnescape( |
wasKeyValueGet( |
@@ -327,7 +332,7 @@ |
message |
) |
); |
|
|
// Retrieve the membership notification. |
if(wasKeyValueGet("type", message) == "membership" && |
wasKeyValueGet("action", message) == "joined") { |
@@ -346,11 +351,11 @@ |
jump_state = "greet"; |
state url; |
} |
|
|
// This script only processes group notifications. |
if(wasKeyValueGet("type", message) != "group") |
return; |
|
|
// Get the sent message. |
data = wasURLUnescape( |
wasKeyValueGet( |
@@ -358,30 +363,30 @@ |
message |
) |
); |
|
|
// Check if this is an eggdrop command. |
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) != |
wasKeyValueGet("command", configuration) + "motd") |
return; |
|
|
// Remove command. |
command = llDeleteSubList(command, 0, 0); |
|
|
// Dump the rest of the message. |
data = llDumpList2String(command, " "); |
|
|
// Get the sent message. |
if(data == "") { |
jump_state = "get"; |
state url; |
} |
|
|
jump_state = "set"; |
state url; |
} |
@@ -396,7 +401,7 @@ |
} |
} |
} |
|
|
state greet { |
state_entry() { |
// DEBUG |
@@ -451,7 +456,7 @@ |
); |
state listen_group; |
} |
|
|
data = llDumpList2String( |
llDeleteSubList( |
wasCSVToList( |
@@ -464,10 +469,10 @@ |
), |
"" |
); |
|
|
if(data == "") |
state listen_group; |
|
|
data = "Hello " + firstname + " " + lastname + "!" + " " + data; |
state tell; |
} |
@@ -489,7 +494,7 @@ |
llSetTimerEvent(0); |
} |
} |
|
|
state get { |
state_entry() { |
// DEBUG |
@@ -521,7 +526,12 @@ |
wasListToCSV( |
[ |
"group", |
wasURLEscape(group) |
wasURLEscape( |
wasKeyValueGet( |
"group", |
configuration |
) |
) |
] |
) |
), |
@@ -544,7 +554,7 @@ |
); |
state listen_group; |
} |
|
|
data = llDumpList2String( |
llDeleteSubList( |
wasCSVToList( |
@@ -557,12 +567,12 @@ |
), |
"" |
); |
|
|
if(data == "") { |
data = "Sorry, no MOTD is currently set."; |
state tell; |
} |
|
|
state tell; |
} |
timer() { |
@@ -583,7 +593,7 @@ |
llSetTimerEvent(0); |
} |
} |
|
|
state set { |
state_entry() { |
// DEBUG |
@@ -615,7 +625,12 @@ |
wasListToCSV( |
[ |
"name", |
wasURLEscape(group), |
wasURLEscape( |
wasKeyValueGet( |
"group", |
configuration |
) |
), |
"data", |
wasURLEscape(data) |
] |
@@ -661,7 +676,7 @@ |
llSetTimerEvent(0); |
} |
} |
|
|
state tell { |
state_entry() { |
// DEBUG |