2022-09-25 16:00:43 +02:00
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
|
|
namespace MinecraftClient.Commands
|
|
|
|
|
{
|
2022-10-12 12:56:56 +02:00
|
|
|
class Bots : Command
|
2022-09-25 16:00:43 +02:00
|
|
|
{
|
|
|
|
|
public override string CmdName { get { return "bots"; } }
|
|
|
|
|
public override string CmdUsage { get { return "bots [list|unload <bot name|all>]"; } }
|
2022-10-28 11:13:20 +08:00
|
|
|
public override string CmdDesc { get { return Translations.cmd_bots_desc; } }
|
2022-09-25 16:00:43 +02:00
|
|
|
|
2022-10-02 18:31:08 +08:00
|
|
|
public override string Run(McClient handler, string command, Dictionary<string, object>? localVars)
|
2022-09-25 16:00:43 +02:00
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
if (HasArg(command))
|
2022-09-25 16:00:43 +02:00
|
|
|
{
|
2022-10-02 18:31:08 +08:00
|
|
|
string[] args = GetArgs(command);
|
2022-09-25 16:00:43 +02:00
|
|
|
|
|
|
|
|
if (args.Length == 1)
|
|
|
|
|
{
|
|
|
|
|
if (args[0].Equals("list", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
StringBuilder sb = new();
|
|
|
|
|
|
|
|
|
|
int length = handler.GetLoadedChatBots().Count;
|
|
|
|
|
|
|
|
|
|
if (length == 0)
|
2022-10-28 11:13:20 +08:00
|
|
|
return Translations.cmd_bots_noloaded;
|
2022-09-25 16:00:43 +02:00
|
|
|
|
|
|
|
|
for (int i = 0; i < length; i++)
|
|
|
|
|
{
|
|
|
|
|
sb.Append(handler.GetLoadedChatBots()[i].GetType().Name);
|
|
|
|
|
|
|
|
|
|
if (i != length - 1)
|
|
|
|
|
sb.Append(" ,");
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-28 11:13:20 +08:00
|
|
|
return Translations.cmd_bots_list + ": " + sb.ToString();
|
2022-09-25 16:00:43 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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)
|
2022-10-28 11:13:20 +08:00
|
|
|
return Translations.cmd_bots_noloaded;
|
2022-09-25 16:00:43 +02:00
|
|
|
|
|
|
|
|
handler.UnloadAllBots();
|
2022-10-28 11:13:20 +08:00
|
|
|
return Translations.cmd_bots_unloaded_all;
|
2022-09-25 16:00:43 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
ChatBot? bot = handler.GetLoadedChatBots().Find(bot => bot.GetType().Name.ToLower() == botName.ToLower());
|
|
|
|
|
|
|
|
|
|
if (bot == null)
|
2022-10-28 11:13:20 +08:00
|
|
|
return string.Format(Translations.cmd_bots_notfound, botName);
|
2022-09-25 16:00:43 +02:00
|
|
|
|
|
|
|
|
handler.BotUnLoad(bot);
|
2022-10-28 11:13:20 +08:00
|
|
|
return string.Format(Translations.cmd_bots_unloaded, botName);
|
2022-09-25 16:00:43 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return GetCmdDescTranslated();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|