mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Added command for reloading settings, chat bots, listing chat bots and unloading a chat bot manually by name.
This commit is contained in:
parent
ef79ca1fe8
commit
9b407dbdad
7 changed files with 198 additions and 46 deletions
76
MinecraftClient/ChatBots/BotsCommand.cs
Normal file
76
MinecraftClient/ChatBots/BotsCommand.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using MinecraftClient.Mapping;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
|
||||
namespace MinecraftClient.Commands
|
||||
{
|
||||
class BotsCommand : Command
|
||||
{
|
||||
public override string CmdName { get { return "bots"; } }
|
||||
public override string CmdUsage { get { return "bots [list|unload <bot name|all>]"; } }
|
||||
public override string CmdDesc { get { return "cmd.bots.desc"; } }
|
||||
|
||||
public override string Run(McClient handler, string command, Dictionary<string, object> localVars)
|
||||
{
|
||||
if (hasArg(command))
|
||||
{
|
||||
string[] args = getArgs(command);
|
||||
|
||||
if (args.Length == 1)
|
||||
{
|
||||
if (args[0].Equals("list", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
StringBuilder sb = new();
|
||||
|
||||
int length = handler.GetLoadedChatBots().Count;
|
||||
|
||||
if (length == 0)
|
||||
return Translations.TryGet("cmd.bots.noloaded");
|
||||
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
sb.Append(handler.GetLoadedChatBots()[i].GetType().Name);
|
||||
|
||||
if (i != length - 1)
|
||||
sb.Append(" ,");
|
||||
|
||||
}
|
||||
|
||||
return Translations.Get("cmd.bots.list") + ": " + sb.ToString();
|
||||
}
|
||||
|
||||
}
|
||||
else if (args.Length == 2)
|
||||
{
|
||||
if (args[0].Equals("unload", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
string botName = args[1].Trim();
|
||||
|
||||
if (botName.ToLower().Equals("all", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (handler.GetLoadedChatBots().Count == 0)
|
||||
return Translations.TryGet("cmd.bots.noloaded");
|
||||
|
||||
handler.UnloadAllBots();
|
||||
return Translations.TryGet("cmd.bots.unloaded_all");
|
||||
}
|
||||
else
|
||||
{
|
||||
ChatBot? bot = handler.GetLoadedChatBots().Find(bot => bot.GetType().Name.ToLower() == botName.ToLower());
|
||||
|
||||
if (bot == null)
|
||||
return Translations.TryGet("cmd.bots.notfound", botName);
|
||||
|
||||
handler.BotUnLoad(bot);
|
||||
return Translations.TryGet("cmd.bots.unloaded", botName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return GetCmdDescTranslated();
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue