Cleanup and switching to StringBuilder

This commit is contained in:
Madpeter 2020-04-29 17:22:44 +01:00
parent 6dd56a2295
commit af6ae11ee9
6 changed files with 66 additions and 49 deletions

View file

@ -125,14 +125,13 @@ namespace BetterSecondBot.WikiMake
string[] arg_hints = shared_interface.GetCommandArgHints(c); string[] arg_hints = shared_interface.GetCommandArgHints(c);
if(area == "Core") if(area == "Core")
{ {
string example_call = "Example: [[COMMAND]]"; StringBuilder ExampleCall = new StringBuilder();
string preaddon = "|||"; ExampleCall.Append("Example: [[COMMAND]]");
ExampleCall.Append("|||");
string addon = ""; string addon = "";
while (loop < minargs) while (loop < minargs)
{ {
example_call += preaddon; ExampleCall.Append(addon);
example_call += addon;
preaddon = "";
addon = "~#~"; addon = "~#~";
string hint_value = ""; string hint_value = "";
if (arg_hints.Length > loop) if (arg_hints.Length > loop)
@ -148,16 +147,16 @@ namespace BetterSecondBot.WikiMake
} }
if (hint_value != "") if (hint_value != "")
{ {
example_call += hint_value; ExampleCall.Append(hint_value);
} }
else else
{ {
example_call += "Not sure"; ExampleCall.Append("?");
ConsoleLog.Debug("[WikiMake] " + area + " Command " + c + " missing some required hint values"); ConsoleLog.Debug("[WikiMake] " + area + " Command " + c + " missing some required hint values");
} }
loop++; loop++;
} }
sb.Append(example_call); sb.Append(ExampleCall.ToString());
sb.Append("<hr style='border-top: 1px dashed #dcdcdc;'>"); sb.Append("<hr style='border-top: 1px dashed #dcdcdc;'>");
} }
sb.Append("[[HELP]]"); sb.Append("[[HELP]]");

View file

@ -10,17 +10,17 @@ namespace BSB.Commands.Group
public override string Helpfile { get { return "Returns a csv of known groups NAME=UUID,NAME=UUID... "; } } public override string Helpfile { get { return "Returns a csv of known groups NAME=UUID,NAME=UUID... "; } }
protected override string RunFunction() protected override string RunFunction()
{ {
string reply = ""; StringBuilder reply = new StringBuilder();
string addon = ""; string addon = "";
foreach (KeyValuePair<UUID, OpenMetaverse.Group> groupdata in bot.MyGroups) foreach (KeyValuePair<UUID, OpenMetaverse.Group> groupdata in bot.MyGroups)
{ {
reply += addon; reply.Append(addon);
reply += groupdata.Value.Name;
reply += "=";
reply += groupdata.Key;
addon = ","; addon = ",";
reply.Append(groupdata.Value.Name);
reply.Append("=");
reply.Append(groupdata.Key);
} }
return reply; return reply.ToString();
} }
} }
} }

View file

@ -8,7 +8,6 @@ namespace BSB.Commands.Group
public class GetGroupRoles : CoreGroupCommand_SmartReply_Group public class GetGroupRoles : CoreGroupCommand_SmartReply_Group
{ {
public override string Helpfile { get { return "Returns group=UUID@@@rolename=UUID,rolename=UUID ... "; } } public override string Helpfile { get { return "Returns group=UUID@@@rolename=UUID,rolename=UUID ... "; } }
public override bool CallFunction(string[] args) public override bool CallFunction(string[] args)
{ {
if (base.CallFunction(args) == true) if (base.CallFunction(args) == true)
@ -42,20 +41,23 @@ namespace BSB.Commands.Group
public override void Callback(string[] args, EventArgs e) public override void Callback(string[] args, EventArgs e)
{ {
GroupRolesDataReplyEventArgs rolesData = (GroupRolesDataReplyEventArgs)e; GroupRolesDataReplyEventArgs rolesData = (GroupRolesDataReplyEventArgs)e;
string reply = "group=" + args[1] + "@@@"; StringBuilder reply = new StringBuilder();
reply.Append("group=");
reply.Append(args[1]);
reply.Append("@@@");
string addon = ""; string addon = "";
foreach(KeyValuePair<UUID,GroupRole> data in rolesData.Roles) foreach(KeyValuePair<UUID,GroupRole> data in rolesData.Roles)
{ {
if (data.Key != UUID.Zero) if (data.Key != UUID.Zero)
{ {
reply += addon; reply.Append(addon);
reply += data.Value.Name;
reply += "=";
reply += data.Key.ToString();
addon = ","; addon = ",";
reply.Append(data.Value.Name);
reply.Append("=");
reply.Append(data.Key.ToString());
} }
} }
bot.GetCommandsInterface.SmartCommandReply(args[0], reply, CommandName); bot.GetCommandsInterface.SmartCommandReply(args[0], reply.ToString(), CommandName);
base.Callback(args, e); base.Callback(args, e);
} }
} }

View file

@ -11,15 +11,15 @@ namespace BSB.Commands.Group
protected override string RunFunction() protected override string RunFunction()
{ {
string reply = ""; StringBuilder reply = new StringBuilder();
string addon = ""; string addon = "";
foreach (UUID group in bot.UnreadGroupchatGroups()) foreach (UUID group in bot.UnreadGroupchatGroups())
{ {
reply += addon; reply.Append(addon);
reply += group;
addon = ","; addon = ",";
reply.Append(group);
} }
return reply; return reply.ToString();
} }
} }
} }

View file

@ -88,13 +88,13 @@ namespace BSB.Static
} }
public static string Spaces(int counter) public static string Spaces(int counter)
{ {
string reply = ""; StringBuilder reply = new StringBuilder();
while (counter > 0) while (counter > 0)
{ {
reply += " "; reply.Append(" ");
counter--; counter--;
} }
return reply; return reply.ToString();
} }
} }
} }

View file

@ -368,32 +368,29 @@ namespace BSB.bottypes
{ {
await CleanDiscordChannel(Chan, 0, true); await CleanDiscordChannel(Chan, 0, true);
} }
StringBuilder output = new StringBuilder();
if (Chan.Name == "interface") if (Chan.Name == "interface")
{ {
if (message.Content.StartsWith("!")) if (message.Content.StartsWith("!"))
{ {
if (message.Content == "!commands") if (message.Content == "!commands")
{ {
string reply = "";
int counter = 0; int counter = 0;
string addon = ""; string addon = "";
foreach(string a in CommandsInterface.GetCommandsList()) foreach(string a in CommandsInterface.GetCommandsList())
{ {
reply += addon; output.Append(addon);
reply += a; addon = " , ";
output.Append(a);
counter++; counter++;
if (counter == 5) if (counter == 5)
{ {
reply += "\n"; output.Append("\n");
addon = ""; addon = "";
counter = 0; counter = 0;
} }
else
{
addon = " , ";
} }
} _ = SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, myconfig.userName, "bot");
_ = SendMessageToChannelAsync("interface", reply, "bot", UUID.Zero, myconfig.userName, "bot");
} }
else if (message.Content.StartsWith("!help") == true) else if (message.Content.StartsWith("!help") == true)
{ {
@ -401,18 +398,33 @@ namespace BSB.bottypes
if (bits.Length == 2) if (bits.Length == 2)
{ {
string command = bits[1].ToLowerInvariant(); string command = bits[1].ToLowerInvariant();
if (CommandsInterface.GetCommandsList().Contains(command) == true) if (CommandsInterface.GetCommandsList().Contains(command) == true)
{ {
_ = SendMessageToChannelAsync("interface", "\n=========================\nCommand: " + command + "\n" +
"Workspace: " + CommandsInterface.GetCommandWorkspace(command) + "\n" + output.Append("\n=========================\nCommand:");
"Min args: " + CommandsInterface.GetCommandArgs(command).ToString() + "\n" + output.Append(command);
"Arg types" + String.Join(",", CommandsInterface.GetCommandArgTypes(command)) + "\n" + output.Append("\n");
"\n" + output.Append("Workspace: ");
"About: " + CommandsInterface.GetCommandHelp(command) + "", "bot", UUID.Zero, myconfig.userName, "bot"); output.Append(CommandsInterface.GetCommandWorkspace(command));
output.Append("\n");
output.Append("Min args: ");
output.Append(CommandsInterface.GetCommandArgs(command).ToString());
output.Append("\n");
output.Append("Arg types: ");
output.Append(String.Join(",", CommandsInterface.GetCommandArgTypes(command)));
output.Append("\n");
output.Append("\n");
output.Append("About: ");
output.Append(CommandsInterface.GetCommandHelp(command));
_ = SendMessageToChannelAsync("interface",output.ToString(), "bot", UUID.Zero, myconfig.userName, "bot");
} }
else else
{ {
_ = SendMessageToChannelAsync("interface", "Unable to find command: " + command + " please use !commands for a full list", "bot", UUID.Zero, myconfig.userName, "bot"); output.Append("Unable to find command: ");
output.Append(command);
output.Append(" please use !commands for a full list");
_ = SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, myconfig.userName, "bot");
} }
} }
else else
@ -422,7 +434,9 @@ namespace BSB.bottypes
} }
else if (message.Content != "!clear") else if (message.Content != "!clear")
{ {
_ = SendMessageToChannelAsync("interface", "Unknown request: " + message.Content + "", "bot", UUID.Zero, myconfig.userName, "bot"); output.Append("Unknown request: ");
output.Append(message.Content);
_ = SendMessageToChannelAsync("interface",output.ToString(), "bot", UUID.Zero, myconfig.userName, "bot");
} }
} }
else else
@ -431,19 +445,21 @@ namespace BSB.bottypes
string command = bits[0].ToLowerInvariant(); string command = bits[0].ToLowerInvariant();
if (CommandsInterface.GetCommandsList().Contains(command) == true) if (CommandsInterface.GetCommandsList().Contains(command) == true)
{ {
bool status = false;
if (bits.Length == 2) if (bits.Length == 2)
{ {
status = CommandsInterface.Call(command, bits[1],UUID.Zero); _ = CommandsInterface.Call(command, bits[1],UUID.Zero);
} }
else else
{ {
status = CommandsInterface.Call(command); _ = CommandsInterface.Call(command);
} }
} }
else else
{ {
_ = SendMessageToChannelAsync("interface", "Unable to find command: " + command + " please use !commands for a full list", "bot", UUID.Zero, myconfig.userName, "bot"); output.Append("Unable to find command: ");
output.Append(command);
output.Append(" please use !commands for a full list");
_ = SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, myconfig.userName, "bot");
} }
} }
} }