User:Cow Taurog/Email-chat

From Second Life Wiki
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Drop both of these scripts into the same prim. Change the settings in the first script to match your taste. The prim will listen for chat on a given channel, and send any chat to the specified email address. It will also check for emails from the same address, and play them over public chat. <lsl> string gsOwnerName="John Doe"; // REPLACE THIS WITH YOUR NAME string gsOwner="nobody@example.com"; // REPLACE THIS WITH YOUR EMAIL ADDRESS integer giPubChan=8; // Will send chat heard on this channel over email (not zero, not negative) float gfFreq=15; // How often in seconds to check for new email integer giTruncate=0; // Chops off the signature of a received email, 0 to keep it or if you don't have one integer giEmailComm=1102; // Linkmessage channel to use for the email wrapper, doesn't need to be changed integer giHovertext=TRUE; // Show instructional hovertext (instructions on replying are also given over chat) vector gvTextColor=<1,0.5,0>; // Hovertext color integer DEBUG=0; // 0 - No debug, 1 - Minimal debug, 2 - Verbose debug // Declarations integer listen0; integer giOutChan; integer giLength; string gsSay; integer i; integer giShout; string gsOriginalName; string gsHelpMess="All commands are given in the subject line, (parameters) for commands are put in the body of the message. Only messages from the owner's email address are used, all others are ignored. \nInput (channel) - Sets the local chat channel used to send messages. \nSay - Incoming messages will be said over local chat. \nShout - Incoming messages will be shouted over local chat. \nOff - Disables the sending of messages using local chat. \nOn - Enables the sending of messages using local chat. \nReset - Resets the script.";

sendemail(string address,string subject,string message){ // same format as llEmail, uses a wrapper script to eliminate the delay

   llMessageLinked(LINK_SET,giEmailComm,address+"|"+subject,message);

}

default{

   state_entry(){
       string sMyEmail=(string)llGetKey()+"@lsl.secondlife.com";
       gsOriginalName=llGetObjectName();
       if(giPubChan==0){giPubChan=9;}giPubChan=llAbs(giPubChan); // if channel is negative or zero, correct it
       llSetText("",ZERO_VECTOR,1);
       llOwnerSay("Address: "+sMyEmail);
       llOwnerSay("Type on /"+(string)giPubChan+" to send an email, Replies will be played over local chat.");
       sendemail(gsOwner,llGetRegionName()+" email/chat relay online.","The "+llGetRegionName()+" email/chat relay is online. Send an email with 'Help' as the subject line for more info. \n\n"+sMyEmail);
       state running;
   }

}

state running{

   state_entry(){
       if(DEBUG>0){llOwnerSay("Running...");}
       llSetTimerEvent(gfFreq);
       listen0=llListen(giPubChan,"","","");
       if(giHovertext==TRUE){llSetText("Type on /"+(string)giPubChan+" to send an email, Replies will be played over local chat.",gvTextColor,1);}
   }
   timer(){llGetNextEmail("","");}
   listen(integer chan,string name,key id,string mess){if(chan==giPubChan){
        sendemail(gsOwner,llGetRegionName()+", "+name,mess);
        llGetNextEmail("","");
   }}
   email(string time,string addy,string subj,string mess,integer left){
       if(subj=="Off"){
           llListenRemove(listen0);
           if(DEBUG>0){llOwnerSay("Not listening...");}
           sendemail(gsOwner,llGetRegionName()+", ch. "+(string)giPubChan+" listen off.","The listen on ch. "+(string)giPubChan+" has been turned off.");
           llSetText("",gvTextColor,1);
           return;
       }
       if(subj=="On"){
           listen0=llListen(giPubChan,"","","");
           if(DEBUG>0){llOwnerSay("Listening...");}
           sendemail(gsOwner,llGetRegionName()+", ch. "+(string)giPubChan+" listen on.","The listen on ch.  "+(string)giPubChan+" has been turned on.");
           if(giHovertext==TRUE){llSetText("Type on /"+(string)giPubChan+" to send an email. Replies will be played over local chat.",gvTextColor,1);}
           return;
       }
       if(subj=="Input"){
           if(mess=="0"){mess="1";}
           llListenRemove(listen0);
           giPubChan=(integer)mess;
           listen0=llListen(giPubChan,"","","");
           if(DEBUG>0){llOwnerSay("Listen changed to ch. "+(string)giPubChan+"...");}
           sendemail(gsOwner,llGetRegionName()+", now listening on "+(string)giPubChan,"The listen is now on on ch.  "+(string)giPubChan);
           if(giHovertext==TRUE){llSetText("Type on /"+(string)giPubChan+" to send an email. Replies will be played over local chat.",gvTextColor,1);}
           return;
       }
       if(subj=="Reset"){
           if(DEBUG>0){llOwnerSay("Resetting...");}
           sendemail(gsOwner,llGetRegionName()+", resetting.","Resetting...");
           llResetScript();
       }
       if(subj=="Say"){
           if(DEBUG>0){llOwnerSay("Now using say instead of shout...");}
           sendemail(gsOwner,llGetRegionName()+", shout off.","Now using say instead of shout...");
           giShout=FALSE;
           return;
       }
       if(subj=="Shout"){
           if(DEBUG>0){llOwnerSay("Now using shout instead of say...");}
           sendemail(gsOwner,llGetRegionName()+", shout off.","Now using shout instead of say...");
           giShout=TRUE;
           return;
       }
       else if(subj=="Help"){sendemail(gsOwner,llGetRegionName()+" email/chat relay help list.",gsHelpMess);return;}
       else if(subj=="'Help'"){sendemail(gsOwner,llGetRegionName()+" email/chat relay help list.",gsHelpMess);return;} // if they ask for 'help', not help...
       else if(subj==""){
           giLength=llStringLength(mess);
           gsSay=llGetSubString(mess,0,(giLength-giTruncate));
           if(addy==gsOwner){llSetObjectName(gsOwnerName);}
           if(giShout==FALSE){llSay(0,gsSay+" (Reply on /"+(string)giPubChan+".)");}
           if(giShout==TRUE){llShout(0,gsSay+" (Reply on /"+(string)giPubChan+".)");}
           llSetObjectName(gsOriginalName);
           return;
       }
       else{sendemail(gsOwner,llGetRegionName()+", error.","Invalid command given. The subject line is used only for sending commands, not for sending chat. Leave the subject blank to send a message over chat, or send an email with 'Help' as the subject line.");}
       llGetNextEmail("","");
   }    

} </lsl>

Email wrapper

This script gets around that annoying 20 second delay by using a link message to send an email. The other script can carry on without waiting, but you can still only send an email every 20 seconds. <lsl> integer giEmailComm=1102; // must match the main script, no need to change this unless you changed the other one list glRaw; string gsAddress; string gsSubject; string gsMessage; //sendemail(string address,string subject,string message){llMessageLinked(LINK_SET,1102,address+"|"+subject,message);} // ^ the function to use the wrapper in another script, format matches llEmail. default{

   link_message(integer sender,integer num,string mess,key id){
       glRaw=llParseString2List(mess,["|"],[]);
       gsAddress=llList2String(glRaw,0);
       gsSubject=llList2String(glRaw,1);
       gsMessage=(string)id;
       llEmail(gsAddress,gsSubject,gsMessage);
   }

} </lsl>