Difference between revisions of "User:DoteDote Edison"

From Second Life Wiki
Jump to navigation Jump to search
m
Line 6: Line 6:


====Email-to-IM Script for the Script Library====
====Email-to-IM Script for the Script Library====
<pre><lsl>
<pre>
// Email-to-IM
// Email-to-IM
// DoteDote Edison
// DoteDote Edison
Line 12: Line 12:
///////// constants /////////
///////// constants /////////
// how often to check for new email when owner is online (seconds)
// how often to check for new email when owner is online (seconds)
float fast = 60.0;
float FAST = 60.0;
// how often to check owner online status when owner is offline (seconds)
// how often to check owner online status when owner is offline (seconds)
float slow = 300.0;  
float SLOW = 300.0;
// timezone offset from UTC
integer offset = -4;


////////// globals //////////
////////// globals //////////
Line 20: Line 22:
key owner;
key owner;
integer owner_online;
integer owner_online;
string GetStamp(string time) {
    list weekdays = ["THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED"];
    integer a = (integer)time + (offset*3600);
    integer hours = a/3600;
    integer mins = a/60;
    string day  = llList2String(weekdays, (hours/24)%7);
    return (string)(hours%24) + ":" + (string)(mins%60) + " " + day;
}


default {
default {
state_entry() {
    state_entry() {
owner = llGetOwner();
        owner = llGetOwner();
string address = (string)owner + "@lsl.secondlife.com";
        string address = (string)llGetKey() + "@lsl.secondlife.com";
llSetText("Email Server\nOnline", <0.25, 1.0, 0.25>, 1.0);
        llSetText("Email Server\nOnline", <0.25, 1.0, 0.25>, 1.0);
llOwnerSay("Now online.  The Email-to-IM address for " + llKey2Name(owner) + " is:\n" + address);
        llOwnerSay("Now online.  The Email-to-IM address for " + llKey2Name(owner) + " is:\n" + address);
llSetTimerEvent(fast);
        llSetTimerEvent(FAST);
}
    }
on_rez(integer start_param) {
    on_rez(integer start_param) {
llResetScript();
        llResetScript();
}
    }
touch_start(integer num_detect) {
    touch_start(integer num_detect) {
if (llDetectedKey(0) == owner) state off;
        if (llDetectedKey(0) == owner) state off;
}
    }
email(string time, string sender, string subject, string body, integer num_remain) {
    email(string time, string sender, string subject, string body, integer num_remain) {
llInstantMessage(owner, "Email Received from: " + sender + " -- " + time);
        llInstantMessage(owner, "Email Received from: " + sender + " -- " + GetStamp(time));
llInstantMessage(owner, body);
        llInstantMessage(owner, body);
if (num_remain > 0) llGetNextEmail("", "");
        if (num_remain > 0) llGetNextEmail("", "");
}
    }
dataserver(key query, string data) {
    dataserver(key query, string data) {
if (query == request) {
        if (query == request) {
request = "";
            request = "";
if (data == "1") {
            if (data == "1") {
owner_online = TRUE;
                owner_online = TRUE;
llSetTimerEvent(fast);
                llSetTimerEvent(FAST);
}
            }
else {
            else {
owner_online = FALSE;
                owner_online = FALSE;
llSetTimerEvent(slow);
                llSetTimerEvent(SLOW);
}
            }
}
        }
}
    }
timer() {
    timer() {
request = llRequestAgentData(owner, DATA_ONLINE);
        request = llRequestAgentData(owner, DATA_ONLINE);
if (owner_online) llGetNextEmail("", "");
        if (owner_online) llGetNextEmail("", "");
}
    }
state_exit() {
    state_exit() {
llSetTimerEvent(0.0);
        llSetTimerEvent(0.0);
llSetText("Email Server\nOffline", <1.0, 0.25, 0.25>, 1.0);
        llSetText("Email Server\nOffline", <1.0, 0.25, 0.25>, 1.0);
}
    }
}
}


state off {
state off {
touch_start(integer num_detect) {
    touch_start(integer num_detect) {
if (llDetectedKey(0) == owner) state default;
        if (llDetectedKey(0) == owner) state default;
}
    }
on_rez(integer start_param) {
    on_rez(integer start_param) {
llResetScript();
        llResetScript();
}
    }
}
}
</lsl></pre>
</pre>

Revision as of 01:38, 29 March 2007


Not a Wiki pro, I'll try to not screw it up.

Email-to-IM Script for the Script Library

// Email-to-IM
// DoteDote Edison

///////// constants /////////
// how often to check for new email when owner is online (seconds)
float FAST = 60.0;
// how often to check owner online status when owner is offline (seconds)
float SLOW = 300.0; 
// timezone offset from UTC
integer offset = -4;

////////// globals //////////
key request;
key owner;
integer owner_online;

string GetStamp(string time) {
    list weekdays = ["THU", "FRI", "SAT", "SUN", "MON", "TUE", "WED"];
    integer a = (integer)time + (offset*3600);
    integer hours = a/3600;
    integer mins = a/60;
    string day  = llList2String(weekdays, (hours/24)%7);
    return (string)(hours%24) + ":" + (string)(mins%60) + " " + day;
}

default {
    state_entry() {
        owner = llGetOwner();
        string address = (string)llGetKey() + "@lsl.secondlife.com";
        llSetText("Email Server\nOnline", <0.25, 1.0, 0.25>, 1.0);
        llOwnerSay("Now online.  The Email-to-IM address for " + llKey2Name(owner) + " is:\n" + address);
        llSetTimerEvent(FAST);
    }
    on_rez(integer start_param) {
        llResetScript();
    }
    touch_start(integer num_detect) {
        if (llDetectedKey(0) == owner) state off;
    }
    email(string time, string sender, string subject, string body, integer num_remain) {
        llInstantMessage(owner, "Email Received from: " + sender + " -- " + GetStamp(time));
        llInstantMessage(owner, body);
        if (num_remain > 0) llGetNextEmail("", "");
    }
    dataserver(key query, string data) {
        if (query == request) {
            request = "";
            if (data == "1") {
                owner_online = TRUE;
                llSetTimerEvent(FAST);
            }
            else {
                owner_online = FALSE;
                llSetTimerEvent(SLOW);
            }
        }
    }
    timer() {
        request = llRequestAgentData(owner, DATA_ONLINE);
        if (owner_online) llGetNextEmail("", "");
    }
    state_exit() {
        llSetTimerEvent(0.0);
        llSetText("Email Server\nOffline", <1.0, 0.25, 0.25>, 1.0);
    }
}

state off {
    touch_start(integer num_detect) {
        if (llDetectedKey(0) == owner) state default;
    }
    on_rez(integer start_param) {
        llResetScript();
    }
}