Ejemplo n.º 1
0
        private int AddGiveaways(HtmlNodeCollection nodes, List <SteamGiftsGiveaway> giveawaysList)
        {
            var count = 0;

            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var name    = node.SelectSingleNode(".//a[@class='giveaway__heading__name']");
                    var link    = node.SelectSingleNode(".//a[@class='giveaway__heading__name']");
                    var storeId = node.SelectSingleNode(".//a[@class='giveaway__icon']");
                    if (name != null && link != null && storeId != null)
                    {
                        var sgGiveaway = new SteamGiftsGiveaway
                        {
                            Name    = name.InnerText,
                            Link    = link.Attributes["href"].Value,
                            StoreId = storeId.Attributes["href"].Value.Split('/')[4]
                        };
                        sgGiveaway.Code = sgGiveaway.Link.Split('/')[2];

                        foreach (var price in node.SelectNodes(".//span[@class='giveaway__heading__thin']"))
                        {
                            if (price.InnerText.Contains("Copies"))
                            {
                                sgGiveaway.Copies = int.Parse(price.InnerText
                                                              .Replace(",", "")
                                                              .Replace(" Copies)", "")
                                                              .Split('(')[1]);
                            }
                            else
                            {
                                sgGiveaway.Price = int.Parse(price.InnerText.Split('(')[1].Split('P')[0]);
                            }
                        }

                        var level = node.SelectSingleNode(".//div[@title='Contributor Level']");
                        sgGiveaway.Level = level == null ? 0 : int.Parse(level.InnerText.Split(' ')[1].Trim('+'));

                        var region = node.SelectSingleNode(".//a[@title='Region Restricted']");
                        if (region != null)
                        {
                            sgGiveaway.Region = region.Attributes["href"].Value.Split('/')[2];
                        }

                        if (sgGiveaway.Price <= Points &&
                            sgGiveaway.Price <= JoinPointLimit &&
                            sgGiveaway.Level >= MinLevel)
                        {
                            giveawaysList?.Add(sgGiveaway);
                            count++;
                        }
                    }
                }
            }

            return(count);
        }
Ejemplo n.º 2
0
        private SteamGiftsGiveaway GetJoinData(SteamGiftsGiveaway sgGiveaway)
        {
            var response = Web.Get($"{Links.SteamGifts}{sgGiveaway.Link}", Cookies.Generate(), UserAgent);

            if (response.RestResponse.Content != string.Empty)
            {
                var htmlDoc = new HtmlDocument();
                htmlDoc.LoadHtml(response.RestResponse.Content);

                var code  = htmlDoc.DocumentNode.SelectSingleNode("//input[@name='code']");
                var token = htmlDoc.DocumentNode.SelectSingleNode("//input[@name='xsrf_token']");
                if (code != null && token != null)
                {
                    sgGiveaway.Code  = code.Attributes["value"].Value;
                    sgGiveaway.Token = token.Attributes["value"].Value;
                }
            }
            return(sgGiveaway);
        }
Ejemplo n.º 3
0
        private async Task <Log> JoinGiveaway(SteamGiftsGiveaway giveaway)
        {
            var task = new TaskCompletionSource <Log>();
            await Task.Run(async() =>
            {
                Thread.Sleep(400);
                giveaway = GetJoinData(giveaway);

                if (giveaway.Token != null)
                {
                    var response = Web.Post(Links.SteamGiftsAjax,
                                            GenerateJoinParams(giveaway.Token, giveaway.Code, "entry_insert"),
                                            Cookies.Generate(), UserAgent);

                    if (response.RestResponse.Content != null)
                    {
                        var jsonresponse =
                            JsonConvert.DeserializeObject <JsonResponseJoin>(response.RestResponse.Content);
                        if (jsonresponse.Type == "success")
                        {
                            Points = jsonresponse.Points;
                            task.SetResult(Messages.GiveawayJoined("SteamGifts", giveaway.Name, giveaway.Price,
                                                                   jsonresponse.Points,
                                                                   giveaway.Level));
                        }
                        else
                        {
                            var jresponse =
                                JsonConvert.DeserializeObject <JsonResponseError>(response.RestResponse.Content);
                            task.SetResult(Messages.GiveawayNotJoined("SteamGifts", giveaway.Name,
                                                                      jresponse.Error?.Message));
                        }
                    }
                }
                else
                {
                    task.SetResult(Messages.GiveawayNotJoined("SteamGifts", giveaway.Name,
                                                              await GetFailedDetail(giveaway.Link)));
                }
            });

            return(task.Task.Result);
        }