mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
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
This commit is contained in:
@@ -89,7 +89,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
[PublicAPI]
|
||||
public async Task<(bool Success, string Message)> HandleTwoFactorAuthenticationConfirmations(bool accept, MobileAuthenticator.Confirmation.EType? acceptedType = null, IReadOnlyCollection<ulong> acceptedTradeOfferIDs = null, bool waitIfNeeded = false) {
|
||||
public async Task<(bool Success, string Message)> HandleTwoFactorAuthenticationConfirmations(bool accept, MobileAuthenticator.Confirmation.EType? acceptedType = null, IReadOnlyCollection<ulong> acceptedCreatorIDs = null, bool waitIfNeeded = false) {
|
||||
if (!Bot.HasMobileAuthenticator) {
|
||||
return (false, Strings.BotNoASFAuthenticator);
|
||||
}
|
||||
@@ -99,7 +99,7 @@ namespace ArchiSteamFarm {
|
||||
}
|
||||
|
||||
ushort handledConfirmationsCount = 0;
|
||||
HashSet<ulong> handledTradeOfferIDs = null;
|
||||
HashSet<ulong> 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<ulong> 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<ulong> 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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user