Skip to content

Commit ac10f32

Browse files
committed
Forward ArchiBoT logic of trade holds for steam sale cards
1 parent 5d7e029 commit ac10f32

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

ArchiSteamFarm/ArchiWebHandler.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,57 @@ internal Dictionary<uint, string> GetOwnedGames(ulong steamID) {
325325
return result;
326326
}
327327

328+
internal async Task<byte?> GetTradeHoldDuration(ulong tradeID) {
329+
if (tradeID == 0) {
330+
Logging.LogNullError(nameof(tradeID), Bot.BotName);
331+
return null;
332+
}
333+
334+
string request = SteamCommunityURL + "/tradeoffer/" + tradeID;
335+
336+
HtmlDocument htmlDocument = await WebBrowser.UrlGetToHtmlDocumentRetry(request).ConfigureAwait(false);
337+
if (htmlDocument == null) {
338+
return null;
339+
}
340+
341+
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='pagecontent']/script");
342+
if (htmlNode == null) {
343+
Logging.LogNullError(nameof(htmlNode), Bot.BotName);
344+
return null;
345+
}
346+
347+
string text = htmlNode.InnerText;
348+
if (string.IsNullOrEmpty(text)) {
349+
Logging.LogNullError(nameof(text), Bot.BotName);
350+
return null;
351+
}
352+
353+
int index = text.IndexOf("g_daysTheirEscrow = ", StringComparison.Ordinal);
354+
if (index < 0) {
355+
Logging.LogNullError(nameof(index), Bot.BotName);
356+
return null;
357+
}
358+
359+
index += 20;
360+
text = text.Substring(index);
361+
362+
index = text.IndexOf(';');
363+
if (index < 0) {
364+
Logging.LogNullError(nameof(index), Bot.BotName);
365+
return null;
366+
}
367+
368+
text = text.Substring(0, index);
369+
370+
byte holdDuration;
371+
if (byte.TryParse(text, out holdDuration)) {
372+
return holdDuration;
373+
}
374+
375+
Logging.LogNullError(nameof(holdDuration), Bot.BotName);
376+
return null;
377+
}
378+
328379
internal HashSet<Steam.TradeOffer> GetTradeOffers() {
329380
if (string.IsNullOrEmpty(Bot.BotConfig.SteamApiKey)) {
330381
// TODO: Correct this when Mono 4.4+ will be a latest stable one | https://bugzilla.xamarin.com/show_bug.cgi?id=39455

ArchiSteamFarm/Trading.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,15 @@ private async Task<bool> ShouldAcceptTrade(Steam.TradeOffer tradeOffer) {
152152
}
153153

154154
// At this point we're sure that STM trade is valid
155+
156+
// If we're dealing with special cards with short lifespan, accept the trade only if user doesn't have trade holds
157+
if (tradeOffer.ItemsToGive.Any(item => GlobalConfig.GlobalBlacklist.Contains(item.RealAppID))) {
158+
byte? holdDuration = await Bot.ArchiWebHandler.GetTradeHoldDuration(tradeOffer.TradeOfferID).ConfigureAwait(false);
159+
if (holdDuration.GetValueOrDefault() > 0) {
160+
return false;
161+
}
162+
}
163+
155164
// Now check if it's worth for us to do the trade
156165
HashSet<Steam.Item> inventory = await Bot.ArchiWebHandler.GetMyInventory(false).ConfigureAwait(false);
157166
if ((inventory == null) || (inventory.Count == 0)) {

0 commit comments

Comments
 (0)