From 89d614f0eccc2f54b786d235ee175d48be58b501 Mon Sep 17 00:00:00 2001 From: Citrinate Date: Wed, 3 Jan 2024 01:10:41 -0500 Subject: [PATCH] Fix lootitems and transferitems not accepting multiple identifiers --- BoosterManager/Commands.cs | 60 +++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/BoosterManager/Commands.cs b/BoosterManager/Commands.cs index 901c460..d45afe4 100644 --- a/BoosterManager/Commands.cs +++ b/BoosterManager/Commands.cs @@ -665,8 +665,7 @@ internal static class Commands { List itemIdentifiers = new List(); foreach (string itemIdentifierString in itemIdentifierStrings) { try { - ItemIdentifier itemIdentifier = new ItemIdentifier(itemIdentifierString); - itemIdentifiers.Add(itemIdentifier); + itemIdentifiers.Add(new ItemIdentifier(itemIdentifierString)); } catch (Exception) { return FormatBotResponse(bot, String.Format("Invalid Item Identifier: {0}", itemIdentifierString)); } @@ -710,8 +709,7 @@ internal static class Commands { List itemIdentifiers = new List(); foreach (string itemIdentifierString in itemIdentifierStrings) { try { - ItemIdentifier itemIdentifier = new ItemIdentifier(itemIdentifierString); - itemIdentifiers.Add(itemIdentifier); + itemIdentifiers.Add(new ItemIdentifier(itemIdentifierString)); } catch (Exception) { return FormatBotResponse(bot, String.Format("Invalid Item Identifier: {0}", itemIdentifierString)); } @@ -1108,7 +1106,7 @@ internal static class Commands { return await ResponseRemoveListings(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), listingIDs).ConfigureAwait(false); } - private static async Task ResponseSendItemToBot(Bot bot, EAccess access, string appIDAsText, string contextIDAsText, string itemIdentifierAsText, bool? marketable = null, string? recieverBotName = null) { + private static async Task ResponseSendItemToBot(Bot bot, EAccess access, string appIDAsText, string contextIDAsText, string itemIdentifiersAsText, bool? marketable = null, string? recieverBotName = null) { if (String.IsNullOrEmpty(appIDAsText)) { throw new ArgumentNullException(nameof(appIDAsText)); } @@ -1133,15 +1131,18 @@ internal static class Commands { return FormatBotResponse(bot, String.Format(Strings.ErrorIsInvalid, nameof(contextIDAsText))); } - if (String.IsNullOrEmpty(itemIdentifierAsText)) { - throw new ArgumentNullException(nameof(itemIdentifierAsText)); + if (String.IsNullOrEmpty(itemIdentifiersAsText)) { + throw new ArgumentNullException(nameof(itemIdentifiersAsText)); } - ItemIdentifier itemIdentifier; - try { - itemIdentifier = new ItemIdentifier(itemIdentifierAsText, marketable); - } catch (Exception) { - return FormatBotResponse(bot, String.Format("Invalid Item Identifier: {0}", itemIdentifierAsText)); + List itemIdentifierStrings = itemIdentifiersAsText.Split(ItemIdentifier.Delimiter, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); + List itemIdentifiers = new List(); + foreach (string itemIdentifierString in itemIdentifierStrings) { + try { + itemIdentifiers.Add(new ItemIdentifier(itemIdentifierString, marketable)); + } catch (Exception) { + return FormatBotResponse(bot, String.Format("Invalid Item Identifier: {0}", itemIdentifierString)); + } } ulong targetSteamID = 0; @@ -1163,12 +1164,12 @@ internal static class Commands { } } - (bool success, string message) = await bot.Actions.SendInventory(appID: appID, contextID: contextID, targetSteamID: targetSteamID, filterFunction: item => itemIdentifier.IsItemMatch(item)).ConfigureAwait(false); + (bool success, string message) = await bot.Actions.SendInventory(appID: appID, contextID: contextID, targetSteamID: targetSteamID, filterFunction: item => itemIdentifiers.Any(itemIdentifier => itemIdentifier.IsItemMatch(item))).ConfigureAwait(false); return FormatBotResponse(bot, success ? message : String.Format(Strings.WarningFailedWithError, message)); } - private static async Task ResponseSendItemToBot(EAccess access, ulong steamID, string senderBotNames, string appIDAsText, string contextIDAsText, string itemIdentifierAsText, bool? marketable = null, string? recieverBotName = null) { + private static async Task ResponseSendItemToBot(EAccess access, ulong steamID, string senderBotNames, string appIDAsText, string contextIDAsText, string itemIdentifiersAsText, bool? marketable = null, string? recieverBotName = null) { if (String.IsNullOrEmpty(senderBotNames)) { throw new ArgumentNullException(nameof(senderBotNames)); } @@ -1182,7 +1183,7 @@ internal static class Commands { // Send All of Item X to Bot C from Bots E,F,... // All of Item X to Bot C from Bot E // All of Item X to Bot C from Bot F - IList results = await Utilities.InParallel(bots.Select(bot => ResponseSendItemToBot(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), appIDAsText, contextIDAsText, itemIdentifierAsText, marketable, recieverBotName))).ConfigureAwait(false); + IList results = await Utilities.InParallel(bots.Select(bot => ResponseSendItemToBot(bot, ArchiSteamFarm.Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), appIDAsText, contextIDAsText, itemIdentifiersAsText, marketable, recieverBotName))).ConfigureAwait(false); List responses = new(results.Where(result => !String.IsNullOrEmpty(result))); @@ -1329,19 +1330,28 @@ internal static class Commands { return access >= EAccess.Owner ? FormatStaticResponse(String.Format(Strings.BotNotFound, recieverBotNames)) : null; } - string[] itemIdentifierStrings = itemIdentifiersAsText.Split(ItemIdentifier.Delimiter, StringSplitOptions.RemoveEmptyEntries).Distinct().ToArray(); + List itemIdentifierStrings = itemIdentifiersAsText.Split(ItemIdentifier.Delimiter, StringSplitOptions.RemoveEmptyEntries | StringSplitOptions.TrimEntries).ToList(); + List itemIdentifiers = new List(); + foreach (string itemIdentifierString in itemIdentifierStrings) { + try { + itemIdentifiers.Add(new ItemIdentifier(itemIdentifierString, marketable)); + } catch (Exception) { + return FormatBotResponse(bot, String.Format("Invalid Item Identifier: {0}", itemIdentifierString)); + } + } + string[] amountStrings = amountsAsText.Split(",", StringSplitOptions.RemoveEmptyEntries); if (amountStrings.Length == 0) { return FormatBotResponse(bot, String.Format(Strings.ErrorIsEmpty, nameof(amountStrings))); } - if (amountStrings.Length == 1 && itemIdentifierStrings.Length > 1) { - amountStrings = Enumerable.Repeat(amountStrings[0], itemIdentifierStrings.Length).ToArray(); + if (amountStrings.Length == 1 && itemIdentifierStrings.Count > 1) { + amountStrings = Enumerable.Repeat(amountStrings[0], itemIdentifierStrings.Count).ToArray(); } - if (amountStrings.Length != itemIdentifierStrings.Length) { - return FormatBotResponse(bot, String.Format("Number of items ({0}) does not match number of item amounts ({1})", itemIdentifierStrings.Length, amountStrings.Length)); + if (amountStrings.Length != itemIdentifierStrings.Count) { + return FormatBotResponse(bot, String.Format("Number of items ({0}) does not match number of item amounts ({1})", itemIdentifierStrings.Count, amountStrings.Length)); } List amounts = new List(); @@ -1353,16 +1363,6 @@ internal static class Commands { amounts.Add(amountNum); } - List itemIdentifiers = new List(); - foreach (string itemIdentifierString in itemIdentifierStrings) { - try { - ItemIdentifier itemIdentifier = new ItemIdentifier(itemIdentifierString, marketable); - itemIdentifiers.Add(itemIdentifier); - } catch (Exception) { - return FormatBotResponse(bot, String.Format("Invalid Item Identifier: {0}", itemIdentifierString)); - } - } - List<(ItemIdentifier, uint)> items = Zip(itemIdentifiers, amounts).ToList(); return await InventoryHandler.SendMultipleItemsToMultipleBots(bot, recieverBots, appID, contextID, items).ConfigureAwait(false);