adds the new commands history system

This commit is contained in:
Madpeter 2020-04-25 23:50:46 +01:00
parent 183cf56c1c
commit 9cc5ff374d
2 changed files with 39 additions and 2 deletions

View file

@ -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

View file

@ -11,6 +11,35 @@ namespace BSB.bottypes
{
public abstract class CommandsBot : AVstorageBot
{
Dictionary<string, long> CommandHistory = new Dictionary<string, long>();
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<string> commands = new List<string>();
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()