From f41d6d53a66c480be6b51b38c8c5b92e0b97e7be Mon Sep 17 00:00:00 2001 From: Archi Date: Thu, 29 Dec 2022 22:25:35 +0100 Subject: [PATCH] Report warning on listing/matching If user intentionally enabled STM or MatchActively, we should display him warning if that's not possible due to not meeting the requirements. --- .../RemoteCommunication.cs | 33 +++++++++++-------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 4bf6d8647..a13f8d2c8 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -147,14 +147,14 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { internal void OnNewItemsNotification() => ShouldSendAnnouncementEarlier = true; internal async Task OnPersonaState(string? nickname = null, string? avatarHash = null) { - if (!Bot.BotConfig.RemoteCommunication.HasFlag(BotConfig.ERemoteCommunication.PublicListing)) { - return; - } - if (WebBrowser == null) { throw new InvalidOperationException(nameof(WebBrowser)); } + if (!Bot.BotConfig.RemoteCommunication.HasFlag(BotConfig.ERemoteCommunication.PublicListing) || !Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.SteamTradeMatcher)) { + return; + } + if ((DateTime.UtcNow < LastAnnouncement.AddMinutes(ShouldSendAnnouncementEarlier ? MinAnnouncementTTL : MaxAnnouncementTTL)) && ShouldSendHeartBeats) { return; } @@ -173,6 +173,8 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { // This is actually network failure, so we'll stop sending heartbeats but not record it as valid check ShouldSendHeartBeats = false; + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{nameof(IsEligibleForListing)}: {eligible?.ToString() ?? "null"}")); + return; } @@ -181,6 +183,8 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { LastAnnouncement = DateTime.UtcNow; ShouldSendAnnouncementEarlier = ShouldSendHeartBeats = false; + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{nameof(IsEligibleForListing)}: {eligible.Value}")); + return; } @@ -396,21 +400,14 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } private async Task IsEligibleForListing() { - // Bot must be eligible for matching first + // Bot must be eligible for matching bool? isEligibleForMatching = await IsEligibleForMatching().ConfigureAwait(false); if (isEligibleForMatching != true) { return isEligibleForMatching; } - // Bot must have STM enabled in TradingPreferences - if (!Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.SteamTradeMatcher)) { - Bot.ArchiLogger.LogGenericTrace(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{nameof(Bot.BotConfig.TradingPreferences)}: {Bot.BotConfig.TradingPreferences}")); - - return false; - } - - // Bot must have public inventory + // Bot must have a public inventory bool? hasPublicInventory = await Bot.HasPublicInventory().ConfigureAwait(false); if (hasPublicInventory != true) { @@ -462,12 +459,20 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { throw new InvalidOperationException(nameof(ASF.GlobalConfig.LicenseID)); } - if (!Bot.IsConnectedAndLoggedOn || Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchEverything) || !Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchActively) || (await IsEligibleForMatching().ConfigureAwait(false) != true)) { + if (!Bot.IsConnectedAndLoggedOn || Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchEverything) || !Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchActively)) { Bot.ArchiLogger.LogGenericTrace(Strings.ErrorAborted); return; } + bool? eligible = await IsEligibleForMatching().ConfigureAwait(false); + + if (eligible != true) { + Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, $"{nameof(IsEligibleForMatching)}: {eligible?.ToString() ?? "null"}")); + + return; + } + HashSet acceptedMatchableTypes = Bot.BotConfig.MatchableTypes.Where(AcceptedMatchableTypes.Contains).ToHashSet(); if (acceptedMatchableTypes.Count == 0) {