private void AddGiveaways(HtmlNodeCollection nodes, string nodeClass) { foreach (var node in nodes) { var entered = node.SelectSingleNode( ".//i[contains(@class, 'fa') and contains(@class, 'fa-check')]"); if (entered == null) { var id = node.SelectSingleNode($".//div[@class='{nodeClass}']/a"); if (id != null) { var name = id.SelectSingleNode(".//span"); var price = id.SelectSingleNode(".//span[2]"); if (name != null && price != null) { var giveaway = new InventoryGiftsGiveaway { Name = name.InnerText.Trim(), Id = id.Attributes["href"].Value.Split('/')[3].Split('/')[0] }; if (price.InnerText.Contains("(CD-Key)")) { giveaway.Price = int.Parse(price.InnerText.Split('(')[2].Split('p')[0].Trim()); } else { giveaway.Price = int.Parse(price.InnerText.Split('(')[1].Split('p')[0].Trim()); } if (giveaway.Price <= Points && giveaway.Price <= JoinPointsLimit) { Giveaways?.Add(giveaway); } } } } } }
private async Task <Log> JoinGiveaway(InventoryGiftsGiveaway giveaway) { var task = new TaskCompletionSource <Log>(); await Task.Run(() => { Thread.Sleep(400); var response = Web.Post($"{Links.InventoryGiftsJoin}?id={giveaway.Id}", GenerateJoinData(giveaway.Id), Cookies.Generate()); if (response.RestResponse.Content.Contains("Remove Entry")) { Points = Points - giveaway.Price; task.SetResult(Messages.GiveawayJoined("InventoryGifts", giveaway.Name, giveaway.Price, Points)); } else { task.SetResult(Messages.GiveawayNotJoined("InventoryGifts", giveaway.Name, response.RestResponse.Content)); } }); return(task.Task.Result); }