From 978e6a3d0ca4f2a6563d02c08e150f9441534c24 Mon Sep 17 00:00:00 2001 From: JustArchi Date: Fri, 10 Jul 2020 00:40:11 +0200 Subject: [PATCH] Change acceptedTradeOfferIDs into acceptedCreatorIDs This makes it possible to accept other confirmation types than trading if they follow the same logic with creator ID. If somebody wants to ensure that he's accepting only trades with given IDs, then he should combine it with acceptedType, which is already supported and expected. This makes it possible to use ASF's HandleTwoFactorAuthenticationConfirmations() e.g. for market listings in custom plugins. Answers the remaining part of #1891 --- ArchiSteamFarm/Actions.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ArchiSteamFarm/Actions.cs b/ArchiSteamFarm/Actions.cs index bd51d8986..2f8afeba7 100644 --- a/ArchiSteamFarm/Actions.cs +++ b/ArchiSteamFarm/Actions.cs @@ -89,7 +89,7 @@ namespace ArchiSteamFarm { } [PublicAPI] - public async Task<(bool Success, string Message)> HandleTwoFactorAuthenticationConfirmations(bool accept, MobileAuthenticator.Confirmation.EType? acceptedType = null, IReadOnlyCollection acceptedTradeOfferIDs = null, bool waitIfNeeded = false) { + public async Task<(bool Success, string Message)> HandleTwoFactorAuthenticationConfirmations(bool accept, MobileAuthenticator.Confirmation.EType? acceptedType = null, IReadOnlyCollection acceptedCreatorIDs = null, bool waitIfNeeded = false) { if (!Bot.HasMobileAuthenticator) { return (false, Strings.BotNoASFAuthenticator); } @@ -99,7 +99,7 @@ namespace ArchiSteamFarm { } ushort handledConfirmationsCount = 0; - HashSet handledTradeOfferIDs = null; + HashSet handledCreatorIDs = null; for (byte i = 0; (i == 0) || ((i < WebBrowser.MaxTries) && waitIfNeeded); i++) { if (i > 0) { @@ -120,8 +120,8 @@ namespace ArchiSteamFarm { } } - if ((acceptedTradeOfferIDs != null) && (acceptedTradeOfferIDs.Count > 0)) { - if (confirmations.RemoveWhere(confirmation => (confirmation.Type != MobileAuthenticator.Confirmation.EType.Trade) || !acceptedTradeOfferIDs.Contains(confirmation.Creator)) > 0) { + if ((acceptedCreatorIDs != null) && (acceptedCreatorIDs.Count > 0)) { + if (confirmations.RemoveWhere(confirmation => !acceptedCreatorIDs.Contains(confirmation.Creator)) > 0) { if (confirmations.Count == 0) { continue; } @@ -134,17 +134,17 @@ namespace ArchiSteamFarm { handledConfirmationsCount += (ushort) confirmations.Count; - if ((acceptedTradeOfferIDs != null) && (acceptedTradeOfferIDs.Count > 0)) { - IEnumerable handledTradeOfferIDsThisRound = confirmations.Where(confirmation => (confirmation.Type == MobileAuthenticator.Confirmation.EType.Trade) && acceptedTradeOfferIDs.Contains(confirmation.Creator)).Select(confirmation => confirmation.Creator); + if ((acceptedCreatorIDs != null) && (acceptedCreatorIDs.Count > 0)) { + IEnumerable handledCreatorIDsThisRound = confirmations.Select(confirmation => confirmation.Creator).Where(acceptedCreatorIDs.Contains); - if (handledTradeOfferIDs != null) { - handledTradeOfferIDs.UnionWith(handledTradeOfferIDsThisRound); + if (handledCreatorIDs != null) { + handledCreatorIDs.UnionWith(handledCreatorIDsThisRound); } else { - handledTradeOfferIDs = handledTradeOfferIDsThisRound.ToHashSet(); + handledCreatorIDs = handledCreatorIDsThisRound.ToHashSet(); } // Check if those are all that we were expected to confirm - if (handledTradeOfferIDs.SetEquals(acceptedTradeOfferIDs)) { + if (handledCreatorIDs.SetEquals(acceptedCreatorIDs)) { return (true, string.Format(Strings.BotHandledConfirmations, handledConfirmationsCount)); } }