From 8ae9db3a3471a69d4522386961bfff4d054f5914 Mon Sep 17 00:00:00 2001 From: Florian Lang Date: Fri, 11 Aug 2017 22:36:03 +0200 Subject: [PATCH 1/5] transfer command easy version --- ArchiSteamFarm/Bot.cs | 163 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 160 insertions(+), 3 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 2656383c2..9dc79e881 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -796,7 +796,15 @@ namespace ArchiSteamFarm { } return await ResponseAddLicense(steamID, args[1]).ConfigureAwait(false); - case "!API": + case "!TRANSFER": + if (args.Length > 3) { + return await ResponseTransfer(steamID, args[1], args[2], args[3]).ConfigureAwait(false); + } + if (args.Length > 2) { + return await ResponseTransfer(steamID, args[1], args[2]).ConfigureAwait(false); + } + return await ResponseTransfer(steamID).ConfigureAwait(false); + case "!API": return ResponseAPI(steamID, args[1]); case "!BL": return await ResponseBlacklist(steamID, args[1]).ConfigureAwait(false); @@ -2293,7 +2301,7 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join("", responses) : null; } - private async Task ResponseAdvancedRedeem(ulong steamID, string options, string keys) { + private async Task ResponseAdvancedRedeem(ulong steamID, string options, string keys) { if ((steamID == 0) || string.IsNullOrEmpty(options) || string.IsNullOrEmpty(keys)) { ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(options) + " || " + nameof(keys)); return null; @@ -3912,7 +3920,156 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join("", responses) : null; } - private string ResponseUnknown(ulong steamID) { + private static async Task ResponseTransfer(ulong steamID) { + // modifie message / remove? + return "To less arguments"; + } + + private async Task ResponseTransfer(ulong steamID, string mode, string botNameTo) { + if ((steamID == 0) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(mode) + " || " + nameof(botNameTo)); + return null; + } + + if (!IsMaster(steamID)) { + return null; + } + + if (!IsConnectedAndLoggedOn) { + return FormatBotResponse(Strings.BotNotConnected); + } + + // Not sure if I need to keep it, guess it's better. + if (!LootingAllowed) { + return FormatBotResponse(Strings.BotLootingTemporarilyDisabled); + } + + HashSet botsT = GetBots(botNameTo); + if ((botsT == null) || (botsT.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameTo)) : null; + } + Bot botT = botsT.First(); + ulong targetSteamMasterID = botT.SteamID; + + if (targetSteamMasterID == SteamID) { + return FormatBotResponse(Strings.BotLootingYourself); + } + + if (!LootingSemaphore.Wait(0)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + + try { + HashSet tmp = new HashSet(); + string[] modes = mode.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string singleMode in modes) { + switch (singleMode.ToUpper()) { + case "C": // Not sure about shortcuts. + case "CARD": + tmp.Add(Steam.Item.EType.TradingCard); + break; + case "F": + case "FOIL": + tmp.Add(Steam.Item.EType.FoilTradingCard); + break; + case "B": + case "BOOSTER": + tmp.Add(Steam.Item.EType.BoosterPack); + break; + case "E": + case "EMOTICON": + tmp.Add(Steam.Item.EType.Emoticon); + break; + case "BA": + case "BACKGROUND": + tmp.Add(Steam.Item.EType.ProfileBackground); + break; + case "U": + case "UNKNOWN": + tmp.Add(Steam.Item.EType.Unknown); + break; + case "G": + case "GEMS": + tmp.Add(Steam.Item.EType.SteamGems); + break; + case "EV": + case "EVERYTHING": + // Needs to be kept up to date, or is there an easy way for all types? + tmp.Add(Steam.Item.EType.TradingCard); + tmp.Add(Steam.Item.EType.FoilTradingCard); + tmp.Add(Steam.Item.EType.BoosterPack); + tmp.Add(Steam.Item.EType.Emoticon); + tmp.Add(Steam.Item.EType.ProfileBackground); + tmp.Add(Steam.Item.EType.Unknown); + tmp.Add(Steam.Item.EType.SteamGems); + break; + default: + // adjust error message + return "Unknown mode " + singleMode + "!"; + } + } + + HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, tmp).ConfigureAwait(false); + if ((inventory == null) || (inventory.Count == 0)) { + return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(inventory))); + } + + if (!await ArchiWebHandler.MarkSentTrades().ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + + if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + + if (HasMobileAuthenticator) { + // Give Steam network some time to generate confirmations + await Task.Delay(3000).ConfigureAwait(false); + if (!await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamMasterID).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + } + } finally { + LootingSemaphore.Release(); + } + + return FormatBotResponse(Strings.BotLootingSuccess); + } + + + private static async Task ResponseTransfer(ulong steamID, string botNameFrom, string mode, string botNameTo) { + //standard procedure adapted from loot + if ((steamID == 0) || string.IsNullOrEmpty(botNameFrom) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNameFrom) + " || " + nameof(mode) + " || " + nameof(botNameTo)); + return null; + } + + HashSet botsF = GetBots(botNameFrom); + if ((botsF == null) || (botsF.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameFrom)) : null; + } + + IEnumerable> tasks = botsF.Select(bot => bot.ResponseTransfer(steamID, mode, botNameTo)); + ICollection results; + + switch (Program.GlobalConfig.OptimizationMode) { + case GlobalConfig.EOptimizationMode.MinMemoryUsage: + results = new List(botsF.Count); + foreach (Task task in tasks) { + results.Add(await task.ConfigureAwait(false)); + } + + break; + default: + results = await Task.WhenAll(tasks).ConfigureAwait(false); + break; + } + + List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); + return responses.Count > 0 ? string.Join("", responses) : null; + } + + private string ResponseUnknown(ulong steamID) { if (steamID != 0) { return IsOperator(steamID) ? FormatBotResponse(Strings.UnknownCommand) : null; } From b92a4ea5056765a0205f75cb68e5608b8906855f Mon Sep 17 00:00:00 2001 From: Florian Lang Date: Fri, 11 Aug 2017 22:51:27 +0200 Subject: [PATCH 2/5] switched to tab as intend --- ArchiSteamFarm/Bot.cs | 279 +++++++++++++++++++++--------------------- 1 file changed, 139 insertions(+), 140 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 9dc79e881..183395b33 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -796,15 +796,15 @@ namespace ArchiSteamFarm { } return await ResponseAddLicense(steamID, args[1]).ConfigureAwait(false); - case "!TRANSFER": - if (args.Length > 3) { - return await ResponseTransfer(steamID, args[1], args[2], args[3]).ConfigureAwait(false); - } - if (args.Length > 2) { - return await ResponseTransfer(steamID, args[1], args[2]).ConfigureAwait(false); - } - return await ResponseTransfer(steamID).ConfigureAwait(false); - case "!API": + case "!TRANSFER": + if (args.Length > 3) { + return await ResponseTransfer(steamID, args[1], args[2], args[3]).ConfigureAwait(false); + } + if (args.Length > 2) { + return await ResponseTransfer(steamID, args[1], args[2]).ConfigureAwait(false); + } + return await ResponseTransfer(steamID).ConfigureAwait(false); + case "!API": return ResponseAPI(steamID, args[1]); case "!BL": return await ResponseBlacklist(steamID, args[1]).ConfigureAwait(false); @@ -2301,7 +2301,7 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join("", responses) : null; } - private async Task ResponseAdvancedRedeem(ulong steamID, string options, string keys) { + private async Task ResponseAdvancedRedeem(ulong steamID, string options, string keys) { if ((steamID == 0) || string.IsNullOrEmpty(options) || string.IsNullOrEmpty(keys)) { ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(options) + " || " + nameof(keys)); return null; @@ -3920,156 +3920,155 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join("", responses) : null; } - private static async Task ResponseTransfer(ulong steamID) { - // modifie message / remove? - return "To less arguments"; - } + private static async Task ResponseTransfer(ulong steamID) { + // modifie message / remove? + return "To less arguments"; + } - private async Task ResponseTransfer(ulong steamID, string mode, string botNameTo) { - if ((steamID == 0) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(mode) + " || " + nameof(botNameTo)); - return null; - } + private async Task ResponseTransfer(ulong steamID, string mode, string botNameTo) { + if ((steamID == 0) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(mode) + " || " + nameof(botNameTo)); + return null; + } - if (!IsMaster(steamID)) { - return null; - } + if (!IsMaster(steamID)) { + return null; + } - if (!IsConnectedAndLoggedOn) { - return FormatBotResponse(Strings.BotNotConnected); - } + if (!IsConnectedAndLoggedOn) { + return FormatBotResponse(Strings.BotNotConnected); + } - // Not sure if I need to keep it, guess it's better. - if (!LootingAllowed) { - return FormatBotResponse(Strings.BotLootingTemporarilyDisabled); - } + // Not sure if I need to keep it, guess it's better. + if (!LootingAllowed) { + return FormatBotResponse(Strings.BotLootingTemporarilyDisabled); + } - HashSet botsT = GetBots(botNameTo); - if ((botsT == null) || (botsT.Count == 0)) { - return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameTo)) : null; - } - Bot botT = botsT.First(); - ulong targetSteamMasterID = botT.SteamID; + HashSet botsT = GetBots(botNameTo); + if ((botsT == null) || (botsT.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameTo)) : null; + } + Bot botT = botsT.First(); + ulong targetSteamMasterID = botT.SteamID; - if (targetSteamMasterID == SteamID) { - return FormatBotResponse(Strings.BotLootingYourself); - } + if (targetSteamMasterID == SteamID) { + return FormatBotResponse(Strings.BotLootingYourself); + } - if (!LootingSemaphore.Wait(0)) { - return FormatBotResponse(Strings.BotLootingFailed); - } + if (!LootingSemaphore.Wait(0)) { + return FormatBotResponse(Strings.BotLootingFailed); + } - try { - HashSet tmp = new HashSet(); - string[] modes = mode.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); - foreach (string singleMode in modes) { - switch (singleMode.ToUpper()) { - case "C": // Not sure about shortcuts. - case "CARD": - tmp.Add(Steam.Item.EType.TradingCard); - break; - case "F": - case "FOIL": - tmp.Add(Steam.Item.EType.FoilTradingCard); - break; - case "B": - case "BOOSTER": - tmp.Add(Steam.Item.EType.BoosterPack); - break; - case "E": - case "EMOTICON": - tmp.Add(Steam.Item.EType.Emoticon); - break; - case "BA": - case "BACKGROUND": - tmp.Add(Steam.Item.EType.ProfileBackground); - break; - case "U": - case "UNKNOWN": - tmp.Add(Steam.Item.EType.Unknown); - break; - case "G": - case "GEMS": - tmp.Add(Steam.Item.EType.SteamGems); - break; - case "EV": - case "EVERYTHING": - // Needs to be kept up to date, or is there an easy way for all types? - tmp.Add(Steam.Item.EType.TradingCard); - tmp.Add(Steam.Item.EType.FoilTradingCard); - tmp.Add(Steam.Item.EType.BoosterPack); - tmp.Add(Steam.Item.EType.Emoticon); - tmp.Add(Steam.Item.EType.ProfileBackground); - tmp.Add(Steam.Item.EType.Unknown); - tmp.Add(Steam.Item.EType.SteamGems); - break; - default: - // adjust error message - return "Unknown mode " + singleMode + "!"; - } - } + try { + HashSet tmp = new HashSet(); + string[] modes = mode.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); + foreach (string singleMode in modes) { + switch (singleMode.ToUpper()) { + case "C": // Not sure about shortcuts. + case "CARD": + tmp.Add(Steam.Item.EType.TradingCard); + break; + case "F": + case "FOIL": + tmp.Add(Steam.Item.EType.FoilTradingCard); + break; + case "B": + case "BOOSTER": + tmp.Add(Steam.Item.EType.BoosterPack); + break; + case "E": + case "EMOTICON": + tmp.Add(Steam.Item.EType.Emoticon); + break; + case "BA": + case "BACKGROUND": + tmp.Add(Steam.Item.EType.ProfileBackground); + break; + case "U": + case "UNKNOWN": + tmp.Add(Steam.Item.EType.Unknown); + break; + case "G": + case "GEMS": + tmp.Add(Steam.Item.EType.SteamGems); + break; + case "EV": + case "EVERYTHING": + // Needs to be kept up to date, or is there an easy way for all types? + tmp.Add(Steam.Item.EType.TradingCard); + tmp.Add(Steam.Item.EType.FoilTradingCard); + tmp.Add(Steam.Item.EType.BoosterPack); + tmp.Add(Steam.Item.EType.Emoticon); + tmp.Add(Steam.Item.EType.ProfileBackground); + tmp.Add(Steam.Item.EType.Unknown); + tmp.Add(Steam.Item.EType.SteamGems); + break; + default: + // adjust error message + return "Unknown mode " + singleMode + "!"; + } + } - HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, tmp).ConfigureAwait(false); - if ((inventory == null) || (inventory.Count == 0)) { - return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(inventory))); - } + HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, tmp).ConfigureAwait(false); + if ((inventory == null) || (inventory.Count == 0)) { + return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(inventory))); + } - if (!await ArchiWebHandler.MarkSentTrades().ConfigureAwait(false)) { - return FormatBotResponse(Strings.BotLootingFailed); - } + if (!await ArchiWebHandler.MarkSentTrades().ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } - if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { - return FormatBotResponse(Strings.BotLootingFailed); - } + if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } - if (HasMobileAuthenticator) { - // Give Steam network some time to generate confirmations - await Task.Delay(3000).ConfigureAwait(false); - if (!await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamMasterID).ConfigureAwait(false)) { - return FormatBotResponse(Strings.BotLootingFailed); - } - } - } finally { - LootingSemaphore.Release(); - } + if (HasMobileAuthenticator) { + // Give Steam network some time to generate confirmations + await Task.Delay(3000).ConfigureAwait(false); + if (!await AcceptConfirmations(true, Steam.ConfirmationDetails.EType.Trade, targetSteamMasterID).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + } + } finally { + LootingSemaphore.Release(); + } - return FormatBotResponse(Strings.BotLootingSuccess); - } + return FormatBotResponse(Strings.BotLootingSuccess); + } + private static async Task ResponseTransfer(ulong steamID, string botNameFrom, string mode, string botNameTo) { + //standard procedure adapted from loot + if ((steamID == 0) || string.IsNullOrEmpty(botNameFrom) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNameFrom) + " || " + nameof(mode) + " || " + nameof(botNameTo)); + return null; + } - private static async Task ResponseTransfer(ulong steamID, string botNameFrom, string mode, string botNameTo) { - //standard procedure adapted from loot - if ((steamID == 0) || string.IsNullOrEmpty(botNameFrom) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNameFrom) + " || " + nameof(mode) + " || " + nameof(botNameTo)); - return null; - } + HashSet botsF = GetBots(botNameFrom); + if ((botsF == null) || (botsF.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameFrom)) : null; + } - HashSet botsF = GetBots(botNameFrom); - if ((botsF == null) || (botsF.Count == 0)) { - return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameFrom)) : null; - } + IEnumerable> tasks = botsF.Select(bot => bot.ResponseTransfer(steamID, mode, botNameTo)); + ICollection results; - IEnumerable> tasks = botsF.Select(bot => bot.ResponseTransfer(steamID, mode, botNameTo)); - ICollection results; + switch (Program.GlobalConfig.OptimizationMode) { + case GlobalConfig.EOptimizationMode.MinMemoryUsage: + results = new List(botsF.Count); + foreach (Task task in tasks) { + results.Add(await task.ConfigureAwait(false)); + } - switch (Program.GlobalConfig.OptimizationMode) { - case GlobalConfig.EOptimizationMode.MinMemoryUsage: - results = new List(botsF.Count); - foreach (Task task in tasks) { - results.Add(await task.ConfigureAwait(false)); - } + break; + default: + results = await Task.WhenAll(tasks).ConfigureAwait(false); + break; + } - break; - default: - results = await Task.WhenAll(tasks).ConfigureAwait(false); - break; - } + List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); + return responses.Count > 0 ? string.Join("", responses) : null; + } - List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); - return responses.Count > 0 ? string.Join("", responses) : null; - } - - private string ResponseUnknown(ulong steamID) { + private string ResponseUnknown(ulong steamID) { if (steamID != 0) { return IsOperator(steamID) ? FormatBotResponse(Strings.UnknownCommand) : null; } From 52f5ef2a39c1a699eb7c812bdc023959fca8e5e0 Mon Sep 17 00:00:00 2001 From: Florian Lang Date: Sat, 12 Aug 2017 00:19:08 +0200 Subject: [PATCH 3/5] misc --- ArchiSteamFarm/Bot.cs | 69 +++++++++++++++++++++---------------------- 1 file changed, 33 insertions(+), 36 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 183395b33..85cc2f93e 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -803,7 +803,7 @@ namespace ArchiSteamFarm { if (args.Length > 2) { return await ResponseTransfer(steamID, args[1], args[2]).ConfigureAwait(false); } - return await ResponseTransfer(steamID).ConfigureAwait(false); + return ResponseUnknown(steamID); case "!API": return ResponseAPI(steamID, args[1]); case "!BL": @@ -3920,11 +3920,6 @@ namespace ArchiSteamFarm { return responses.Count > 0 ? string.Join("", responses) : null; } - private static async Task ResponseTransfer(ulong steamID) { - // modifie message / remove? - return "To less arguments"; - } - private async Task ResponseTransfer(ulong steamID, string mode, string botNameTo) { if ((steamID == 0) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(mode) + " || " + nameof(botNameTo)); @@ -3943,13 +3938,16 @@ namespace ArchiSteamFarm { if (!LootingAllowed) { return FormatBotResponse(Strings.BotLootingTemporarilyDisabled); } - - HashSet botsT = GetBots(botNameTo); - if ((botsT == null) || (botsT.Count == 0)) { + Bot botTo; + if(!Bots.TryGetValue(botNameTo, out botTo)) { return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameTo)) : null; } - Bot botT = botsT.First(); - ulong targetSteamMasterID = botT.SteamID; + + ulong targetSteamMasterID = botTo.SteamID; + + if (targetSteamMasterID==0) { + return FormatBotResponse(Strings.BotNotConnected); + } if (targetSteamMasterID == SteamID) { return FormatBotResponse(Strings.BotLootingYourself); @@ -3960,48 +3958,48 @@ namespace ArchiSteamFarm { } try { - HashSet tmp = new HashSet(); + HashSet transferTypes = new HashSet(); string[] modes = mode.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries); foreach (string singleMode in modes) { switch (singleMode.ToUpper()) { case "C": // Not sure about shortcuts. case "CARD": - tmp.Add(Steam.Item.EType.TradingCard); + transferTypes.Add(Steam.Item.EType.TradingCard); break; case "F": case "FOIL": - tmp.Add(Steam.Item.EType.FoilTradingCard); + transferTypes.Add(Steam.Item.EType.FoilTradingCard); break; case "B": case "BOOSTER": - tmp.Add(Steam.Item.EType.BoosterPack); + transferTypes.Add(Steam.Item.EType.BoosterPack); break; case "E": case "EMOTICON": - tmp.Add(Steam.Item.EType.Emoticon); + transferTypes.Add(Steam.Item.EType.Emoticon); break; case "BA": case "BACKGROUND": - tmp.Add(Steam.Item.EType.ProfileBackground); + transferTypes.Add(Steam.Item.EType.ProfileBackground); break; case "U": case "UNKNOWN": - tmp.Add(Steam.Item.EType.Unknown); + transferTypes.Add(Steam.Item.EType.Unknown); break; case "G": case "GEMS": - tmp.Add(Steam.Item.EType.SteamGems); + transferTypes.Add(Steam.Item.EType.SteamGems); break; case "EV": case "EVERYTHING": // Needs to be kept up to date, or is there an easy way for all types? - tmp.Add(Steam.Item.EType.TradingCard); - tmp.Add(Steam.Item.EType.FoilTradingCard); - tmp.Add(Steam.Item.EType.BoosterPack); - tmp.Add(Steam.Item.EType.Emoticon); - tmp.Add(Steam.Item.EType.ProfileBackground); - tmp.Add(Steam.Item.EType.Unknown); - tmp.Add(Steam.Item.EType.SteamGems); + transferTypes.Add(Steam.Item.EType.TradingCard); + transferTypes.Add(Steam.Item.EType.FoilTradingCard); + transferTypes.Add(Steam.Item.EType.BoosterPack); + transferTypes.Add(Steam.Item.EType.Emoticon); + transferTypes.Add(Steam.Item.EType.ProfileBackground); + transferTypes.Add(Steam.Item.EType.Unknown); + transferTypes.Add(Steam.Item.EType.SteamGems); break; default: // adjust error message @@ -4009,7 +4007,7 @@ namespace ArchiSteamFarm { } } - HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, tmp).ConfigureAwait(false); + HashSet inventory = await ArchiWebHandler.GetMySteamInventory(true, transferTypes).ConfigureAwait(false); if ((inventory == null) || (inventory.Count == 0)) { return FormatBotResponse(string.Format(Strings.ErrorIsEmpty, nameof(inventory))); } @@ -4036,28 +4034,27 @@ namespace ArchiSteamFarm { return FormatBotResponse(Strings.BotLootingSuccess); } - private static async Task ResponseTransfer(ulong steamID, string botNameFrom, string mode, string botNameTo) { + private static async Task ResponseTransfer(ulong steamID, string botNames, string mode, string botNameTo) { //standard procedure adapted from loot - if ((steamID == 0) || string.IsNullOrEmpty(botNameFrom) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { - ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNameFrom) + " || " + nameof(mode) + " || " + nameof(botNameTo)); + if ((steamID == 0) || string.IsNullOrEmpty(botNames) || string.IsNullOrEmpty(botNameTo) || string.IsNullOrEmpty(mode)) { + ASF.ArchiLogger.LogNullError(nameof(steamID) + " || " + nameof(botNames) + " || " + nameof(mode) + " || " + nameof(botNameTo)); return null; } - HashSet botsF = GetBots(botNameFrom); - if ((botsF == null) || (botsF.Count == 0)) { - return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNameFrom)) : null; + HashSet bots = GetBots(botNames); + if ((bots == null) || (bots.Count == 0)) { + return IsOwner(steamID) ? FormatStaticResponse(string.Format(Strings.BotNotFound, botNames)) : null; } - IEnumerable> tasks = botsF.Select(bot => bot.ResponseTransfer(steamID, mode, botNameTo)); + IEnumerable> tasks = bots.Select(bot => bot.ResponseTransfer(steamID, mode, botNameTo)); ICollection results; switch (Program.GlobalConfig.OptimizationMode) { case GlobalConfig.EOptimizationMode.MinMemoryUsage: - results = new List(botsF.Count); + results = new List(bots.Count); foreach (Task task in tasks) { results.Add(await task.ConfigureAwait(false)); } - break; default: results = await Task.WhenAll(tasks).ConfigureAwait(false); From 6a6c903d7d63a319a5daf34ad1804565fd827d20 Mon Sep 17 00:00:00 2001 From: Florian Lang Date: Sat, 12 Aug 2017 00:31:51 +0200 Subject: [PATCH 4/5] tradetoken --- ArchiSteamFarm/Bot.cs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 85cc2f93e..b02018fc9 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -4016,8 +4016,20 @@ namespace ArchiSteamFarm { return FormatBotResponse(Strings.BotLootingFailed); } - if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, BotConfig.SteamTradeToken).ConfigureAwait(false)) { - return FormatBotResponse(Strings.BotLootingFailed); + if (SteamFriends.GetFriendRelationship(targetSteamMasterID)== EFriendRelationship.Friend) { + if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } + } else { + + string tradeToken; + if (string.IsNullOrEmpty(tradeToken = await botTo.ArchiWebHandler.GetTradeToken().ConfigureAwait(false))){ + return FormatBotResponse(Strings.BotLootingFailed); // or is there a specific error? + } + + if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, tradeToken).ConfigureAwait(false)) { + return FormatBotResponse(Strings.BotLootingFailed); + } } if (HasMobileAuthenticator) { From 5d443f3ed2ec688e84ef34ba3c2cdd1029b2a923 Mon Sep 17 00:00:00 2001 From: Florian Lang Date: Sat, 12 Aug 2017 00:45:05 +0200 Subject: [PATCH 5/5] simplified --- ArchiSteamFarm/Bot.cs | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index b02018fc9..1812e39fa 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -4016,20 +4016,13 @@ namespace ArchiSteamFarm { return FormatBotResponse(Strings.BotLootingFailed); } - if (SteamFriends.GetFriendRelationship(targetSteamMasterID)== EFriendRelationship.Friend) { - if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID).ConfigureAwait(false)) { - return FormatBotResponse(Strings.BotLootingFailed); - } - } else { - - string tradeToken; - if (string.IsNullOrEmpty(tradeToken = await botTo.ArchiWebHandler.GetTradeToken().ConfigureAwait(false))){ + string tradeToken = null; + if (!(SteamFriends.GetFriendRelationship(targetSteamMasterID)== EFriendRelationship.Friend) && string.IsNullOrEmpty(tradeToken = await botTo.ArchiWebHandler.GetTradeToken().ConfigureAwait(false))) { return FormatBotResponse(Strings.BotLootingFailed); // or is there a specific error? - } + } - if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, tradeToken).ConfigureAwait(false)) { + if (!await ArchiWebHandler.SendTradeOffer(inventory, targetSteamMasterID, tradeToken).ConfigureAwait(false)) { return FormatBotResponse(Strings.BotLootingFailed); - } } if (HasMobileAuthenticator) {