/// <summary> /// Handle a command received from chat. /// This is after filtering to make sure a message is a command. /// </summary> internal void HandleCommandReceived(SenderSettings senderSettings, IMessageDetail message) { bool success; IList <Response> responses; try { responses = commandHandlerController.ExecuteCommand(senderSettings, message); success = true; } catch (Exception ex) { ErrorLogger.LogException(ex, ErrorSeverity.Error); ErrorLogger.LogDebug($"Exception while handling: {message}", false); responses = new List <Response> { new Response { Message = $"{Emojis.ExclamationSymbol} {languageHandler.GetPhrase(senderSettings.ServerSettings.Language, "Error_Oops")}: {ex.Message}" } }; success = false; } if (dumpDebug) { var sb = MiscUtility.DumpObject(message); ErrorLogger.LogDebug("Handled " + message.GetType() + ": \r\n" + sb, true); } if (responses.Count > 0) { foreach (Response response in responses) { OnCommandReceived?.Invoke(this, new CommandReceivedEventArgs(senderSettings, message, response)); /// Handled by <see cref="SlateBotController_OnCommandReceived"/> /// and the <see cref="UserSettingsHandler"/> if (dumpDebug) { var sb = MiscUtility.DumpObject(response); ErrorLogger.LogDebug("Response " + response.GetType() + ": \r\n" + sb, true); } } if ((message is SocketMessageWrapper smw) && (smw.socketMessage is SocketUserMessage sum)) { // Help out if we're debugging. if (Debugger.IsAttached) { var sb = MiscUtility.DumpObject(sum); ErrorLogger.LogDebug("Handled " + sum.GetType() + ": \r\n" + sb, dumpDebug); } // React to the message handled. sum.AddReactionAsync(new Emoji(success ? Emojis.CheckUnicode : Emojis.CrossSymbol)).ConfigureAwait(false); } } else if (message is ConsoleMessageDetail) // If from the console { ErrorLogger.LogDebug(NO_RESPONSE_CONSOLE_MESSAGE + "(" + message.Message + ")", true); } }