adds the new commands history system
This commit is contained in:
parent
183cf56c1c
commit
9cc5ff374d
2 changed files with 39 additions and 2 deletions
|
|
@ -204,11 +204,12 @@ namespace BSB.Commands
|
||||||
{
|
{
|
||||||
return Call(command, "");
|
return Call(command, "");
|
||||||
}
|
}
|
||||||
public bool Call(string command,string arg)
|
|
||||||
|
protected bool CallCommand(string command, string arg)
|
||||||
{
|
{
|
||||||
command = command.ToLowerInvariant();
|
command = command.ToLowerInvariant();
|
||||||
CoreCommand cmd = (CoreCommand)GetCommand(command);
|
CoreCommand cmd = (CoreCommand)GetCommand(command);
|
||||||
if(cmd != null)
|
if (cmd != null)
|
||||||
{
|
{
|
||||||
cmd.Setup(bot);
|
cmd.Setup(bot);
|
||||||
if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true))
|
if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true))
|
||||||
|
|
@ -252,6 +253,13 @@ namespace BSB.Commands
|
||||||
}
|
}
|
||||||
return false;
|
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
|
public abstract class CoreCommand : API_interface
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,35 @@ namespace BSB.bottypes
|
||||||
{
|
{
|
||||||
public abstract class CommandsBot : AVstorageBot
|
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; } }
|
public Commands.CoreCommandsInterface GetCommandsInterface { get { return CommandsInterface; } }
|
||||||
protected Commands.CoreCommandsInterface CommandsInterface;
|
protected Commands.CoreCommandsInterface CommandsInterface;
|
||||||
public CommandsBot()
|
public CommandsBot()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue