Cleanup old winter sale code

This commit is contained in:
JustArchi
2017-06-03 18:59:22 +02:00
parent 76a98c09e8
commit a09271ae3e
4 changed files with 14 additions and 149 deletions

View File

@@ -22,7 +22,6 @@
*/
/*
using System;
using System.Collections.Generic;
using System.Threading;
@@ -31,53 +30,34 @@ using HtmlAgilityPack;
namespace ArchiSteamFarm {
internal sealed class SteamSaleEvent : IDisposable {
private static readonly DateTime SaleEndingDateUtc = new DateTime(2017, 1, 2, 18, 0, 0, DateTimeKind.Utc);
private readonly Bot Bot;
private readonly Timer SteamAwardsTimer;
private readonly Timer SteamDiscoveryQueueTimer;
internal SteamSaleEvent(Bot bot) {
if (bot == null) {
throw new ArgumentNullException(nameof(bot));
}
Bot = bot ?? throw new ArgumentNullException(nameof(bot));
Bot = bot;
if (DateTime.UtcNow >= SaleEndingDateUtc) {
if (!Debugging.IsDebugBuild) {
return;
}
SteamAwardsTimer = new Timer(
async e => await VoteForSteamAwards().ConfigureAwait(false),
null,
TimeSpan.FromMinutes(1 + 0.2 * Bot.Bots.Count), // Delay
TimeSpan.FromHours(6.1) // Period
);
SteamDiscoveryQueueTimer = new Timer(
async e => await ExploreDiscoveryQueue().ConfigureAwait(false),
null,
TimeSpan.FromMinutes(1 + 0.2 * Bot.Bots.Count), // Delay
TimeSpan.FromHours(6.1) // Period
TimeSpan.FromHours(8.1) // Period
);
}
public void Dispose() {
SteamAwardsTimer?.Dispose();
SteamDiscoveryQueueTimer?.Dispose();
}
private async Task ExploreDiscoveryQueue() {
if (DateTime.UtcNow >= SaleEndingDateUtc) {
if (!Bot.IsConnectedAndLoggedOn) {
return;
}
if (!Bot.ArchiWebHandler.Ready) {
return;
}
for (byte i = 0; (i < 3) && !(await IsDiscoveryQueueEmpty().ConfigureAwait(false)).GetValueOrDefault(); i++) {
for (byte i = 0; (i < 3) && (await IsDiscoveryQueueAvailable().ConfigureAwait(false)).GetValueOrDefault(); i++) {
HashSet<uint> queue = await Bot.ArchiWebHandler.GenerateNewDiscoveryQueue().ConfigureAwait(false);
if (queue == null) {
break;
@@ -95,11 +75,7 @@ namespace ArchiSteamFarm {
}
}
private async Task<bool?> IsDiscoveryQueueEmpty() {
if (!Bot.ArchiWebHandler.Ready) {
return null;
}
private async Task<bool?> IsDiscoveryQueueAvailable() {
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetDiscoveryQueuePage().ConfigureAwait(false);
if (htmlDocument == null) {
return null;
@@ -107,81 +83,18 @@ namespace ArchiSteamFarm {
HtmlNode htmlNode = htmlDocument.DocumentNode.SelectSingleNode("//div[@class='subtext']");
if (htmlNode == null) {
// No cards for exploring the queue available
return true;
// Valid, no cards for exploring the queue available
return false;
}
string text = htmlNode.InnerText;
if (!string.IsNullOrEmpty(text)) {
// It'd make more sense to check "Come back tomorrow", but it might not cover out-of-the-event queue
return !text.StartsWith("You can get ", StringComparison.Ordinal);
// 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);
}
Bot.ArchiLogger.LogNullError(nameof(text));
return null;
}
private async Task VoteForSteamAwards() {
if (DateTime.UtcNow >= SaleEndingDateUtc) {
return;
}
if (!Bot.ArchiWebHandler.Ready) {
return;
}
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetSteamAwardsPage().ConfigureAwait(false);
HtmlNodeCollection nominationsNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='vote_nominations store_horizontal_autoslider']");
if (nominationsNodes == null) {
// Event ended, error or likewise
return;
}
foreach (HtmlNode nominationsNode in nominationsNodes) {
HtmlNode myVoteNode = nominationsNode.SelectSingleNode("./div[@class='vote_nomination your_vote']");
if (myVoteNode != null) {
// Already voted
continue;
}
string voteIDText = nominationsNode.GetAttributeValue("data-voteid", null);
if (string.IsNullOrEmpty(voteIDText)) {
Bot.ArchiLogger.LogNullError(nameof(voteIDText));
return;
}
byte voteID;
if (!byte.TryParse(voteIDText, out voteID) || (voteID == 0)) {
Bot.ArchiLogger.LogNullError(nameof(voteID));
return;
}
HtmlNodeCollection voteNodes = nominationsNode.SelectNodes("./div[@class='vote_nomination ']");
if (voteNodes == null) {
Bot.ArchiLogger.LogNullError(nameof(voteNodes));
return;
}
// Random a game we'll actually vote for, we don't want to make GabeN angry by rigging votes...
HtmlNode voteNode = voteNodes[Utilities.RandomNext(voteNodes.Count)];
string appIDText = voteNode.GetAttributeValue("data-vote-appid", null);
if (string.IsNullOrEmpty(appIDText)) {
Bot.ArchiLogger.LogNullError(nameof(appIDText));
return;
}
uint appID;
if (!uint.TryParse(appIDText, out appID) || (appID == 0)) {
Bot.ArchiLogger.LogNullError(nameof(appID));
return;
}
await Bot.ArchiWebHandler.SteamAwardsVote(voteID, appID).ConfigureAwait(false);
}
}
}
}
*/
}