Added a Debug mode setting to the Websocket chat bot.

This commit is contained in:
Milutinke 2022-10-24 22:52:49 +02:00
parent 46e8818b5b
commit 7b19a1137f
2 changed files with 7 additions and 2 deletions

View file

@ -185,6 +185,9 @@ namespace MinecraftClient.ChatBots
[TomlInlineComment("$config.ChatBot.WebSocketBot.Password$")] [TomlInlineComment("$config.ChatBot.WebSocketBot.Password$")]
public string? Password = "wspass12345"; public string? Password = "wspass12345";
[TomlInlineComment("$config.ChatBot.WebSocketBot.DebugMode$")]
public bool DebugMode = false;
} }
public WebSocketBot() public WebSocketBot()
@ -266,7 +269,8 @@ namespace MinecraftClient.ChatBots
{ {
try try
{ {
LogDebugToConsole("\n\n\tGot command\n\n\t" + message + "\n\n"); if (Config.DebugMode)
LogDebugToConsole("\n\n\tGot command\n\n\t" + message + "\n\n");
WsChatBotCommand cmd = JsonConvert.DeserializeObject<WsChatBotCommand>(message)!; WsChatBotCommand cmd = JsonConvert.DeserializeObject<WsChatBotCommand>(message)!;
WsCommandResponder responder = new WsCommandResponder(this, session, cmd.Command, cmd.RequestId); WsCommandResponder responder = new WsCommandResponder(this, session, cmd.Command, cmd.RequestId);
@ -1119,7 +1123,7 @@ namespace MinecraftClient.ChatBots
{ {
session.SendToClient("{\"event\": \"" + type + "\", \"data\": " + (data.IsNullOrEmpty() ? "null" : "\"" + Json.EscapeString(data) + "\"") + "}"); session.SendToClient("{\"event\": \"" + type + "\", \"data\": " + (data.IsNullOrEmpty() ? "null" : "\"" + Json.EscapeString(data) + "\"") + "}");
if (!(type.Contains("Entity") || type.Equals("OnTimeUpdate") || type.Equals("OnServerTpsUpdate"))) if (!(type.Contains("Entity") || type.Equals("OnTimeUpdate") || type.Equals("OnServerTpsUpdate")) && Config.DebugMode)
LogDebugToConsole( LogDebugToConsole(
"\n\n\tSending:\n\n\t{\"event\": \"" + type + "\n\n\tSending:\n\n\t{\"event\": \"" + type +
"\", \"data\": " + (data.IsNullOrEmpty() ? "null" : "\"" "\", \"data\": " + (data.IsNullOrEmpty() ? "null" : "\""

View file

@ -1047,3 +1047,4 @@ config.ChatBot.WebSocketBot=Remotely control the client using Web Sockets.\n# Th
config.ChatBot.WebSocketBot.Ip=The IP address that Websocket server will be bounded to. config.ChatBot.WebSocketBot.Ip=The IP address that Websocket server will be bounded to.
config.ChatBot.WebSocketBot.Port=The Port that Websocket server will be bounded to. config.ChatBot.WebSocketBot.Port=The Port that Websocket server will be bounded to.
config.ChatBot.WebSocketBot.Password=A password that will be used to authenticate on thw Websocket server (It is recommended to change the default password and to set a strong one). config.ChatBot.WebSocketBot.Password=A password that will be used to authenticate on thw Websocket server (It is recommended to change the default password and to set a strong one).
config.ChatBot.WebSocketBot.DebugMode=If enabled the chat bot will print what is it recieving and sending when the "DebugMessages" are enabled in "Logging" section. This is useful when making your own library or trying to figure what is wrong with an existing one.