Difference between revisions of "GetGroupInfo"

From Second Life Wiki
Jump to navigation Jump to search
(Created initial version. Group info retrieved from website includes name, description, number of members, open enrollment (Y/N), membership fee, founder ID, founder name, group image, and group maturity rating, all from group id.)
 
 
Line 1: Line 1:
 
= Usage and Description =
== Get Group Info ==
by --[[User:Pazako Karu|Pazako Karu]] ([[User talk:Pazako Karu|talk]]) 18:15, 31 March 2019 (PDT)
== Usage and Description ==
call getGroupInfo and check that groupRequest == "1" to verify return success.
call getGroupInfo and check that groupRequest == "1" to verify return success.
Group data acquired from LL group pages and includes:
Group data acquired from LL group pages and includes:
Line 15: Line 12:
  * groupMaturityRating
  * groupMaturityRating
which are put in that order into a list GROUP_INFO.
which are put in that order into a list GROUP_INFO.
== LSL Code ==
= LSL Code =


<source lang="lsl2">
<source lang="lsl2">
Line 71: Line 68:
}
}
</source>
</source>
--[[User:Pazako Karu|Pazako Karu]] ([[User talk:Pazako Karu|talk]]) 18:15, 31 March 2019 (PDT)

Latest revision as of 18:20, 31 March 2019

Usage and Description

call getGroupInfo and check that groupRequest == "1" to verify return success. Group data acquired from LL group pages and includes:

* groupTitle
* groupDescription
* groupMemberCount
* groupOpenEnroll
* groupMembershipFee
* groupFounderID
* groupFounderName
* groupImageID
* groupMaturityRating

which are put in that order into a list GROUP_INFO.

LSL Code

key getGroupInfo(key group_id)
{
    return llHTTPRequest("http://world.secondlife.com/group/" + (string)group_id,[HTTP_METHOD,"GET"],"");
}
key groupRequest;
list GROUP_INFO;
default
{
    state_entry()
    {
        groupRequest = getGroupInfo("a053573f-e2b3-ccb0-954a-177ad62e4d37");
    }
    http_response(key req, integer status, list meta, string body)
    {
        if (req == groupRequest)
        {
            if (status == 200)
            {
                integer posS = llSubStringIndex(body, "<title>")+7; // Find web title, which is group name
                integer posF = llSubStringIndex(body, "</title>")-1; // Find the end of the title
                string groupTitle = llGetSubString(body, posS, posF); // Set groupTitle to found title
                posS = llSubStringIndex(body, "<meta name=\"description\" content=\"")+34; // Find the start of the description
                body = llGetSubString(body, posS, -1); // Trim the beginning of the body off
                posF = llSubStringIndex(body, "\" />"); // Find first instance of />, which ends the description tag
                string groupDescription = llGetSubString(body, 0, posF); // Set groupDescription to found description
                body = llGetSubString(body, posF, -1); // Trim the title/description of the body off
                list GROUP_DATA = llParseString2List(body, ["<meta name=","content=", "/>", "\"", " ", "\n"],[]); // Break the body into a list
                // The following looks for name-value pairs in the html for each group
                // If you do not need some of the following, comment them out to avoid unnecessary processing lag.
                integer groupMemberCount =      (integer)llList2String(GROUP_DATA, llListFindList(GROUP_DATA, ["member_count"])+1);
                // This returns a binary result for comparison, Y=1 and anything else is 0.   
                integer groupOpenEnroll =       (llList2String(GROUP_DATA, llListFindList(GROUP_DATA, ["open_enrollment"])+1) == "Y");
                integer groupMembershipFee =    (integer)llList2String(GROUP_DATA, llListFindList(GROUP_DATA, ["membership_fee"])+1);
                key     groupFounderID =        (key)llList2String(GROUP_DATA, llListFindList(GROUP_DATA, ["founderid"])+1);
                // Because GROUP_DATA removed spaces, Founder Name needs special treatment. If the order of tags changes in the future,
                // groupid should be changed to whatever tag follows founder.
                string  groupFounderName =      llDumpList2String(llList2List(GROUP_DATA, llListFindList(GROUP_DATA, ["founder"])+1,
                                                                                llListFindList(GROUP_DATA, ["groupid"])-1), " ");;
                key     groupImageID =          (key)llList2String(GROUP_DATA, llListFindList(GROUP_DATA, ["imageid"])+1);
                string  groupMaturityRating =   llList2String(GROUP_DATA, llListFindList(GROUP_DATA, ["mat"])+1);
                
                GROUP_INFO = [groupTitle, groupDescription, groupMemberCount, groupOpenEnroll, groupMembershipFee, groupFounderID,
                                groupFounderName, groupImageID, groupMaturityRating];
                                
                groupRequest = "1"; // Check if groupRequest is now "1" to verify you have valid GROUP_INFO after a request.

                llOwnerSay(llDumpList2String(GROUP_INFO, "\n")); // Simple use case for info
            }
            else llOwnerSay(0, "HTTP error in group reqeust: " + body);
        }
    }
}

--Pazako Karu (talk) 18:15, 31 March 2019 (PDT)