Exemple #1
0
        /// <summary>
        /// Gets the role of a certain user in the group. If the user isn't in the group or the rank the user has doesn't exist within the group object, it returns null.
        /// </summary>
        /// <param name="user">The user to get the role from.</param>
        /// <returns>The role of the user.</returns>
        public async Task <GroupRole> GetRoleOfUser(User user)
        {
            string stringifiedJSON = await HttpHelper.GetStringFromURL(string.Format("https://groups.roblox.com/v1/users/{0}/groups/roles", user.ID));

            JObject obj = JObject.Parse(stringifiedJSON);
            JToken  dataToken;

            if (obj.TryGetValue("data", out dataToken))
            {
                JArray arr = (JArray)dataToken;
                foreach (JObject groupMembershipObject in arr)
                {
                    JToken groupObject;
                    if (groupMembershipObject.TryGetValue("group", out groupObject))
                    {
                        JToken idToken;
                        if (((JObject)groupObject).TryGetValue("id", out idToken))
                        {
                            if (idToken.Value <int>() == ID)
                            {
                                JToken roleToken;
                                if (groupMembershipObject.TryGetValue("role", out roleToken))
                                {
                                    JObject roleObj = (JObject)roleToken;

                                    int    roleId   = 0;
                                    string roleName = "";
                                    int    roleRank = 0;

                                    JToken tok;
                                    if (roleObj.TryGetValue("id", out tok))
                                    {
                                        roleId = tok.Value <int>();
                                    }
                                    else
                                    {
                                        throw new Exception("Token \"id\" could not be found in roleObj.");
                                    }

                                    if (roleObj.TryGetValue("rank", out tok))
                                    {
                                        roleRank = tok.Value <int>();
                                    }
                                    else
                                    {
                                        throw new Exception("Token \"rank\" could not be found in roleObj.");
                                    }

                                    if (roleObj.TryGetValue("name", out tok))
                                    {
                                        roleName = tok.Value <string>();
                                    }
                                    else
                                    {
                                        throw new Exception("Token \"name\" could not be found in roleObj.");
                                    }

                                    return(new GroupRole(roleName, roleRank, roleId));
                                }
                                else
                                {
                                    throw new Exception("Token \"role\" could not be found in groupMembershipObject.");
                                }
                            }
                        }
                        else
                        {
                            throw new Exception("Token \"group.id\" could not be found in groupMembershipObject.");
                        }
                    }
                    else
                    {
                        throw new Exception("Token \"group\" could not be found in groupMembershipObject.");
                    }
                }
                return(null);
            }
            else
            {
                throw new Exception("Could not find \"data\" in json response. Did the response model change?");
            }
        }
Exemple #2
0
        private async Task <GroupResult_t> GetEnemyPage(int page)
        {
            string data = await HttpHelper.GetStringFromURL(string.Format("https://api.roblox.com/groups/{0}/enemies?page={1}", ID, page));

            return(JsonConvert.DeserializeObject <GroupResult_t>(data));
        }
Exemple #3
0
 /// <summary>
 /// Does the user id provided have the asset?
 /// </summary>
 /// <param name="userId">The user to check.</param>
 /// <returns>Does the user id provided have the asset?</returns>
 public async Task <bool> DoesUserHave(int userId)
 {
     return(await HttpHelper.GetStringFromURL(string.Format("http://api.roblox.com/Ownership/HasAsset?userId={0}&assetId={1}", userId, ID)) == "true");
 }
Exemple #4
0
        /// <summary>
        /// Gets an <see cref="Asset"/> with information filled in.
        /// </summary>
        /// <param name="assetId">The asset id to pull from</param>
        /// <returns>Asset filled with information</returns>
        public static async Task <Asset> FromID(int assetId)
        {
            try
            {
                string data = await HttpHelper.GetStringFromURL(string.Format("https://api.roblox.com/marketplace/productinfo?assetId={0}", assetId));

                JObject obj = JObject.Parse(data);

                Asset asset = new Asset();
                asset.ID        = (int)obj["AssetId"];
                asset.ProductId = (int?)obj["ProductId"] ?? -1;

                asset.Name        = (string)obj["Name"];
                asset.Description = (string)obj["Description"];

                asset.AssetType = (EAssetType)(int)obj["AssetTypeId"]; // eww.

                string creatorType = (string)obj["Creator"]["CreatorType"];

                if (creatorType == "Group")
                {
                    Group group = await Group.FromID((int)obj["Creator"]["CreatorTargetId"]);

                    asset.CreatorType = ECreatorType.Group;
                }
                else
                {
                    User user = new User();
                    user.ID           = (int)obj["Creator"]["CreatorTargetId"];
                    user.Username     = (string)obj["Creator"]["Name"];
                    asset.CreatorType = ECreatorType.User;
                }

                asset.IconImageAssetId = (int?)obj["IconImageAssetId"] ?? 0;

                asset.Created = DateTime.Parse((string)obj["Created"]);
                asset.Updated = DateTime.Parse((string)obj["Updated"]);

                asset.PriceInRobux = (int?)obj["PriceInRobux"] ?? 0; // We don't use PriceInTickets since Tickets are gone from roblox.
                asset.Sales        = (int?)obj["Sales"] ?? 0;

                asset.IsNew           = (bool?)obj["IsNew"] ?? false;
                asset.IsForSale       = (bool?)obj["IsForSale"] ?? false;
                asset.IsPublicDomain  = (bool?)obj["IsPublicDomain"] ?? false;
                asset.IsLimited       = (bool?)obj["IsLimited"] ?? false;
                asset.IsLimitedUnique = (bool?)obj["IsLimitedUnique"] ?? false;
                if (obj.Value <int?>("Remaining") != null)
                {
                    asset.Remaining = (int)obj["Remaining"];
                }
                else
                {
                    asset.Remaining = -1; // Infinite amount of this item.
                }
                asset.MinimumMembershipLevel = (EMembershipLevel)(int)obj["MinimumMembershipLevel"];
                asset.Is13OrOver             = ((int?)obj["ContentRatingTypeId"] == 1);

                return(asset);
            }
            catch (WebException)
            {
                return(null);
            }
        }
Exemple #5
0
 /// <summary>
 /// Gets the asset data from https://assetgame.roblox.com/Asset/?id=
 /// </summary>
 /// <returns>The asset downloaded as a string</returns>
 public async Task <string> DownloadAsString()
 {
     return(await HttpHelper.GetStringFromURL("https://assetgame.roblox.com/Asset/?id=" + ID));
 }