'Open Source Scripting' group (Second Life) wiki

Pandora Chatbot

Modified: 17/04/2007 18:01 by 198.188.134.45

An ALICE base chatbot hosted at Pandorabots.com



Place these two scripts in an object. The first one is the listener for you to customize and control who it listens to. The second one is the actual engine itself.

public/Upload/listen.lsl

listen script
 
         
string mesg;
key gOwner;
list talkers;

listen_to(key talker) { integer index = llListFindList( talkers, [talker] ); if ( index != -1 ) { talkers = llDeleteSubList(talkers, index, index); llMessageLinked(LINK_SET,0,"BYE",talker); } else { talkers = talkers + talker; llMessageLinked(LINK_SET,0,"HI",talker); } }

default { state_entry() { gOwner = llGetOwner(); llListen(0,"",NULL_KEY,""); }

on_rez(integer i) { llWhisper(0,"Owner say /chat or touch me"); llResetScript(); } touch_start(integer num_detected) { listen_to(llDetectedKey(0)); }

listen(integer channel, string name, key id, string msg) { if (msg == "/chat") { listen_to(id); return; } if ((msg == "/reset") && (id == gOwner)) { llWhisper(0,"Resetting"); llResetScript(); }

integer index = llListFindList( talkers, [id] ); if (index != -1) { mesg = llToLower(msg); llMessageLinked(LINK_SET,0,msg,id); } }

}


public/Upload/pandorabot.lsl

pandorabot script
key requestid;
string botid;
string cust;
string reply;
string newreply;
integer that_begin;
integer that_end;
integer cust_begin;

string SearchAndReplace(string input, string old, string new) { return llDumpList2String(llParseString2List(input, [old], []), new); }

default { state_entry() { cust=""; botid="b1e9139eee362838"; }

on_rez(integer param) { llResetScript(); }

link_message(integer sender_num, integer num, string msg, key id) { requestid = llHTTPRequest("http://www.pandorabots.com/pandora/talk-xml?botid="+botid+"&input="+llEscapeURL(msg)+"&custid="+cust,[HTTP_METHOD,"POST"],""); } http_response(key request_id, integer status, list metadata, string body) { if (request_id == requestid) { cust_begin=llSubStringIndex(body, "custid="); cust=llGetSubString(body, cust_begin+8, cust_begin+23); that_begin = llSubStringIndex(body, "<@that>"); // this should be < that > (delete @) that_end = llSubStringIndex(body, "<@/that>"); //this should be < / that > (delete @) reply = llGetSubString(body, that_begin + 6, that_end - 1); newreply = SearchAndReplace(reply, "%20", " "); reply = newreply; newreply = SearchAndReplace(reply,"&@quot;","\""); //this should be & quot; (delete @) the wiki changes it to " reply = newreply; newreply = SearchAndReplace(reply,"&@lt;br&@gt;","\n"); //the first search should be & lt;br & gt; (delete @) reply = newreply; newreply = SearchAndReplace(reply, "&@gt;", ">"); //the first search should be & gt; (delete @) reply = newreply; newreply = SearchAndReplace(reply, "&@lt;", "<"); //this first search should be & lt; llSay(0,newreply); } } }

ScrewTurn Wiki version 1.0.11. Some of the icons created by FamFamFam.