diff --git a/src/Tgstation.Server.Host/Components/Chat/Chat.cs b/src/Tgstation.Server.Host/Components/Chat/Chat.cs
index 121ea10a23..77fb9031b2 100644
--- a/src/Tgstation.Server.Host/Components/Chat/Chat.cs
+++ b/src/Tgstation.Server.Host/Components/Chat/Chat.cs
@@ -1,6 +1,7 @@
-using System;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using System;
using System.Collections.Generic;
-using System.Globalization;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
@@ -26,6 +27,11 @@ namespace Tgstation.Server.Host.Components.Chat
///
readonly IIOManager ioManager;
+ ///
+ /// The for the
+ ///
+ readonly ILogger logger;
+
///
/// s that never change
///
@@ -69,18 +75,20 @@ namespace Tgstation.Server.Host.Components.Chat
///
/// If has been called
///
- bool started;
+ bool started;
///
/// Construct a
///
/// The value of
/// The value of
+ /// The value of
/// The used to populate
- public Chat(IProviderFactory providerFactory, IIOManager ioManager, ICommandFactory commandFactory)
+ public Chat(IProviderFactory providerFactory, IIOManager ioManager, ILogger logger, ICommandFactory commandFactory)
{
this.providerFactory = providerFactory ?? throw new ArgumentNullException(nameof(providerFactory));
this.ioManager = ioManager ?? throw new ArgumentNullException(nameof(ioManager));
+ this.logger = logger ?? throw new ArgumentNullException(nameof(logger));
builtinCommands = commandFactory?.GenerateCommands() ?? throw new ArgumentNullException(nameof(commandFactory));
providers = new Dictionary();
@@ -136,13 +144,41 @@ namespace Tgstation.Server.Host.Components.Chat
/// A representing the running operation
async Task ProcessMessage(IProvider provider, Message message, CancellationToken cancellationToken)
{
+ logger.LogTrace("Chat message: {0}. User (Note unconverted provider Id): {1}", message.Content, JsonConvert.SerializeObject(message.User));
+ if (customCommandHandler == null)
+ {
+ logger.LogError("Recieved chat message with no command handler installed!");
+ return;
+ }
+
if (!(message.Content.StartsWith(CommonMention, StringComparison.InvariantCultureIgnoreCase) || message.Content.StartsWith(provider.BotMention, StringComparison.Ordinal)))
//no mention
return;
-
- await Task.Yield();
- lock (this)
- throw new NotImplementedException();
+
+ var splits = new List(message.Content.Split(' '));
+ if (splits.Count == 1)
+ {
+ //just a mention
+ await SendMessage("Hi!", new List { message.User.Channel.RealId }, cancellationToken).ConfigureAwait(false);
+ return;
+ }
+
+ splits.RemoveAt(0);
+
+ var command = splits[0];
+ splits.RemoveAt(0);
+ var arguments = String.Join(" ", splits);
+
+ if (customCommandHandler == null)
+ logger.LogError("Recieved chat message with no command handler installed!");
+ try
+ {
+ await customCommandHandler.HandleChatCommand(command, arguments, message.User, cancellationToken).ConfigureAwait(false);
+ }
+ catch (Exception e)
+ {
+ logger.LogWarning("Error processing custom command: {0}", e);
+ }
}
///
diff --git a/src/Tgstation.Server.Host/Components/Chat/ICommandFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ICommandFactory.cs
index 8abfe7abcd..4fb9dd2de1 100644
--- a/src/Tgstation.Server.Host/Components/Chat/ICommandFactory.cs
+++ b/src/Tgstation.Server.Host/Components/Chat/ICommandFactory.cs
@@ -3,8 +3,15 @@ using Tgstation.Server.Host.Components.Chat.Commands;
namespace Tgstation.Server.Host.Components.Chat
{
+ ///
+ /// Factory for built in s
+ ///
interface ICommandFactory
{
+ ///
+ /// Generate builtin s
+ ///
+ /// A of s
IReadOnlyList GenerateCommands();
}
}