TwitterBox Twitter Script
Writing by admin on Wednesday, 14 of March , 2007 at 6:24 pm
Here is the wonderful code by Ordinal Malaprop which will enable you to Twitter from SecondLife as well as recieve Twitter updates in SecondLife.
You simply create a prim and put this script into that prim after editing the script with your own email and password for your Twitter account.
This code also features an animation (you can drop your own animation in named “Twitter”) and a prim “Twitterball” which rezzes and creates particles in the shape of musical notation. The Twitterbox starts the animation and also makes the sound when in “private” mode.
// Twitterbox v0.2
// Post to Twitter and receive updates from within SL
// Ordinal Malaprop
// 2007-03-08
// Free for distribution and use, but if you use it in something else
// I would like at least a mention.
//------------------------------------------------------------------
// Edit these to your own specifications
// The email address you signed up to Twitter with
string EMAIL = "your@emailaddress.com";
// Your Twitter password
string PASS = "123xxx";
// This is the URL of the intermediary script. Don't change it unless
// you are using an intermediary of your own.
string TWITTERPING = "http://ordinalmalaprop.com/twitter/control-0.2.php";
// Leave these alone.
integer gTime = 0;
integer gCode = 0;
string gScreenName = "";
integer gManual = FALSE;
// gNotify defines the type of notification
// 0 = none
// 1 = private sound
// 2 = full animation and public sound
integer gNotify = 2;
//------------------------------------------------------------------
key twitter_send(string action, string subject)
{
if (EMAIL == "" || PASS == "") {
llOwnerSay("No email/password set - edit script and try again");
return NULL_KEY;
}
else {
vector pos = llGetPos();
return llHTTPRequest(TWITTERPING,
[HTTP_METHOD, "POST"],
EMAIL + "\n" + PASS + "\n" + action + "\n" + subject + "\n" + llGetRegionName() + "/" + (string)llRound(pos.x) + "/" + (string)llRound(pos.y) + "/" + (string)llRound(pos.z) + "/");
}
}
menu()
{
llDialog(llGetOwner(), "Please select an option", ["Check Now", "Web", "Help", "About",
"Notify", "Cancel"], 282);
}
string notify_level()
{
if (gNotify == 0) return "Quiet";
else if (gNotify == 1) return "Private";
else if (gNotify == 2) return "Public";
return "** something illegal **";
}
help()
{
if (EMAIL == "" || PASS == "") {
llOwnerSay(
"BEWARE! You have not configured an email and password! " + "Open the object, open the TwitterBox script, and fill in " + "the variables at the top. Make sure string EMAIL = \"your.email@somewhere.com\" and string PASS = \"yourTwitterPassword\".");
}
llOwnerSay(
"To send a tweet, say '/282
llOwnerSay(”Type the word SLURL (all caps) within the text to insert a TinyURL to the SLurl for your location into your tweet.”);
}
about()
{
llOwnerSay(”A simple SL client for Twitter - http://twitter.com/ ” + “- by Ordinal Malaprop”);
llOwnerSay(
“TwitterBox will automatically check for new tweets from your ” +
“friends every minute, or when you tell it to manually from ” +
“the menu, obtainable by touching the HUD.”);
llOwnerSay(
“To use, you need to have registered with Twitter, and edited ” + “the script to include your email address and password.”);
llOwnerSay(
“For more information or the latest version, visit ” +
“http://ordinalmalaprop.com/twitter/”);
}
twitterball()
{
llStartAnimation(”Twitter”);
llSleep(1.0);
llRezObject(”Twitterball”, llGetPos() + <0.0, 0.0, 1.5>, ZERO_VECTOR, ZERO_ROTATION, 1);
}
//——————————————————————
default
{
state_entry()
{
llOwnerSay(”Initialising…”);
// At the start, get the user’s screen name and ID number
twitter_send(”get id”, “”);
// reset the clock to now
gTime = llGetUnixTime();
// and set up a regular check
llSetTimerEvent(10.0);
// and also start listening for commands
llListen(282, “”, llGetOwner(), “”);
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
llOwnerSay(”Done.”);
help();
}
changed(integer change)
{
if (change & CHANGED_OWNER) {
llResetScript();
}
}
attach(key id)
{
// Don’t do anything if taking it off!
if (id == NULL_KEY) return;
// Get screen name again whenever it is attached,
// as this may change
twitter_send(”get id”, “”);
// Also display the help message
help();
llRequestPermissions(llGetOwner(), PERMISSION_TRIGGER_ANIMATION);
}
timer()
{
twitter_send(”check”, “”);
}
touch_start(integer n)
{
// On owner touch, launch a control menu
if (llDetectedKey(0) != llGetOwner()) return;
menu();
}
listen(integer c, string name, key id, string msg)
{
if (msg == “Check Now”) {
llOwnerSay(”Checking latest entries…”);
gManual = TRUE;
twitter_send(”check”, “”);
llSetTimerEvent(60.0);
}
else if (msg == “TestTwit”) {
llSleep(1.0);
twitterball();
}
else if (msg == “Web”) {
llLoadURL(id, “Visit your own Twitter page”, “http://twitter.com/” + gScreenName);
}
else if (msg == “Help”) {
help();
}
else if (msg == “About”) {
about();
}
else if (msg == “Notify”) {
llDialog(llGetOwner(), “Please select an option for notifications - currently ” + notify_level(), [”Quiet”, “Private”, “Public”, “Cancel”], 282);
}
else if (msg == “Quiet”) {
gNotify = 0;
llOwnerSay(”No sound or animation notifications”);
}
else if (msg == “Private”) {
gNotify = 1;
llOwnerSay(”Private sound only for notifications”);
}
else if (msg == “Public”) {
gNotify = 2;
llOwnerSay(”Animations and public sound when twittering, private sound for new tweets”);
}
else if (msg != “Cancel”) {
llOwnerSay(”Twittering…”);
twitter_send(”update”, msg);
}
}
http_response(key id, integer status, list metadata, string body)
{
if (llGetSubString(body, 0, 1) == “OK”) {
// A success
list lines = llParseString2List(body, [”\n”], []);
string firstLine = llList2String(lines, 0);
if (llGetListLength(lines) == 1) {
// A successful update, or an ID check
list bits = llParseString2List(firstLine, [”,”], []);
gCode = llList2Integer(bits, 1);
gScreenName = llList2String(bits, 2);
if (llList2String(bits, 3) == “posted”) {
llOwnerSay(”Successfully Twittered!”);
if (gNotify == 1) {
llPlaySound(”c923f3d9-83a6-99dc-9b7d-bbcdb3c30789″, 1.0);
} else if (gNotify == 2) {
twitterball();
}
}
}
else {
integer f = 1;
integer maxTime = gTime;
do {
string user = llList2String(lines, f);
integer time = llList2Integer(lines, f + 2);
if (user != gScreenName && time > gTime) {
if (maxTime == gTime) {
// First new tweet, play sound
if (gNotify != 0) {
llPlaySound(”c923f3d9-83a6-99dc-9b7d-bbcdb3c30789″, 1.0);
}
}
llOwnerSay(llList2String(lines, f) + “: ” + llList2String(lines, f + 1));
maxTime = time;
}
f += 3;
} while (f < llGetListLength(lines));
if (maxTime == gTime) {
if (gManual) {
llOwnerSay("No new entries");
gManual = FALSE;
}
} else {
gTime = maxTime;
}
}
} else {
if (body == "") {
// SL sends back a blank entry if it can't get in touch
body = "Could not contact intermediary server " + TWITTERPING;
}
else llOwnerSay("Error " + (string)status + " - " + body);
}
}
}
Comments (1)
Category: Chris Hambly
- Add this post to Del.icio.us - Digg





















