Skip to content

Commit 41823dc

Browse files
committed
Added removepending command
1 parent b50f4fa commit 41823dc

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed

BoosterManager/Commands.cs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ internal static class Commands {
175175
case "MARKET2FAOK" or "M2FAOK":
176176
return await Response2FAOK(bot, access, Confirmation.EConfirmationType.Market).ConfigureAwait(false);
177177

178+
case "REMOVEPENDING" or "REMOVEPENDINGLISTINGS" or "CANCELPENDING" or "CANCELPENDINGLISTINGS" or "RP":
179+
return await ResponseRemovePendingListings(bot, access).ConfigureAwait(false);
180+
178181
case "T2FAOKA":
179182
return await Response2FAOK(access, steamID, "ASF", Confirmation.EConfirmationType.Trade).ConfigureAwait(false);
180183
case "TRADE2FAOK" or "T2FAOK":
@@ -468,6 +471,9 @@ internal static class Commands {
468471
return await ResponseRemoveListings(access, steamID, args[1], Utilities.GetArgsAsText(args, 2, ",")).ConfigureAwait(false);
469472
case "REMOVELISTINGS" or "REMOVELISTING" or "CANCELLISTINGS" or "CANCELLISTING" or "RLISTINGS" or "RLISTING" or "REMOVEL" or "RL" :
470473
return await ResponseRemoveListings(bot, access, args[1]).ConfigureAwait(false);
474+
475+
case "REMOVEPENDING" or "REMOVEPENDINGLISTINGS" or "CANCELPENDING" or "CANCELPENDINGLISTINGS" or "RP":
476+
return await ResponseRemovePendingListings(access, steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
471477

472478
case "UNPACKGEMS" or "UNPACKGEM":
473479
return await ResponseUnpackGems(access, steamID, Utilities.GetArgsAsText(args, 1, ",")).ConfigureAwait(false);
@@ -1273,6 +1279,32 @@ internal static class Commands {
12731279
return await ResponseRemoveListings(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), listingIDs).ConfigureAwait(false);
12741280
}
12751281

1282+
private static async Task<string?> ResponseRemovePendingListings(Bot bot, EAccess access) {
1283+
if (access < EAccess.Master) {
1284+
return null;
1285+
}
1286+
1287+
if (!bot.IsConnectedAndLoggedOn) {
1288+
return FormatBotResponse(bot, Strings.BotNotConnected);
1289+
}
1290+
1291+
return await MarketHandler.RemovePendingListings(bot).ConfigureAwait(false);
1292+
}
1293+
1294+
private static async Task<string?> ResponseRemovePendingListings(EAccess access, ulong steamID, string botName) {
1295+
if (String.IsNullOrEmpty(botName)) {
1296+
throw new ArgumentNullException(nameof(botName));
1297+
}
1298+
1299+
Bot? bot = Bot.GetBot(botName);
1300+
1301+
if (bot == null) {
1302+
return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, botName)) : null;
1303+
}
1304+
1305+
return await ResponseRemovePendingListings(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID)).ConfigureAwait(false);
1306+
}
1307+
12761308
private static async Task<string?> ResponseSendItemToBot(Bot bot, EAccess access, ItemIdentifier itemIdentifier, bool? marketable = null, string? recieverBotName = null) {
12771309
string? appIDAsText = itemIdentifier.AppID.ToString();
12781310
if (appIDAsText == null) {

BoosterManager/Handlers/MarketHandler.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,52 @@ internal static async Task<string> RemoveListings(Bot bot, List<ulong> listingID
9090

9191
return Commands.FormatBotResponse(bot, String.Format("Removed {0} listings", listingIDs.Count));
9292
}
93+
94+
internal static async Task<string> RemovePendingListings(Bot bot) {
95+
(Steam.MarketListingsResponse? marketListings, _) = await WebRequest.GetMarketListings(bot).ConfigureAwait(false);
96+
97+
if (marketListings == null || marketListings.ListingsToConfirm == null || !marketListings.Success) {
98+
return "Failed to load Market Listings";
99+
}
100+
101+
if (marketListings.ListingsToConfirm.Count == 0) {
102+
return "No pending market listings found";
103+
}
104+
105+
HashSet<ulong> pendingListingIDs = new();
106+
107+
foreach (JsonNode? listing in marketListings.ListingsToConfirm) {
108+
if (listing == null) {
109+
bot.ArchiLogger.LogNullError(listing);
110+
111+
return "Failed to load Market Listings";
112+
}
113+
114+
ulong? listingid = listing["listingid"]?.ToString().ToJsonObject<ulong>();
115+
if (listingid == null) {
116+
bot.ArchiLogger.LogNullError(listingid);
117+
118+
return "Failed to load Market Listings";
119+
}
120+
121+
pendingListingIDs.Add(listingid.Value);
122+
}
123+
124+
int failedToRemove = 0;
125+
126+
foreach (ulong listingID in pendingListingIDs) {
127+
await Task.Delay(100).ConfigureAwait(false);
128+
if (!await WebRequest.RemoveListing(bot, listingID).ConfigureAwait(false)) {
129+
failedToRemove++;
130+
}
131+
}
132+
133+
if (failedToRemove != 0) {
134+
return String.Format("Successfully removed {0} pending market listings, failed to remove {1} listings", pendingListingIDs.Count - failedToRemove, failedToRemove);
135+
}
136+
137+
return String.Format("Successfully removed {0} pending market listings", pendingListingIDs.Count);
138+
}
93139

94140
internal static async Task<string> FindAndRemoveListings(Bot bot, List<ItemIdentifier> itemIdentifiers) {
95141
Dictionary<string, List<ulong>>? filteredListings = await GetListingIDsFromIdentifiers(bot, itemIdentifiers).ConfigureAwait(false);

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ Command | Access | Description
107107
`findandremovelistings <Bots> <ItemIdentifiers>`|`Master`|Removes any market listing belonging to the given bot and matching any of the [`ItemIdentifiers`](#itemidentifiers).
108108
`listings [Bots]`|`Master`|Displays the total value of all market listings owned by the given bot.
109109
`removelistings [Bot] <ListingIDs>`|`Master`|Removes market `ListingIDs` belonging to the given bot.
110+
`removepending <Bots>`|`Master`|Removes all pending market listings belonging to the given bot.
110111
`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.
111112
`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.
112113

@@ -149,6 +150,7 @@ Command | Alias |
149150
`findlistings`|`fl`
150151
`findandremovelistings`|`frl`
151152
`removelistings`|`rlistings`, `removel`
153+
`removepending`|`rp`
152154
`logboosterdata`|`logbd`
153155
`loginventoryhistory`|`logih`
154156
`logmarketlistings`|`logml`

0 commit comments

Comments
 (0)