Example #1
0
        // API content
        public async Task <ActionResult> ShrineOfSecrets()
        {
            JObject shrine = null;

            try
            {
                shrine = await _dbdService.GetShrine();
            }
            catch (Exception)
            {
                return(Content("Uh oh, we failed to retrieve the shrine from dbd servers :/"));
            }

            if (!string.IsNullOrEmpty(Request.Query["pretty"]))
            {
                if (shrine != null)
                {
                    try
                    {
                        var output = new StringBuilder();

                        var items = shrine["items"].ToArray();
                        var start = (DateTime)shrine["startDate"];
                        var end   = (DateTime)shrine["endDate"];

                        foreach (var item in items)
                        {
                            var name = CorrectPerkName((string)item["id"]);
                            var cost = item["cost"].ToArray();
                            if (!cost.Any())
                            {
                                continue;
                            }

                            var price = (int)cost[0]["price"];

                            output.Append($"{name} : {price}");

                            if (item != items.Last())
                            {
                                output.Append(", ");
                            }
                        }

                        output.Append(" | ");

                        var changesIn = end - DateTime.Now;
                        output.Append(
                            $"Shrine changes in {changesIn.Days} days, {changesIn.Hours} hours, and {changesIn.Minutes} mins");

                        return(Content(output.ToString()));
                    }
                    catch
                    {
                        return(Content("Uhhhh, we failed to parse the data retrieved, contact me to fix"));
                    }
                }
                else
                {
                    return(Content("Uh oh, we failed to retrieve the shrine from dbd servers :/"));
                }
            }
            else
            {
                return(Json(shrine, new JsonSerializerSettings()
                {
                    Formatting = Formatting.Indented
                }));
            }
        }
Example #2
0
        public async Task <ActionResult> ShrineOfSecrets(string branch = "live")
        {
            ShrineResponse shrine;

            try
            {
                shrine = await _dbdService.GetShrine(branch);

                if (shrine == null)
                {
                    throw new InvalidOperationException();
                }
            }
            catch (Exception)
            {
                return(Content("Uh oh, we failed to retrieve the shrine from dbd servers :/"));
            }

            var useRealFix = _dbdService.PerkInfos.TryGetValue(BranchToDepotBranch(branch),
                                                               out var perkInfos);

            foreach (var item in shrine.Items)
            {
                if (useRealFix && perkInfos.TryGetValue(item.Id, out var perk))
                {
                    item.Name = perk.DisplayName;
                }
                else
                {
                    item.Name = CorrectPerkName(item.Id);
                }
            }

            var format = (string)Request.Query["format"];

            if (!string.IsNullOrEmpty(Request.Query["pretty"]))
            {
                if (!string.IsNullOrEmpty(format))
                {
                    try
                    {
                        return(Content(Smart.Format(format, shrine)));
                    }
                    catch (Exception e)
                    {
                        return(Json(new
                        {
                            success = false,
                            type = "Format Exception",
                            reason = e.Message
                        }));
                    }
                }
                else
                {
                    try
                    {
                        var output = new StringBuilder();

                        foreach (var item in shrine.Items)
                        {
                            if (!item.Cost.Any())
                            {
                                continue;
                            }

                            output.Append($"{item.Name} : {item.Cost[0].Price}");

                            if (item != shrine.Items.Last())
                            {
                                output.Append(", ");
                            }
                        }

                        output.Append(" | ");

                        var changesIn = shrine.EndDate - DateTime.Now;
                        output.Append(
                            $"Shrine changes in {changesIn.Days} days, {changesIn.Hours} hours, and {changesIn.Minutes} mins");

                        return(Content(output.ToString()));
                    }
                    catch
                    {
                        return(Content("Uhhhh, we failed to parse the data retrieved, contact me to fix"));
                    }
                }
            }
            else
            {
                return(Json(shrine, ShrineConverter.Settings));
            }
        }