Forward ArchiBoT logic of trade holds for steam sale cards

This commit is contained in:
JustArchi
2016-06-12 02:18:18 +02:00
parent 5d7e0290d7
commit ac10f32431
2 changed files with 60 additions and 0 deletions

View File

@@ -325,6 +325,57 @@ namespace ArchiSteamFarm {
return result;
}
internal async Task<byte?> 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<Steam.TradeOffer> 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

View File

@@ -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<Steam.Item> inventory = await Bot.ArchiWebHandler.GetMyInventory(false).ConfigureAwait(false);
if ((inventory == null) || (inventory.Count == 0)) {