Finish first automatic implementation of SteamSaleEvent

This commit is contained in:
JustArchi
2017-06-23 21:04:51 +02:00
parent bdf1e91bb3
commit 2c2c365cd2
3 changed files with 41 additions and 13 deletions

View File

@@ -708,6 +708,15 @@ namespace ArchiSteamFarm.Localization {
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Clearing Steam discovery queue #{0}....
/// </summary>
internal static string ClearingDiscoveryQueue {
get {
return ResourceManager.GetString("ClearingDiscoveryQueue", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Content:
///{0}.
@@ -727,6 +736,15 @@ namespace ArchiSteamFarm.Localization {
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Done clearing Steam discovery queue #{0}..
/// </summary>
internal static string DoneClearingDiscoveryQueue {
get {
return ResourceManager.GetString("DoneClearingDiscoveryQueue", resourceCulture);
}
}
/// <summary>
/// Wyszukuje zlokalizowany ciąg podobny do ciągu Access denied!.
/// </summary>

View File

@@ -695,4 +695,12 @@ StackTrace:
<value>Current memory usage: {0} MB.</value>
<comment>{0} will be replaced by number (in megabytes) of memory being used</comment>
</data>
<data name="ClearingDiscoveryQueue" xml:space="preserve">
<value>Clearing Steam discovery queue #{0}...</value>
<comment>{0} will be replaced by queue number</comment>
</data>
<data name="DoneClearingDiscoveryQueue" xml:space="preserve">
<value>Done clearing Steam discovery queue #{0}.</value>
<comment>{0} will be replaced by queue number</comment>
</data>
</root>

View File

@@ -26,11 +26,12 @@ using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using ArchiSteamFarm.Localization;
using HtmlAgilityPack;
namespace ArchiSteamFarm {
internal sealed class SteamSaleEvent : IDisposable {
private const byte MaxSingleQueuesDaily = 3;
private const byte MaxSingleQueuesDaily = 3; // This is mainly a pre-caution for infinite queue clearing
private readonly Bot Bot;
private readonly Timer SteamDiscoveryQueueTimer;
@@ -38,10 +39,6 @@ namespace ArchiSteamFarm {
internal SteamSaleEvent(Bot bot) {
Bot = bot ?? throw new ArgumentNullException(nameof(bot));
if (!Debugging.IsDebugBuild) {
return;
}
SteamDiscoveryQueueTimer = new Timer(
async e => await ExploreDiscoveryQueue().ConfigureAwait(false),
null,
@@ -61,19 +58,23 @@ namespace ArchiSteamFarm {
for (byte i = 0; (i < MaxSingleQueuesDaily) && (await IsDiscoveryQueueAvailable().ConfigureAwait(false)).GetValueOrDefault(); i++) {
HashSet<uint> queue = await Bot.ArchiWebHandler.GenerateNewDiscoveryQueue().ConfigureAwait(false);
if (queue == null) {
if ((queue == null) || (queue.Count == 0)) {
break;
}
Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.ClearingDiscoveryQueue, i));
// We could in theory do this in parallel, but who knows what would happen...
foreach (uint queuedAppID in queue) {
if (await Bot.ArchiWebHandler.ClearFromDiscoveryQueue(queuedAppID).ConfigureAwait(false)) {
continue;
}
i = MaxSingleQueuesDaily;
break;
Bot.ArchiLogger.LogGenericWarning(Strings.WarningFailed);
return;
}
Bot.ArchiLogger.LogGenericInfo(string.Format(Strings.DoneClearingDiscoveryQueue, i));
}
}
@@ -90,13 +91,14 @@ namespace ArchiSteamFarm {
}
string text = htmlNode.InnerText;
if (!string.IsNullOrEmpty(text)) {
// It'd make more sense to check against "Come back tomorrow", but it might not cover out-of-the-event queue
return text.StartsWith("You can get ", StringComparison.Ordinal);
if (string.IsNullOrEmpty(text)) {
Bot.ArchiLogger.LogNullError(nameof(text));
return null;
}
Bot.ArchiLogger.LogNullError(nameof(text));
return null;
// It'd make more sense to check against "Come back tomorrow", but it might not cover out-of-the-event queue
bool result = text.StartsWith("You can get ", StringComparison.Ordinal);
return result;
}
}
}