From 9cc5ff374dfb509edd450103bfd44fece4495359 Mon Sep 17 00:00:00 2001 From: Madpeter Date: Sat, 25 Apr 2020 23:50:46 +0100 Subject: [PATCH] adds the new commands history system --- Core/Commands/commandlib.cs | 12 ++++++++++-- Core/bottypes/CommandsBot.cs | 29 +++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/Core/Commands/commandlib.cs b/Core/Commands/commandlib.cs index 524f67a..5a4ca5d 100644 --- a/Core/Commands/commandlib.cs +++ b/Core/Commands/commandlib.cs @@ -204,11 +204,12 @@ namespace BSB.Commands { return Call(command, ""); } - public bool Call(string command,string arg) + + protected bool CallCommand(string command, string arg) { command = command.ToLowerInvariant(); CoreCommand cmd = (CoreCommand)GetCommand(command); - if(cmd != null) + if (cmd != null) { cmd.Setup(bot); if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true)) @@ -252,6 +253,13 @@ namespace BSB.Commands } return false; } + + } + public bool Call(string command, string arg) + { + bool result = CallCommand(command, arg); + bot.CommandHistoryAdd(command, arg, result); + return result; } } public abstract class CoreCommand : API_interface diff --git a/Core/bottypes/CommandsBot.cs b/Core/bottypes/CommandsBot.cs index 8f4e065..f722530 100644 --- a/Core/bottypes/CommandsBot.cs +++ b/Core/bottypes/CommandsBot.cs @@ -11,6 +11,35 @@ namespace BSB.bottypes { public abstract class CommandsBot : AVstorageBot { + Dictionary CommandHistory = new Dictionary(); + protected int commandid = 1; + public void CommandHistoryAdd(string command, string arg, bool status) + { + string message = "(" + commandid.ToString() + "): " + status.ToString() + " -> " + command + " [" + arg + "]"; + CommandHistory.Add(message, helpers.UnixTimeNow()); + if(CommandHistory.Count() > myconfig.MaxCommandHistory) + { + CommandHistory.Remove(CommandHistory.ElementAt(0).Key); + } + if (myconfig.CommandsToConsole == true) + { + ConsoleLog.Info(message); + } + commandid++; + if (commandid >= myconfig.MaxCommandHistory) commandid = 1; + } + public string[] GetLastCommands(int amount=10) + { + List commands = new List(); + int loop = 0; + while((loop < CommandHistory.Count) && (loop < amount)) + { + commands.Add(CommandHistory.Keys.ElementAt(CommandHistory.Count - loop)); + loop++; + } + return commands.ToArray(); + } + public Commands.CoreCommandsInterface GetCommandsInterface { get { return CommandsInterface; } } protected Commands.CoreCommandsInterface CommandsInterface; public CommandsBot()