I like my Steam account

This commit is contained in:
JustArchi
2016-12-23 03:37:29 +01:00
parent e3f87e4a19
commit 6038faaa5f
2 changed files with 22 additions and 2 deletions

View File

@@ -118,8 +118,8 @@ namespace ArchiSteamFarm {
Bot.ArchiLogger.LogGenericDebug("Getting SteamAwards page...");
HtmlDocument htmlDocument = await Bot.ArchiWebHandler.GetSteamAwardsPage().ConfigureAwait(false);
HtmlNode voteNode = htmlDocument?.DocumentNode.SelectSingleNode("//div[@class='vote_nomination ']");
if (voteNode == null) {
HtmlNodeCollection voteNodes = htmlDocument?.DocumentNode.SelectNodes("//div[@class='vote_nomination ']");
if (voteNodes == null) {
// Event ended, error or likewise
Bot.ArchiLogger.LogGenericDebug("Could not get SteamAwards page, returning");
return;
@@ -150,6 +150,9 @@ namespace ArchiSteamFarm {
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));

View File

@@ -30,6 +30,8 @@ using System.Runtime.CompilerServices;
namespace ArchiSteamFarm {
internal static class Utilities {
private static readonly Random Random = new Random();
[MethodImpl(MethodImplOptions.AggressiveInlining)]
[SuppressMessage("ReSharper", "UnusedParameter.Global")]
internal static void Forget(this object obj) { }
@@ -54,5 +56,20 @@ namespace ArchiSteamFarm {
}
internal static uint GetUnixTime() => (uint) DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds;
internal static int RandomNext(int maxWithout) {
if (maxWithout <= 0) {
ASF.ArchiLogger.LogNullError(nameof(maxWithout));
return -1;
}
if (maxWithout == 1) {
return 0;
}
lock (Random) {
return Random.Next(maxWithout);
}
}
}
}