Skip to content

Instantly share code, notes, and snippets.

@ecmelkytz
Created February 14, 2014 16:14
Show Gist options
  • Save ecmelkytz/9003889 to your computer and use it in GitHub Desktop.
Save ecmelkytz/9003889 to your computer and use it in GitHub Desktop.
Second Life connection with the pandorabots
key requestid;
key user;
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="a303fe9e9e340b"; //Buraya kendi Bot ID numaranızı yerleştiriniz
} on_rez(integer param)
{
llResetScript();
}
link_message(integer sender_num, integer num, string msg, key id)
{
// llSay(0,"sende "+msg);
user = 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);
// llSay(0,body);
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);
// llSay(0,"##1:"+reply);
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); // ausgabe im chat
llInstantMessage(user, newreply); // ausgabe als IM
}
}
}
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);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment