diff --git a/ArchiSteamFarm/ArchiWebHandler.cs b/ArchiSteamFarm/ArchiWebHandler.cs index 049c8c40a..747d99ab5 100644 --- a/ArchiSteamFarm/ArchiWebHandler.cs +++ b/ArchiSteamFarm/ArchiWebHandler.cs @@ -325,6 +325,57 @@ namespace ArchiSteamFarm { return result; } + internal async Task GetTradeHoldDuration(ulong tradeID) { + if (tradeID == 0) { + Logging.LogNullError(nameof(tradeID), Bot.BotName); + return null; + } + + string request = SteamCommunityURL + "/tradeoffer/" + tradeID; + + HtmlDocument htmlDocument = await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false); + if (htmlDocument == null) { + return null; + } + + HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='pagecontent']/script"); + if (htmlNode == null) { + Logging.LogNullError(nameof(htmlNode), Bot.BotName); + return null; + } + + string text = htmlNode.InnerText; + if (string.IsNullOrEmpty(text)) { + Logging.LogNullError(nameof(text), Bot.BotName); + return null; + } + + int index = text.IndexOf("g_daysTheirEscrow = ", StringComparison.Ordinal); + if (index < 0) { + Logging.LogNullError(nameof(index), Bot.BotName); + return null; + } + + index += 20; + text = text.Substring(index); + + index = text.IndexOf(';'); + if (index < 0) { + Logging.LogNullError(nameof(index), Bot.BotName); + return null; + } + + text = text.Substring(0, index); + + byte holdDuration; + if (byte.TryParse(text, out holdDuration)) { + return holdDuration; + } + + Logging.LogNullError(nameof(holdDuration), Bot.BotName); + return null; + } + internal HashSet GetTradeOffers() { if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) { // TODO: Correct this when Mono 4.4+ will be a latest stable one | https://bugzilla.xamarin.com/show_bug.cgi?id=39455 diff --git a/ArchiSteamFarm/Trading.cs b/ArchiSteamFarm/Trading.cs index 181ccfd50..854f64a17 100644 --- a/ArchiSteamFarm/Trading.cs +++ b/ArchiSteamFarm/Trading.cs @@ -152,6 +152,15 @@ namespace ArchiSteamFarm { } // At this point we're sure that STM trade is valid + + // If we're dealing with special cards with short lifespan, accept the trade only if user doesn't have trade holds + if (tradeOffer.ItemsToGive.Any(item => GlobalConfig.GlobalBlacklist.Contains(item.RealAppID))) { + byte? holdDuration = await Bot.ArchiWebHandler.GetTradeHoldDuration(tradeOffer.TradeOfferID).ConfigureAwait(false); + if (holdDuration.GetValueOrDefault() > 0) { + return false; + } + } + // Now check if it's worth for us to do the trade HashSet inventory = await Bot.ArchiWebHandler.GetMyInventory(false).ConfigureAwait(false); if ((inventory == null) || (inventory.Count == 0)) {