From ebaa13ae11ecff195963a3664561616cea373330 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Wed, 28 Sep 2022 18:55:19 -0400 Subject: [PATCH] Cleanup ChatManager --- .../Components/Chat/ChatManager.cs | 39 +++++++------------ .../Components/Chat/ChatManagerFactory.cs | 12 ------ .../Components/Chat/IChatManagerFactory.cs | 4 +- .../Components/InstanceFactory.cs | 2 +- 4 files changed, 17 insertions(+), 40 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs index 7bc5052f60..bcb4f19dd5 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs @@ -14,7 +14,6 @@ using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Chat.Providers; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Extensions; -using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Chat { @@ -33,11 +32,6 @@ namespace Tgstation.Server.Host.Components.Chat /// readonly IProviderFactory providerFactory; - /// - /// The for the . - /// - readonly IIOManager ioManager; - /// /// The for the . /// @@ -48,11 +42,6 @@ namespace Tgstation.Server.Host.Components.Chat /// readonly IRestartRegistration restartRegistration; - /// - /// The for the . - /// - readonly IAsyncDelayer asyncDelayer; - /// /// The for the . /// @@ -137,21 +126,23 @@ namespace Tgstation.Server.Host.Components.Chat /// Initializes a new instance of the class. /// /// The value of . - /// The value of . /// The value of . /// The to populate with. - /// The value of . /// The value of . /// The value of . /// The used to populate . - public ChatManager(IProviderFactory providerFactory, IIOManager ioManager, ICommandFactory commandFactory, IServerControl serverControl, IAsyncDelayer asyncDelayer, ILoggerFactory loggerFactory, ILogger logger, IEnumerable initialChatBots) + public ChatManager( + IProviderFactory providerFactory, + ICommandFactory commandFactory, + IServerControl serverControl, + ILoggerFactory loggerFactory, + ILogger logger, + IEnumerable initialChatBots) { this.providerFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory)); - this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager)); this.commandFactory = commandFactory ?? throw new ArgumentNullException(nameof(commandFactory)); if (serverControl == null) throw new ArgumentNullException(nameof(serverControl)); - this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); activeChatBots = initialChatBots?.ToList() ?? throw new ArgumentNullException(nameof(initialChatBots)); @@ -189,7 +180,7 @@ namespace Tgstation.Server.Host.Components.Chat if (newChannels == null) throw new ArgumentNullException(nameof(newChannels)); - logger.LogTrace("ChangeChannels {0}...", connectionId); + logger.LogTrace("ChangeChannels {connectionId}...", connectionId); var provider = await RemoveProviderChannels(connectionId, false, cancellationToken); if (provider == null) return; @@ -244,7 +235,7 @@ namespace Tgstation.Server.Host.Components.Chat foreach (var newMapping in newMappings) { var newId = baseId++; - logger.LogTrace("Mapping channel {0}:{1} as {2}", newMapping.Channel.ConnectionName, newMapping.Channel.FriendlyName, newId); + logger.LogTrace("Mapping channel {connectionName}:{channelFriendlyName} as {newId}", newMapping.Channel.ConnectionName, newMapping.Channel.FriendlyName, newId); mappedChannels.Add(newId, newMapping); newMapping.Channel.RealId = newId; } @@ -366,7 +357,7 @@ namespace Tgstation.Server.Host.Components.Chat lock (mappedChannels) // so it doesn't change while we're using it wdChannels = mappedChannels.Where(x => x.Value.IsUpdatesChannel).Select(x => x.Key).ToList(); - logger.LogTrace("Sending deployment message for RevisionInformation: {0}", revisionInformation.Id); + logger.LogTrace("Sending deployment message for RevisionInformation: {revisionInfoId}", revisionInformation.Id); var callbacks = new List>(); @@ -401,7 +392,7 @@ namespace Tgstation.Server.Host.Components.Chat { logger.LogWarning( ex, - "Error sending deploy message to provider {0}!", + "Error sending deploy message to provider {providerId}!", channelMapping.ProviderId); } })); @@ -510,7 +501,7 @@ namespace Tgstation.Server.Host.Components.Chat /// A resulting in the being removed if it exists, otherwise. async Task RemoveProviderChannels(long connectionId, bool removeProvider, CancellationToken cancellationToken) { - logger.LogTrace("RemoveProviderChannels {0}...", connectionId); + logger.LogTrace("RemoveProviderChannels {connectionId}...", connectionId); IProvider provider; lock (providers) { @@ -616,7 +607,7 @@ namespace Tgstation.Server.Host.Components.Chat lock (synchronizationLock) newId = channelIdCounter++; logger.LogTrace( - "Mapping private channel {0}:{1} as {2}", + "Mapping private channel {connectionName}:{channelFriendlyName} as {newId}", message.User.Channel.ConnectionName, message.User.FriendlyName, newId); @@ -673,7 +664,7 @@ namespace Tgstation.Server.Host.Components.Chat return; logger.LogTrace( - "Start processing command: {0}. User (True provider Id): {1}", + "Start processing command: {message}. User (True provider Id): {profiderId}", message.Content, JsonConvert.SerializeObject(message.User)); try @@ -866,7 +857,7 @@ namespace Tgstation.Server.Host.Components.Chat /// A representing the running operation. Task SendMessage(string message, IEnumerable channelIds, CancellationToken cancellationToken) { - logger.LogTrace("Chat send \"{0}\" to channels: {1}", message, String.Join(", ", channelIds)); + logger.LogTrace("Chat send \"{message}\" to channels: {channelIdsCommaSeperated}", message, String.Join(", ", channelIds)); return Task.WhenAll( channelIds.Select(x => diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatManagerFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ChatManagerFactory.cs index 42ff35ecbe..12427da6be 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatManagerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatManagerFactory.cs @@ -7,7 +7,6 @@ using Microsoft.Extensions.Logging; using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Chat.Providers; using Tgstation.Server.Host.Core; -using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Chat { @@ -29,41 +28,30 @@ namespace Tgstation.Server.Host.Components.Chat /// readonly IServerControl serverControl; - /// - /// The for the . - /// - readonly IAsyncDelayer asyncDelayer; - /// /// Initializes a new instance of the class. /// /// The value of . /// The value of . - /// The value of . /// The value of . public ChatManagerFactory( IProviderFactory providerFactory, IServerControl serverControl, - IAsyncDelayer asyncDelayer, ILoggerFactory loggerFactory) { this.providerFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory)); this.serverControl = serverControl ?? throw new ArgumentNullException(nameof(serverControl)); - this.asyncDelayer = asyncDelayer ?? throw new ArgumentNullException(nameof(asyncDelayer)); this.loggerFactory = loggerFactory ?? throw new ArgumentNullException(nameof(loggerFactory)); } /// public IChatManager CreateChatManager( - IIOManager ioManager, ICommandFactory commandFactory, IEnumerable initialChatBots) => new ChatManager( providerFactory, - ioManager, commandFactory, serverControl, - asyncDelayer, loggerFactory, loggerFactory.CreateLogger(), initialChatBots.Where(x => x.Enabled.Value)); diff --git a/src/Tgstation.Server.Host/Components/Chat/IChatManagerFactory.cs b/src/Tgstation.Server.Host/Components/Chat/IChatManagerFactory.cs index 05313f3187..bff29dc9c4 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IChatManagerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IChatManagerFactory.cs @@ -1,7 +1,6 @@ using System.Collections.Generic; using Tgstation.Server.Host.Components.Chat.Commands; -using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Chat { @@ -13,10 +12,9 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Create a . /// - /// The for the . /// The for the . /// The initial for the . /// A new . - IChatManager CreateChatManager(IIOManager ioManager, ICommandFactory commandFactory, IEnumerable initialChatBots); + IChatManager CreateChatManager(ICommandFactory commandFactory, IEnumerable initialChatBots); } } diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 243470001f..57a44f29b2 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -260,7 +260,7 @@ namespace Tgstation.Server.Host.Components var commandFactory = new CommandFactory(assemblyInformationProvider, byond, repoManager, databaseContextFactory, metadata); - var chatManager = chatFactory.CreateChatManager(instanceIoManager, commandFactory, metadata.ChatSettings); + var chatManager = chatFactory.CreateChatManager(commandFactory, metadata.ChatSettings); try { var sessionControllerFactory = new SessionControllerFactory(