Esempio n. 1
0
        private async Task <Log> GetJoinData(SteamCompanionGiveaway scGiveaway, Steam steam)
        {
            var response = Web.Get(scGiveaway.Link, Cookies.Generate());

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

                var storId = htmlDoc.DocumentNode.SelectSingleNode("//a[@class='banner large-5 columns']");
                var code   = htmlDoc.DocumentNode.SelectSingleNode($"//div[@data-points='{scGiveaway.Price}']");
                var giftId = htmlDoc.DocumentNode.SelectSingleNode("//input[@name='giftID']");
                if (storId != null && code != null && giftId != null)
                {
                    scGiveaway.StoreId = storId.Attributes["href"].Value.Split('/')[4];
                    scGiveaway.Code    = code.Attributes["data-hashid"].Value;
                    return(new Log("", Color.White, true));
                }

                var group =
                    htmlDoc.DocumentNode.SelectSingleNode("//a[@class='notification group-join regular-button qa']");
                if (group != null)
                {
                    if (AutoJoin)
                    {
                        var trueGroupUrl = Web.Get(group.Attributes["href"].Value, Cookies.Generate());

                        return(await steam.Join(trueGroupUrl.RestResponse.ResponseUri.AbsoluteUri));
                    }
                    var error =
                        htmlDoc.DocumentNode.SelectSingleNode("//a[@class='notification group-join regular-button qa']");
                    return
                        (new Log(
                             $"{Messages.GetDateTime()} {{SteamCompanion}} {strings.GiveawayJoined_Join} \"{scGiveaway.Name}\" {strings.GiveawayNotJoined_NotConfirmed} " +
                             $"{strings.GiveawayNotJoined_YouMustEnteredToGroup} {{{(error == null ? "Error" : error.Attributes["href"].Value)}}}",
                             Color.Yellow, false));
                }

                var exception =
                    htmlDoc.DocumentNode.SelectSingleNode("//a[@class='notification regular-button']").InnerText;

                if (exception != null)
                {
                    return(Messages.GiveawayNotJoined("SteamCompanion", scGiveaway.Name, exception));
                }
            }
            return(Messages.GiveawayNotJoined("SteamCompanion", scGiveaway.Name, "Content is empty"));
        }
Esempio n. 2
0
        private async Task <Log> JoinGiveaway(SteamCompanionGiveaway giveaway, Steam steam)
        {
            var task = new TaskCompletionSource <Log>();
            await Task.Run(async() =>
            {
                Thread.Sleep(400);
                var data = await GetJoinData(giveaway, steam);
                if (data != null && data.Success)
                {
                    if (giveaway.Code != null)
                    {
                        var list   = new List <HttpHeader>();
                        var header = new HttpHeader
                        {
                            Name  = "X-Requested-With",
                            Value = "XMLHttpRequest"
                        };
                        list.Add(header);

                        var response = Web.Post(Links.SteamCompanionJoin,
                                                GenerateJoinData(giveaway.Code), list,
                                                Cookies.Generate());

                        if (response.RestResponse.Content.Split('"')[3].Split('"')[0] == "Success")
                        {
                            Points = int.Parse(response.RestResponse.Content.Split(':')[2].Split(',')[0]);
                            task.SetResult(Messages.GiveawayJoined("SteamCompanion", giveaway.Name, giveaway.Price,
                                                                   int.Parse(response.RestResponse.Content.Split(':')[2].Split(',')[0])));
                        }
                        else
                        {
                            task.SetResult(Messages.GiveawayNotJoined("SteamCompanion", giveaway.Name,
                                                                      response.RestResponse.Content));
                        }
                    }
                }
                else
                {
                    task.SetResult(data);
                }
            });

            return(task.Task.Result);
        }
Esempio n. 3
0
        private void AddGiveaways(HtmlNodeCollection nodes, List <SteamCompanionGiveaway> giveaways)
        {
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var name = node.SelectNodes(".//p[@class='game-name']/a/span").Count > 1
                        ? node.SelectSingleNode(".//p[@class='game-name']/a/span[2]")
                        : node.SelectSingleNode(".//p[@class='game-name']/a/span[1]");
                    var price = node.SelectSingleNode(".//p[@class='game-name']/a");

                    if (price != null && name != null)
                    {
                        var scGiveaway = new SteamCompanionGiveaway
                        {
                            Name  = name.InnerText,
                            Price = int.Parse(price.InnerText.Replace("p)", "").Split('(')[
                                                  node.SelectSingleNode(".//p[@class='game-name']")
                                                  .InnerText.Replace("p)", "")
                                                  .Split('(')
                                                  .Length - 1]),
                            Link = node.SelectSingleNode(".//p[@class='game-name']/a").Attributes["href"].Value
                        };

                        var region = node.SelectSingleNode(".//span[@class='icon-region']");
                        if (region != null)
                        {
                            scGiveaway.Region = true;
                        }

                        if (scGiveaway.Price <= Points &&
                            scGiveaway.Price <= JoinPointLimit)
                        {
                            giveaways?.Add(scGiveaway);
                        }
                    }
                }
            }
        }