From d112a3553ed0bccefd175a832960ff5af34f3ed0 Mon Sep 17 00:00:00 2001 From: Jordan Brown Date: Tue, 28 Apr 2020 16:42:05 -0400 Subject: [PATCH] Fix CustomCommands never getting their ICustomCommandHandler --- .../Components/Chat/ChatManager.cs | 1 + .../Components/Chat/ChatTrackingContext.cs | 26 ++++++++++++++++++- .../Components/Chat/IChatTrackingContext.cs | 2 +- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs index 0cd2ee4bb5..71201c50a1 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatManager.cs @@ -645,6 +645,7 @@ namespace Tgstation.Server.Host.Components.Chat IChatTrackingContext context = null; lock (mappedChannels) context = new ChatTrackingContext( + customCommandHandler, mappedChannels.Select(y => y.Value.Channel), loggerFactory.CreateLogger(), () => diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs b/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs index 93873f876f..4663724586 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatTrackingContext.cs @@ -26,7 +26,22 @@ namespace Tgstation.Server.Host.Components.Chat public IReadOnlyCollection Channels { get; private set; } /// - public IReadOnlyCollection CustomCommands { get; set; } + public IEnumerable CustomCommands + { + get => customCommands; + set => customCommands = (value ?? throw new InvalidOperationException("value cannot be null!")) + .Select(customCommand => + { + customCommand.SetHandler(customCommandHandler); + return customCommand; + }) + .ToList(); + } + + /// + /// The for the . + /// + readonly ICustomCommandHandler customCommandHandler; /// /// The for the . @@ -38,6 +53,11 @@ namespace Tgstation.Server.Host.Components.Chat /// readonly object synchronizationLock; + /// + /// Backing field for . + /// + IReadOnlyCollection customCommands; + /// /// The if any. /// @@ -56,20 +76,24 @@ namespace Tgstation.Server.Host.Components.Chat /// /// Initializes a new instance of the . /// + /// The value of . /// The initial value of . /// The value of . /// The value of . public ChatTrackingContext( + ICustomCommandHandler customCommandHandler, IEnumerable initialChannels, ILogger logger, Action onDispose) { + this.customCommandHandler = customCommandHandler ?? throw new ArgumentNullException(nameof(customCommandHandler)); Channels = initialChannels?.ToList() ?? throw new ArgumentNullException(nameof(initialChannels)); this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); this.onDispose = onDispose ?? throw new ArgumentNullException(nameof(onDispose)); synchronizationLock = new object(); Active = true; + customCommands = Array.Empty(); } /// diff --git a/src/Tgstation.Server.Host/Components/Chat/IChatTrackingContext.cs b/src/Tgstation.Server.Host/Components/Chat/IChatTrackingContext.cs index 069b3c33c5..e4e4bc34ed 100644 --- a/src/Tgstation.Server.Host/Components/Chat/IChatTrackingContext.cs +++ b/src/Tgstation.Server.Host/Components/Chat/IChatTrackingContext.cs @@ -22,7 +22,7 @@ namespace Tgstation.Server.Host.Components.Chat /// /// of s in the . /// - IReadOnlyCollection CustomCommands { get; set; } + IEnumerable CustomCommands { get; set; } /// /// Sets the for the .