From 41823dcceacdb048afd70b610228dcd53dad4440 Mon Sep 17 00:00:00 2001 From: Citrinate Date: Tue, 19 Mar 2024 17:51:06 -0400 Subject: [PATCH] Added removepending command --- BoosterManager/Commands.cs | 32 +++++++++++++++++ BoosterManager/Handlers/MarketHandler.cs | 46 ++++++++++++++++++++++++ README.md | 2 ++ 3 files changed, 80 insertions(+) diff --git a/BoosterManager/Commands.cs b/BoosterManager/Commands.cs index 5ebfe3b..c0a2e8f 100644 --- a/BoosterManager/Commands.cs +++ b/BoosterManager/Commands.cs @@ -175,6 +175,9 @@ internal static class Commands { case "MARKET2FAOK" or "M2FAOK": return await Response2FAOK(bot, access, Confirmation.EConfirmationType.Market).ConfigureAwait(false); + case "REMOVEPENDING" or "REMOVEPENDINGLISTINGS" or "CANCELPENDING" or "CANCELPENDINGLISTINGS" or "RP": + return await ResponseRemovePendingListings(bot, access).ConfigureAwait(false); + case "T2FAOKA": return await Response2FAOK(access, steamID, "ASF", Confirmation.EConfirmationType.Trade).ConfigureAwait(false); case "TRADE2FAOK" or "T2FAOK": @@ -468,6 +471,9 @@ internal static class Commands { return await ResponseRemoveListings(access, steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false); case "REMOVELISTINGS" or "REMOVELISTING" or "CANCELLISTINGS" or "CANCELLISTING" or "RLISTINGS" or "RLISTING" or "REMOVEL" or "RL" : return await ResponseRemoveListings(bot, access, args[1]).ConfigureAwait(false); + + case "REMOVEPENDING" or "REMOVEPENDINGLISTINGS" or "CANCELPENDING" or "CANCELPENDINGLISTINGS" or "RP": + return await ResponseRemovePendingListings(access, steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); case "UNPACKGEMS" or "UNPACKGEM": return await ResponseUnpackGems(access, steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false); @@ -1273,6 +1279,32 @@ internal static class Commands { return await ResponseRemoveListings(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), listingIDs).ConfigureAwait(false); } + private static async Task ResponseRemovePendingListings(Bot bot, EAccess access) { + if (access < EAccess.Master) { + return null; + } + + if (!bot.IsConnectedAndLoggedOn) { + return FormatBotResponse(bot, Strings.BotNotConnected); + } + + return await MarketHandler.RemovePendingListings(bot).ConfigureAwait(false); + } + + private static async Task ResponseRemovePendingListings(EAccess access, ulong steamID, string botName) { + if (String.IsNullOrEmpty(botName)) { + throw new ArgumentNullException(nameof(botName)); + } + + Bot? bot = Bot.GetBot(botName); + + if (bot == null) { + return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, botName)) : null; + } + + return await ResponseRemovePendingListings(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID)).ConfigureAwait(false); + } + private static async Task ResponseSendItemToBot(Bot bot, EAccess access, ItemIdentifier itemIdentifier, bool? marketable = null, string? recieverBotName = null) { string? appIDAsText = itemIdentifier.AppID.ToString(); if (appIDAsText == null) { diff --git a/BoosterManager/Handlers/MarketHandler.cs b/BoosterManager/Handlers/MarketHandler.cs index 997d77b..40e3a4b 100644 --- a/BoosterManager/Handlers/MarketHandler.cs +++ b/BoosterManager/Handlers/MarketHandler.cs @@ -90,6 +90,52 @@ internal static async Task RemoveListings(Bot bot, List listingID return Commands.FormatBotResponse(bot, String.Format("Removed {0} listings", listingIDs.Count)); } + + internal static async Task RemovePendingListings(Bot bot) { + (Steam.MarketListingsResponse? marketListings, _) = await WebRequest.GetMarketListings(bot).ConfigureAwait(false); + + if (marketListings == null || marketListings.ListingsToConfirm == null || !marketListings.Success) { + return "Failed to load Market Listings"; + } + + if (marketListings.ListingsToConfirm.Count == 0) { + return "No pending market listings found"; + } + + HashSet pendingListingIDs = new(); + + foreach (JsonNode? listing in marketListings.ListingsToConfirm) { + if (listing == null) { + bot.ArchiLogger.LogNullError(listing); + + return "Failed to load Market Listings"; + } + + ulong? listingid = listing["listingid"]?.ToString().ToJsonObject(); + if (listingid == null) { + bot.ArchiLogger.LogNullError(listingid); + + return "Failed to load Market Listings"; + } + + pendingListingIDs.Add(listingid.Value); + } + + int failedToRemove = 0; + + foreach (ulong listingID in pendingListingIDs) { + await Task.Delay(100).ConfigureAwait(false); + if (!await WebRequest.RemoveListing(bot, listingID).ConfigureAwait(false)) { + failedToRemove++; + } + } + + if (failedToRemove != 0) { + return String.Format("Successfully removed {0} pending market listings, failed to remove {1} listings", pendingListingIDs.Count - failedToRemove, failedToRemove); + } + + return String.Format("Successfully removed {0} pending market listings", pendingListingIDs.Count); + } internal static async Task FindAndRemoveListings(Bot bot, List itemIdentifiers) { Dictionary>? filteredListings = await GetListingIDsFromIdentifiers(bot, itemIdentifiers).ConfigureAwait(false); diff --git a/README.md b/README.md index 2ffc24f..3ca5cab 100644 --- a/README.md +++ b/README.md @@ -107,6 +107,7 @@ Command | Access | Description `findandremovelistings `|`Master`|Removes any market listing belonging to the given bot and matching any of the [`ItemIdentifiers`](#itemidentifiers). `listings [Bots]`|`Master`|Displays the total value of all market listings owned by the given bot. `removelistings [Bot] `|`Master`|Removes market `ListingIDs` belonging to the given bot. +`removepending `|`Master`|Removes all pending market listings belonging to the given bot. `market2faok [Bot] [Minutes]`|`Master`|Accepts all pending 2FA market confirmations for given bot instances. Optionally repeat this action once every `Minutes`. To cancel any repetition, set `Minutes` to 0. `value [Bots] [BalanceLimit]`|`Master`|Displays the combined wallet balance and total value of all market listings owned by the given bot. The maximum allowed balance in your region may be provided as `BalanceLimit`, a whole number, and it will instead display how close the given bot is to reaching that limit. @@ -149,6 +150,7 @@ Command | Alias | `findlistings`|`fl` `findandremovelistings`|`frl` `removelistings`|`rlistings`, `removel` +`removepending`|`rp` `logboosterdata`|`logbd` `loginventoryhistory`|`logih` `logmarketlistings`|`logml`