Skip to content

Commit

Permalink
Added removepending command
Browse files Browse the repository at this point in the history
  • Loading branch information
Citrinate committed Mar 19, 2024
1 parent b50f4fa commit 41823dc
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
32 changes: 32 additions & 0 deletions BoosterManager/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<string?> 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<string?> 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<string?> ResponseSendItemToBot(Bot bot, EAccess access, ItemIdentifier itemIdentifier, bool? marketable = null, string? recieverBotName = null) {
string? appIDAsText = itemIdentifier.AppID.ToString();
if (appIDAsText == null) {
Expand Down
46 changes: 46 additions & 0 deletions BoosterManager/Handlers/MarketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,52 @@ internal static async Task<string> RemoveListings(Bot bot, List<ulong> listingID

return Commands.FormatBotResponse(bot, String.Format("Removed {0} listings", listingIDs.Count));
}

internal static async Task<string> 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<ulong> 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<ulong>();
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<string> FindAndRemoveListings(Bot bot, List<ItemIdentifier> itemIdentifiers) {
Dictionary<string, List<ulong>>? filteredListings = await GetListingIDsFromIdentifiers(bot, itemIdentifiers).ConfigureAwait(false);
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ Command | Access | Description
`findandremovelistings <Bots> <ItemIdentifiers>`|`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] <ListingIDs>`|`Master`|Removes market `ListingIDs` belonging to the given bot.
`removepending <Bots>`|`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.

Expand Down Expand Up @@ -149,6 +150,7 @@ Command | Alias |
`findlistings`|`fl`
`findandremovelistings`|`frl`
`removelistings`|`rlistings`, `removel`
`removepending`|`rp`
`logboosterdata`|`logbd`
`loginventoryhistory`|`logih`
`logmarketlistings`|`logml`
Expand Down

0 comments on commit 41823dc

Please sign in to comment.