Example #1
0
        private async Task <Log> JoinGiveaway(GameAwaysGiveaway giveaway)
        {
            var task = new TaskCompletionSource <Log>();
            await Task.Run(() =>
            {
                Thread.Sleep(400);

                var response = Web.Post($"{Links.GameAwaysJoin}{giveaway.Id}",
                                        GenerateJoinParams(), Cookies.Generate());

                if (!string.IsNullOrEmpty(response.RestResponse.Content))
                {
                    var jsonresponse = JsonConvert.DeserializeObject <JsonJoinResponse>(response.RestResponse.Content);
                    if (jsonresponse != null)
                    {
                        Points = jsonresponse.Balance;
                        task.SetResult(Messages.GiveawayJoined("GameAways", giveaway.Name, giveaway.Price,
                                                               jsonresponse.Balance));
                    }
                    else
                    {
                        task.SetResult(Messages.GiveawayNotJoined("GameAways", giveaway.Name, "Oooops, some wrong..."));
                    }
                }
            });

            return(task.Task.Result);
        }
Example #2
0
        private void AddGiveaways(HtmlNodeCollection nodes)
        {
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var name    = node.SelectSingleNode(".//a[@class='game-title']");
                    var storeId = node.SelectSingleNode(".//div[@class='ga-tag-container']/a[1]");
                    var price   = node.SelectSingleNode(".//a[@class='entry-fee']");
                    var group   =
                        node.SelectSingleNode(
                            ".//span[contains(@class, 'ga-list-menu-icon') and contains(@class, 'ga-list-group')]");
                    if (name != null && storeId != null && price != null && group == null)
                    {
                        var gaGiveaway = new GameAwaysGiveaway
                        {
                            Name    = name.InnerText,
                            Id      = node.Attributes["id"].Value,
                            StoreId = storeId.Attributes["href"].Value.Split('/')[4],
                            Price   = int.Parse(price.InnerText.Replace(" GP", ""))
                        };

                        if (gaGiveaway.Price <= Points && gaGiveaway.Price <= JoinPointsLimit)
                        {
                            Giveaways?.Add(gaGiveaway);
                        }
                    }
                }
            }
        }