private async Task VoteForSteamAwards()
        {
            HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetSteamAwardsPage().ConfigureAwait(false);

            HtmlNodeCollection nominationNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='vote_nominations store_horizontal_autoslider']");

            if (nominationNodes == null)
            {
                // Event ended, error or likewise
                return;
            }

            foreach (HtmlNode nominationNode in nominationNodes)
            {
                HtmlNode myVoteNode = nominationNode.SelectSingleNode("./div[@class='vote_nomination your_vote']");
                if (myVoteNode != null)
                {
                    // Already voted
                    continue;
                }

                string voteIDText = nominationNode.GetAttributeValue("data-voteid", null);
                if (string.IsNullOrEmpty(voteIDText))
                {
                    Bot.ArchiLogger.LogNullError(nameof(voteIDText));
                    return;
                }

                if (!byte.TryParse(voteIDText, out byte voteID) || (voteID == 0))
                {
                    Bot.ArchiLogger.LogNullError(nameof(voteID));
                    return;
                }

                HtmlNodeCollection voteNodes = nominationNode.SelectNodes("./div[starts-with(@class, 'vote_nomination')]");
                if (voteNodes == null)
                {
                    Bot.ArchiLogger.LogNullError(nameof(voteNodes));
                    return;
                }

                // Random a game we'll actually vote for, we don't want to make GabeN angry by rigging votes...
                HtmlNode voteNode = voteNodes[Utilities.RandomNext(voteNodes.Count)];

                string appIDText = voteNode.GetAttributeValue("data-vote-appid", null);
                if (string.IsNullOrEmpty(appIDText))
                {
                    Bot.ArchiLogger.LogNullError(nameof(appIDText));
                    return;
                }

                if (!uint.TryParse(appIDText, out uint appID) || (appID == 0))
                {
                    Bot.ArchiLogger.LogNullError(nameof(appID));
                    return;
                }

                await Bot.ArchiWebHandler.SteamAwardsVote(voteID, appID).ConfigureAwait(false);
            }
        }
Example #2
0
        private void SortGamesToFarm()
        {
            IOrderedEnumerable <Game> gamesToFarm;

            switch (Bot.BotConfig.FarmingOrder)
            {
            case BotConfig.EFarmingOrder.Unordered:
                return;

            case BotConfig.EFarmingOrder.AppIDsAscending:
                gamesToFarm = GamesToFarm.OrderBy(game => game.AppID);
                break;

            case BotConfig.EFarmingOrder.AppIDsDescending:
                gamesToFarm = GamesToFarm.OrderByDescending(game => game.AppID);
                break;

            case BotConfig.EFarmingOrder.CardDropsAscending:
                gamesToFarm = GamesToFarm.OrderBy(game => game.CardsRemaining);
                break;

            case BotConfig.EFarmingOrder.CardDropsDescending:
                gamesToFarm = GamesToFarm.OrderByDescending(game => game.CardsRemaining);
                break;

            case BotConfig.EFarmingOrder.HoursAscending:
                gamesToFarm = GamesToFarm.OrderBy(game => game.HoursPlayed);
                break;

            case BotConfig.EFarmingOrder.HoursDescending:
                gamesToFarm = GamesToFarm.OrderByDescending(game => game.HoursPlayed);
                break;

            case BotConfig.EFarmingOrder.NamesAscending:
                gamesToFarm = GamesToFarm.OrderBy(game => game.GameName);
                break;

            case BotConfig.EFarmingOrder.NamesDescending:
                gamesToFarm = GamesToFarm.OrderByDescending(game => game.GameName);
                break;

            case BotConfig.EFarmingOrder.Random:
                gamesToFarm = GamesToFarm.OrderBy(game => Utilities.RandomNext());
                break;

            default:
                Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(Bot.BotConfig.FarmingOrder)));
                return;
            }

            GamesToFarm.ReplaceWith(gamesToFarm.ToList());             // We must call ToList() here as we can't enumerate during replacing
        }
Example #3
0
        private async Task SortGamesToFarm()
        {
            // Put priority idling appIDs on top
            IOrderedEnumerable <Game> gamesToFarm = GamesToFarm.OrderByDescending(game => Bot.IsPriorityIdling(game.AppID));

            foreach (BotConfig.EFarmingOrder farmingOrder in Bot.BotConfig.FarmingOrders)
            {
                switch (farmingOrder)
                {
                case BotConfig.EFarmingOrder.Unordered:
                    break;

                case BotConfig.EFarmingOrder.AppIDsAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => game.AppID);
                    break;

                case BotConfig.EFarmingOrder.AppIDsDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => game.AppID);
                    break;

                case BotConfig.EFarmingOrder.BadgeLevelsAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => game.BadgeLevel);
                    break;

                case BotConfig.EFarmingOrder.BadgeLevelsDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => game.BadgeLevel);
                    break;

                case BotConfig.EFarmingOrder.CardDropsAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => game.CardsRemaining);
                    break;

                case BotConfig.EFarmingOrder.CardDropsDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => game.CardsRemaining);
                    break;

                case BotConfig.EFarmingOrder.MarketableAscending:
                case BotConfig.EFarmingOrder.MarketableDescending:
                    HashSet <uint> marketableAppIDs = await Bot.GetMarketableAppIDs().ConfigureAwait(false);

                    if ((marketableAppIDs != null) && (marketableAppIDs.Count > 0))
                    {
                        switch (farmingOrder)
                        {
                        case BotConfig.EFarmingOrder.MarketableAscending:
                            gamesToFarm = gamesToFarm.ThenBy(game => marketableAppIDs.Contains(game.AppID));
                            break;

                        case BotConfig.EFarmingOrder.MarketableDescending:
                            gamesToFarm = gamesToFarm.ThenByDescending(game => marketableAppIDs.Contains(game.AppID));
                            break;

                        default:
                            Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(farmingOrder), farmingOrder));
                            return;
                        }
                    }

                    break;

                case BotConfig.EFarmingOrder.HoursAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => game.HoursPlayed);
                    break;

                case BotConfig.EFarmingOrder.HoursDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => game.HoursPlayed);
                    break;

                case BotConfig.EFarmingOrder.NamesAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => game.GameName);
                    break;

                case BotConfig.EFarmingOrder.NamesDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => game.GameName);
                    break;

                case BotConfig.EFarmingOrder.Random:
                    gamesToFarm = gamesToFarm.ThenBy(game => Utilities.RandomNext());
                    break;

                case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
                case BotConfig.EFarmingOrder.RedeemDateTimesDescending:
                    Dictionary <uint, DateTime> redeemDates = new Dictionary <uint, DateTime>(GamesToFarm.Count);

                    foreach (Game game in GamesToFarm)
                    {
                        DateTime       redeemDate = DateTime.MinValue;
                        HashSet <uint> packageIDs = Program.GlobalDatabase.GetPackageIDs(game.AppID);

                        if (packageIDs != null)
                        {
                            foreach (uint packageID in packageIDs)
                            {
                                if (!Bot.OwnedPackageIDs.TryGetValue(packageID, out (EPaymentMethod PaymentMethod, DateTime TimeCreated)packageData))
                                {
                                    continue;
                                }

                                if (packageData.TimeCreated > redeemDate)
                                {
                                    redeemDate = packageData.TimeCreated;
                                }
                            }
                        }

                        redeemDates[game.AppID] = redeemDate;
                    }

                    switch (farmingOrder)
                    {
                    case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
                        gamesToFarm = gamesToFarm.ThenBy(game => redeemDates[game.AppID]);
                        break;

                    case BotConfig.EFarmingOrder.RedeemDateTimesDescending:
                        gamesToFarm = gamesToFarm.ThenByDescending(game => redeemDates[game.AppID]);
                        break;

                    default:
                        Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(farmingOrder), farmingOrder));
                        return;
                    }

                    break;

                default:
                    Bot.ArchiLogger.LogGenericError(string.Format(Strings.WarningUnknownValuePleaseReport, nameof(farmingOrder), farmingOrder));
                    return;
                }
            }

            // We must call ToList() here as we can't replace items while enumerating
            GamesToFarm.ReplaceWith(gamesToFarm.ToList());
        }
        private void SortGamesToFarm()
        {
            IOrderedEnumerable <Game> gamesToFarm = GamesToFarm.OrderBy(game => Bot.IsPriorityIdling(game.AppID) ? 1 : 0);

            switch (Bot.BotConfig.FarmingOrder)
            {
            case BotConfig.EFarmingOrder.Unordered:
                break;

            case BotConfig.EFarmingOrder.AppIDsAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.AppID);
                break;

            case BotConfig.EFarmingOrder.AppIDsDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.AppID);
                break;

            case BotConfig.EFarmingOrder.BadgeLevelsAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.BadgeLevel);
                break;

            case BotConfig.EFarmingOrder.BadgeLevelsDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.BadgeLevel);
                break;

            case BotConfig.EFarmingOrder.CardDropsAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.CardsRemaining);
                break;

            case BotConfig.EFarmingOrder.CardDropsDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.CardsRemaining);
                break;

            case BotConfig.EFarmingOrder.HoursAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.HoursPlayed);
                break;

            case BotConfig.EFarmingOrder.HoursDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.HoursPlayed);
                break;

            case BotConfig.EFarmingOrder.NamesAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.GameName);
                break;

            case BotConfig.EFarmingOrder.NamesDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.GameName);
                break;

            case BotConfig.EFarmingOrder.Random:
                gamesToFarm = gamesToFarm.ThenBy(game => Utilities.RandomNext());
                break;

            case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
            case BotConfig.EFarmingOrder.RedeemDateTimesDescending:
                Dictionary <uint, DateTime> redeemDates = new Dictionary <uint, DateTime>(GamesToFarm.Count);

                foreach (Game game in GamesToFarm)
                {
                    DateTime redeemDate = DateTime.MinValue;
                    if (Program.GlobalDatabase.AppIDsToPackageIDs.TryGetValue(game.AppID, out ConcurrentHashSet <uint> packageIDs))
                    {
                        // ReSharper disable once LoopCanBePartlyConvertedToQuery - C# 7.0 out can't be used within LINQ query yet | https://github.com/dotnet/roslyn/issues/15619
                        foreach (uint packageID in packageIDs)
                        {
                            if (!Bot.OwnedPackageIDs.TryGetValue(packageID, out (EPaymentMethod PaymentMethod, DateTime TimeCreated)packageData))
                            {
                                continue;
                            }

                            if (packageData.TimeCreated > redeemDate)
                            {
                                redeemDate = packageData.TimeCreated;
                            }
                        }
                    }

                    redeemDates[game.AppID] = redeemDate;
                }

                switch (Bot.BotConfig.FarmingOrder)
                {
                case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => redeemDates[game.AppID]);
                    break;

                case BotConfig.EFarmingOrder.RedeemDateTimesDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => redeemDates[game.AppID]);
                    break;

                default:
                    Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(Bot.BotConfig.FarmingOrder)));
                    return;
                }

                break;

            default:
                Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(Bot.BotConfig.FarmingOrder)));
                return;
            }

            // We must call ToList() here as we can't enumerate during replacing
            GamesToFarm.ReplaceWith(gamesToFarm.ToList());
        }
Example #5
0
        private void SortGamesToFarm()
        {
            // Put priority idling appIDs on top
            IOrderedEnumerable <Game> gamesToFarm = GamesToFarm.OrderByDescending(game => Bot.IsPriorityIdling(game.AppID));

            switch (Bot.BotConfig.FarmingOrder)
            {
            case BotConfig.EFarmingOrder.Unordered:
                break;

            case BotConfig.EFarmingOrder.AppIDsAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.AppID);
                break;

            case BotConfig.EFarmingOrder.AppIDsDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.AppID);
                break;

            case BotConfig.EFarmingOrder.BadgeLevelsAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.BadgeLevel);
                break;

            case BotConfig.EFarmingOrder.BadgeLevelsDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.BadgeLevel);
                break;

            case BotConfig.EFarmingOrder.CardDropsAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.CardsRemaining);
                break;

            case BotConfig.EFarmingOrder.CardDropsDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.CardsRemaining);
                break;

            case BotConfig.EFarmingOrder.HoursAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.HoursPlayed);
                break;

            case BotConfig.EFarmingOrder.HoursDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.HoursPlayed);
                break;

            case BotConfig.EFarmingOrder.NamesAscending:
                gamesToFarm = gamesToFarm.ThenBy(game => game.GameName);
                break;

            case BotConfig.EFarmingOrder.NamesDescending:
                gamesToFarm = gamesToFarm.ThenByDescending(game => game.GameName);
                break;

            case BotConfig.EFarmingOrder.Random:
                gamesToFarm = gamesToFarm.ThenBy(game => Utilities.RandomNext());
                break;

            case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
            case BotConfig.EFarmingOrder.RedeemDateTimesDescending:
                Dictionary <uint, DateTime> redeemDates = new Dictionary <uint, DateTime>(GamesToFarm.Count);

                foreach (Game game in GamesToFarm)
                {
                    DateTime redeemDate = DateTime.MinValue;
                    if (Program.GlobalDatabase.AppIDsToPackageIDs.TryGetValue(game.AppID, out ConcurrentHashSet <uint> packageIDs))
                    {
                        foreach (uint packageID in packageIDs)
                        {
                            if (!Bot.OwnedPackageIDs.TryGetValue(packageID, out (EPaymentMethod PaymentMethod, DateTime TimeCreated)packageData))
                            {
                                continue;
                            }

                            if (packageData.TimeCreated > redeemDate)
                            {
                                redeemDate = packageData.TimeCreated;
                            }
                        }
                    }

                    redeemDates[game.AppID] = redeemDate;
                }

                switch (Bot.BotConfig.FarmingOrder)
                {
                case BotConfig.EFarmingOrder.RedeemDateTimesAscending:
                    gamesToFarm = gamesToFarm.ThenBy(game => redeemDates[game.AppID]);
                    break;

                case BotConfig.EFarmingOrder.RedeemDateTimesDescending:
                    gamesToFarm = gamesToFarm.ThenByDescending(game => redeemDates[game.AppID]);
                    break;

                default:
                    Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(Bot.BotConfig.FarmingOrder)));
                    return;
                }

                break;

            default:
                Bot.ArchiLogger.LogGenericError(string.Format(Strings.ErrorIsInvalid, nameof(Bot.BotConfig.FarmingOrder)));
                return;
            }

            // We must call ToList() here as we can't replace items while enumerating
            GamesToFarm.ReplaceWith(gamesToFarm.ToList());
        }
        public async Task <bool> VoteForSteamAwards()
        {
            HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetSteamAwardsPage().ConfigureAwait(false);

            if (htmlDocument == null)
            {
                Bot.ArchiLogger.LogNullError("htmlDocument", "VoteForSteamAwards");
                return(false);
            }

            HtmlNodeCollection votePanelNodes = htmlDocument.DocumentNode.SelectNodes("//div[@class='vote_nominations store_horizontal_autoslider']");

            if (votePanelNodes == null)
            {
                Bot.ArchiLogger.LogNullError("noVotePanels", "VoteForSteamAwards");
                return(false);
            }

            List <bool> successes = new List <bool>();

            foreach (HtmlNode votePanelNode in votePanelNodes)
            {
                HtmlNode yourVoteNode = votePanelNode.SelectSingleNode("./div[@class='vote_nomination your_vote']");
                if (yourVoteNode == null)
                {
                    uint voteID;
                    if (uint.TryParse(votePanelNode.GetAttributeValue("data-voteid", (string)null), out voteID))
                    {
                        HtmlNodeCollection nominationNodes = votePanelNode.SelectNodes("./div[starts-with(@class, 'vote_nomination')]");
                        if (nominationNodes == null)
                        {
                            Bot.ArchiLogger.LogNullError("voteNodes", "VoteForSteamAwards");
                            successes.Add(false);
                        }
                        else
                        {
                            int count       = nominationNodes.Count;
                            int randomIndex = Utilities.RandomNext(count);

                            Bot.ArchiLogger.LogGenericInfo("nominationGamesCount", count.ToString());
                            Bot.ArchiLogger.LogGenericInfo("nominationGameRandomIndex", randomIndex.ToString());

                            uint appIDToVoteFor;

                            if (uint.TryParse(nominationNodes[randomIndex].GetAttributeValue("data-vote-appid", (string)null), out appIDToVoteFor))
                            {
                                Bot.ArchiLogger.LogGenericInfo("nominationVoteID", voteID.ToString());
                                Bot.ArchiLogger.LogGenericInfo("nominationAppID", appIDToVoteFor.ToString());

                                bool success = await Bot.ArchiWebHandler.SteamAwardsVote(voteID, appIDToVoteFor).ConfigureAwait(false);

                                if (success)
                                {
                                    Bot.ArchiLogger.LogGenericInfo("successVote", "voteid: " + voteID + ", appid: " + appIDToVoteFor);
                                }
                                else
                                {
                                    Bot.ArchiLogger.LogGenericError("failedVote", "voteid: " + voteID + ", appid: " + appIDToVoteFor);
                                }

                                successes.Add(success);
                            }
                            else
                            {
                                Bot.ArchiLogger.LogNullError("appID", "VoteForSteamAwards");
                                successes.Add(false);
                            }
                        }
                    }
                    else
                    {
                        Bot.ArchiLogger.LogNullError("voteID", "VoteForSteamAwards");
                        successes.Add(false);
                    }
                }
            }

            return(successes.All(x => x));
        }