From ac427ed1ec613d11ed17cf4ba75068161ed8e904 Mon Sep 17 00:00:00 2001 From: Archi Date: Mon, 1 Jan 2024 22:58:54 +0100 Subject: [PATCH] Misc match improvements --- .../Commands.cs | 14 +++++++++++--- .../RemoteCommunication.cs | 15 ++------------- 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs index 8807684b4..07e2a0910 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs @@ -80,15 +80,23 @@ internal static class Commands { return access > EAccess.None ? bot.Commands.FormatBotResponse(Strings.ErrorAccessDenied) : null; } + if (!bot.IsConnectedAndLoggedOn) { + return bot.Commands.FormatBotResponse(Strings.BotNotConnected); + } + + if (bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchEverything)) { + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(BotConfig.ETradingPreferences.MatchEverything))); + } + if ((ASF.GlobalConfig?.LicenseID == null) || (ASF.GlobalConfig.LicenseID == Guid.Empty)) { return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(ASF.GlobalConfig.LicenseID))); } - if (!bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchActively) || !ItemsMatcherPlugin.RemoteCommunications.TryGetValue(bot, out RemoteCommunication? remoteCommunication)) { - return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(BotConfig.ETradingPreferences.MatchActively))); + if (!ItemsMatcherPlugin.RemoteCommunications.TryGetValue(bot, out RemoteCommunication? remoteCommunication)) { + return bot.Commands.FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(remoteCommunication))); } - remoteCommunication.TriggerMatchActivelyEarlier(); + remoteCommunication.TriggerMatchActively(); return bot.Commands.FormatBotResponse(Strings.Done); } diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index 73bdb3072..cfde0cd96 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -771,16 +771,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } - internal void TriggerMatchActivelyEarlier() { - if (MatchActivelyTimer == null) { - throw new InvalidOperationException(nameof(MatchActivelyTimer)); - } - - // ReSharper disable once SuspiciousLockOverSynchronizationPrimitive - this is not a mistake, we need extra synchronization, and we can re-use the semaphore object for that - lock (MatchActivelySemaphore) { - MatchActivelyTimer.Change(TimeSpan.Zero, TimeSpan.FromHours(6)); - } - } + internal void TriggerMatchActively() => Utilities.InBackground(() => MatchActively()); private async Task IsEligibleForListing() { // Bot must be eligible for matching @@ -881,7 +872,7 @@ 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)) { + if (!Bot.IsConnectedAndLoggedOn || Bot.BotConfig.TradingPreferences.HasFlag(BotConfig.ETradingPreferences.MatchEverything)) { Bot.ArchiLogger.LogGenericTrace(Strings.ErrorAborted); return; @@ -1131,8 +1122,6 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { #pragma warning disable CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose using (await Bot.Actions.GetTradingLock().ConfigureAwait(false)) { #pragma warning restore CA2000 // False positive, we're actually wrapping it in the using clause below exactly for that purpose - Bot.ArchiLogger.LogGenericInfo(Strings.Starting); - tradesSent = await MatchActively(response.Value.Users, assetsForMatching, acceptedMatchableTypes).ConfigureAwait(false); }