I have created a little accessory for the Twitter-service in SL. It allows you to move around in the world with the "stylish" possibility to send some updates to twitter. I call it the "Twitter Wristlet", because its a wristlet. ;)
The only differences between the wristlet and my other fixed Twitter-service are the following:
- The wristlet doesn't create objects on which the tweets (status-updates) are displayed. I just prints them to screen using llOwnerSay.
- Because it can be very disturbing to have half of the screen full of Twitter-updates, you can stop/start the timer which receives the tweets.
The LSL-code for the wristlet looks like that. I use the Chatchannel 998 for communicating with the wristlet.
key requestId;
list resultList;
string rawList;
float refreshTime = 30.0;
default
{
state_entry()
{
integer i;
rawList = "";
llSetTimerEvent(refreshTime);
llListen(998, "", llGetOwner(), "" );
}
listen(integer channel, string name, key id, string message) {
if(message == "#stop#") {
// stops the automatic refresh of the tweets
llSetTimerEvent(0.0);
llOwnerSay("The automatic refresh has been stopped. Reactivate using #start#");
} else if(message == "#start#") {
llSetTimerEvent(refreshTime);
llOwnerSay("Refresh will taking place every " + (string)refreshTime + " seconds. Stop using #stop#");
} else {
llOwnerSay("trying to send your status message: " + message);
llHTTPRequest("###YOUR RUBY URL###/twitter/post_message",[HTTP_METHOD,"POST", HTTP_MIMETYPE, "application/x-www-form-urlencoded"],"msg="+message);
llOwnerSay("ok, status has been sent.");
}
}
timer() {
llOwnerSay("loading tweets...");
requestId = llHTTPRequest("###YOUR RUBY URL###/twitter/get_messages?type=public",[HTTP_METHOD,"GET"],"");
}
http_response(key request_id, integer status, list metadata, string body) {
integer i;
if (request_id == requestId) {
rawList = body;
// create the boxes from the list information
resultList = llParseString2List(body,["\n"],[]);
integer listlength = llGetListLength(resultList);
float boxPosition = 1;
for(i=0;i<listlength;i+=1) {
string statusLineWithName = llList2String(resultList, i);
list statusParts = llParseString2List(statusLineWithName, ["|"], []);
string text = llList2String(statusParts, 0);
string name = llList2String(statusParts, 1);
llOwnerSay(name + ": " + text);
}
} else {
// llSay(0,(string)status+" error");
}
}
}
3 comments:
Hey this sounds great! But how do we get it, or created it?
The linden script code is included in this post. As a backend for connecting to twitter i use the Ruby on Rails stuff i wrote about in one of my last postings.
The only way to use it now, is to setup your own server & co.
But i will think about a way, that also other users can use my server. :) So stay tuned.
Ok thanks, do let me know!
Post a Comment