// Global variables key gUser; key gChannel; integer gListen; integer qCount = 0; integer tCount = 1; integer isReady = 0; string gZip; string gWxBugKey; string gDay; string weatherMail = "identity@domain.com"; // To read notecard data string noteName = "wxbug"; integer noteLine = 0; key noteQuery; // Stole this from the Wiki, it dumps error info DEBUG(list out) { llSay(0, llList2CSV(out)); } ///// // This is the default state default { state_entry() { if (gWxBugKey == "") { noteQuery = llGetNotecardLine(noteName, noteLine); } llSetColor(<0, 255, 0>, ALL_SIDES); if (isReady == 0) { llSay(0, "WeatherPrim ready."); isReady = 1; } } dataserver(key query_id, string data) { if (query_id == noteQuery) { if (data != EOF) { gWxBugKey = data; } } } touch(integer total_number) { llSetColor(<255, 0, 0>, ALL_SIDES); gUser = llDetectedKey(0); state cmdline; } } ///// // This is the state that handles user interfacing state cmdline { state_entry() { llSay(0, "In which U.S. zip code do you want to know about the weather?"); llSay(0, "Please just give say the first five digits."); gListen = llListen(0, "", gUser, ""); } listen(integer channel, string name, key id, string message) { if (qCount == 1) { message = llToLower(message); if (message == "monday" || message == "tuesday" || message == "wednesday" || message == "thursday" || message == "friday" || message == "saturday" || message == "sunday") { gDay = message; llSay(0, "Okay, let me look that up."); llOpenRemoteDataChannel(); } else if (message == "today") { gDay = message; llSay(0, "Today's weather? Why not just look out a window?"); llSleep(2); llSay(0, "Just kidding."); llOpenRemoteDataChannel(); } else { llSay(0, "Could you repeat that, I misunderstood you."); } } else if (qCount == 0) { if (llStringLength(message) == 5) { qCount++; gZip = message; llSay(0, "And what day do you want to know about?"); llSay(0, "Please just tell me either the weekday, or say today."); } else { llSay(0, "Sorry, what was that zip code?"); } } } remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) { if (type == REMOTE_DATA_CHANNEL) { gChannel = channel; state xmlrpc; } else { DEBUG(["Unexpected event type", type, channel, message_id, sender, ival, sval]); } } state_exit() { llSay(0, "This could take a minute, please be patient."); } } ///// // This is the state that accepts data from the net state xmlrpc { state_entry() { llSetTimerEvent(1.0); string weathermsg = (string)gChannel + "," + gWxBugKey + "," + gZip + "," + gDay; llEmail(weatherMail, "weather request", weathermsg); } remote_data(integer type, key channel, key message_id, string sender, integer ival, string sval) { if (type == REMOTE_DATA_REQUEST) { if (ival == 100) { llRemoteDataReply(channel, message_id, "Recieved", 101); list dayList = llParseString2List(sval, ["|"], []); integer dlcnt = 0; while (llList2String(dayList, dlcnt) != "") { list dayInfo = llParseString2List(llList2String(dayList, dlcnt), [","], []); string day = llList2String(dayInfo, 0); string cnd = llList2String(dayInfo, 1); llSay(0, cnd + " on " + day + "."); dlcnt++; } state default; } else if (ival == 400) { llRemoteDataReply(channel, message_id, "Recieved", 401); llSay(0, "Looks like there was a problem. Pleast try again later."); state default; } else { llSay(0, sval); llRemoteDataReply(channel, message_id, "Sorry, I have no response for that code.", 0); } } else { DEBUG(["Unexpected event type:", type, channel, message_id, sender, ival, sval]); } } timer() { if (tCount < 120) { tCount++; } else { llSay(0, "I do apologize. There seems to be an error. Please try again later."); llSetTimerEvent(0.0); state default; } } state_exit() { llCloseRemoteDataChannel(gChannel); llListenRemove(gListen); gZip = ""; gDay = ""; tCount = 0; qCount = 0; llSleep(2); } }