diff --git a/ArchiSteamFarm/Actions.cs b/ArchiSteamFarm/Actions.cs index 541dba702..e1376a043 100644 --- a/ArchiSteamFarm/Actions.cs +++ b/ArchiSteamFarm/Actions.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Generic; +using System.Diagnostics.CodeAnalysis; using System.Linq; using System.Threading; using System.Threading.Tasks; @@ -202,7 +203,8 @@ namespace ArchiSteamFarm { } [PublicAPI] - public async Task<(bool Success, string Message)> SendTradeOffer(uint appID = Steam.Asset.SteamAppID, uint contextID = Steam.Asset.SteamCommunityContextID, ulong targetSteamID = 0, IReadOnlyCollection wantedRealAppIDs = null, IReadOnlyCollection wantedTypes = null) { + [SuppressMessage("ReSharper", "FunctionComplexityOverflow")] + public async Task<(bool Success, string Message)> SendTradeOffer(uint appID = Steam.Asset.SteamAppID, uint contextID = Steam.Asset.SteamCommunityContextID, ulong targetSteamID = 0, string tradeToken = null, IReadOnlyCollection wantedRealAppIDs = null, IReadOnlyCollection wantedTypes = null) { if ((appID == 0) || (contextID == 0)) { Bot.ArchiLogger.LogNullError(nameof(appID) + " || " + nameof(contextID)); @@ -219,12 +221,24 @@ namespace ArchiSteamFarm { if (targetSteamID == 0) { return (false, Strings.BotLootingMasterNotDefined); } + + if (!string.IsNullOrEmpty(Bot.BotConfig.SteamTradeToken)) { + tradeToken = Bot.BotConfig.SteamTradeToken; + } } if (targetSteamID == Bot.SteamID) { return (false, Strings.BotSendingTradeToYourself); } + if (string.IsNullOrEmpty(tradeToken) && (Bot.SteamFriends.GetFriendRelationship(targetSteamID) != EFriendRelationship.Friend)) { + Bot targetBot = Bot.Bots.Values.FirstOrDefault(bot => bot.SteamID == targetSteamID); + + if (targetBot?.IsConnectedAndLoggedOn == true) { + tradeToken = await targetBot.ArchiHandler.GetTradeToken().ConfigureAwait(false); + } + } + lock (TradingSemaphore) { if (TradingScheduled) { return (false, Strings.ErrorAborted); @@ -250,7 +264,7 @@ namespace ArchiSteamFarm { return (false, Strings.BotLootingFailed); } - (bool success, HashSet mobileTradeOfferIDs) = await Bot.ArchiWebHandler.SendTradeOffer(targetSteamID, inventory, token: Bot.BotConfig.SteamTradeToken).ConfigureAwait(false); + (bool success, HashSet mobileTradeOfferIDs) = await Bot.ArchiWebHandler.SendTradeOffer(targetSteamID, inventory, token: tradeToken).ConfigureAwait(false); if ((mobileTradeOfferIDs != null) && (mobileTradeOfferIDs.Count > 0) && Bot.HasMobileAuthenticator) { (bool twoFactorSuccess, _) = await HandleTwoFactorAuthenticationConfirmations(true, Steam.ConfirmationDetails.EType.Trade, mobileTradeOfferIDs, true).ConfigureAwait(false); diff --git a/ArchiSteamFarm/Bot.cs b/ArchiSteamFarm/Bot.cs index 383bf066c..00a629343 100755 --- a/ArchiSteamFarm/Bot.cs +++ b/ArchiSteamFarm/Bot.cs @@ -377,7 +377,7 @@ namespace ArchiSteamFarm { Bot targetBot = Bots.Values.FirstOrDefault(bot => bot.SteamID == steamID); - if (targetBot != null) { + if (targetBot?.IsConnectedAndLoggedOn == true) { string targetTradeToken = await targetBot.ArchiHandler.GetTradeToken().ConfigureAwait(false); if (!string.IsNullOrEmpty(targetTradeToken)) {