コード例 #1
0
ファイル: SteamPortal.cs プロジェクト: finalcd/KryBot
        private void AddGiveaways(HtmlNodeCollection nodes)
        {
            if (nodes != null)
            {
                foreach (var node in nodes)
                {
                    var name    = node.SelectSingleNode(".//div[@class='giveaway_name']");
                    var storeId = node.SelectSingleNode(".//a[@class='steam-icon']");
                    if (name != null && storeId != null)
                    {
                        var spGiveaway = new SteamPortalGiveaway
                        {
                            Name    = name.InnerText,
                            StoreId = storeId.Attributes["href"].Value.Split('/')[4]
                        };

                        var price = node.SelectSingleNode(".//span[@class='coin-white-icon']");
                        var code  = node.SelectSingleNode(".//div[@class='ga_join_btn ga_coin_join']");
                        if (price != null && code != null)
                        {
                            spGiveaway.Price = int.Parse(price.InnerText);
                            spGiveaway.Code  = code.Attributes["onclick"].Value.Split('\'')[5].Replace("ga:", "");

                            var iconsBlock = node.SelectSingleNode(".//div[@class='giveaway_iconbar']");
                            var icons      = iconsBlock?.SelectNodes(".//span");
                            if (icons != null)
                            {
                                foreach (var icon in icons)
                                {
                                    if (icon.Attributes["class"].Value.Contains("region"))
                                    {
                                        spGiveaway.Region = icon.Attributes["class"].Value.Split('-')[1];
                                    }
                                }
                            }

                            if (spGiveaway.Price <= Points &&
                                spGiveaway.Price <= MaxJoinValue)
                            {
                                Giveaways?.Add(spGiveaway);
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: SteamPortal.cs プロジェクト: finalcd/KryBot
        private async Task <Log> JoinGiveaway(SteamPortalGiveaway giveaway)
        {
            var task = new TaskCompletionSource <Log>();
            await Task.Run(() =>
            {
                Thread.Sleep(400);
                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.SteamPortalJoin,
                                            GenerateJoinData(giveaway.Code), list,
                                            Cookies.Generate());
                    var jresponse =
                        JsonConvert.DeserializeObject <JsonJoin>(response.RestResponse.Content.Replace(".", ""));
                    if (jresponse.Error == 0)
                    {
                        Points = jresponse.TargetH.MyCoins;
                        task.SetResult(Messages.GiveawayJoined("SteamPortal", giveaway.Name, giveaway.Price,
                                                               jresponse.TargetH.MyCoins));
                    }
                    else
                    {
                        task.SetResult(Messages.GiveawayNotJoined("SteamPortal", giveaway.Name, "Error"));
                    }
                }
                else
                {
                    task.SetResult(null);
                }
            });

            return(task.Task.Result);
        }