From c36ade95c8ec67bbe07202a9e06e0afc96604e83 Mon Sep 17 00:00:00 2001 From: Zontreck Date: Tue, 18 Aug 2020 01:12:27 -0700 Subject: [PATCH] Remove legacy argument count requirement for commands --- Assembly/ASMInfo.cs | 4 ++-- ChatLogger.cs | 2 +- CommandSystem/BaseHooks.cs | 22 ++++++++++------------ CommandSystem/CommandGroup.cs | 6 ++---- CommandSystem/CommandHelp.cs | 6 ++---- CommandSystem/CommandRegistry.cs | 4 ++-- GroupKeepAlive.cs | 4 ---- GroupLog.cs | 2 +- Level System/Auth.cs | 2 +- Program.cs | 2 +- WebHookServer/HookCmds.cs | 2 +- 11 files changed, 23 insertions(+), 33 deletions(-) diff --git a/Assembly/ASMInfo.cs b/Assembly/ASMInfo.cs index 9cf268e..59a8103 100644 --- a/Assembly/ASMInfo.cs +++ b/Assembly/ASMInfo.cs @@ -6,7 +6,7 @@ using System.Reflection; [assembly: AssemblyCompany("ZNI")] [assembly: AssemblyAlgorithmId(System.Configuration.Assemblies.AssemblyHashAlgorithm.MD5)] [assembly: AssemblyCopyright("(C) 2020 Tara Piccari")] -[assembly: AssemblyFileVersion("5.4.394")] +[assembly: AssemblyFileVersion("5.4.395")] [assembly: AssemblyDescription("Second Life Bot - BotCore5")] @@ -15,7 +15,7 @@ namespace Bot.Assemble public class ASMInfo { public static string BotName = "ZBotCore"; - public static string BotVer = "5.4.394"; + public static string BotVer = "5.4.395"; public static string GitPassword { get diff --git a/ChatLogger.cs b/ChatLogger.cs index 73ad674..9f6fc75 100644 --- a/ChatLogger.cs +++ b/ChatLogger.cs @@ -42,7 +42,7 @@ namespace Bot /// /// /// - [CommandGroup("log_chat", 5, 0, "log_chat - Toggles chat and IM logging", Destinations.DEST_AGENT | Destinations.DEST_LOCAL )] + [CommandGroup("log_chat", 5, "log_chat - Toggles chat and IM logging", Destinations.DEST_AGENT | Destinations.DEST_LOCAL )] public void toggleChatLog(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { MHE(source, client, "Toggling"); diff --git a/CommandSystem/BaseHooks.cs b/CommandSystem/BaseHooks.cs index 0640afd..baca148 100644 --- a/CommandSystem/BaseHooks.cs +++ b/CommandSystem/BaseHooks.cs @@ -36,7 +36,7 @@ namespace Bot.CommandSystem Final += "
Bot Version"+ASMInfo.BotVer+"

"; - Final += ""; + Final += "
CommandMinimum Level RequiredUsageAllowed SourcesNumber of Arguments required
"; foreach (KeyValuePair cmd in reg.Cmds) { // Command @@ -47,8 +47,6 @@ namespace Bot.CommandSystem Final += ""; // Allowed Sources Final += ""; - // # Arguments - Final += ""; } Final += "
CommandMinimum Level RequiredUsageAllowed Sources
" + cmd.Value.cmdUsage.RawUsage() + "" + cmd.Value.CommandSource + "" + cmd.Value.arguments.ToString() + "
"; @@ -94,7 +92,7 @@ namespace Bot.CommandSystem - [CommandGroup("show_level", 0, 0, "This command shows your current auth level if any.", Destinations.DEST_AGENT | Destinations.DEST_DISCORD | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] + [CommandGroup("show_level", 0, "This command shows your current auth level if any.", Destinations.DEST_AGENT | Destinations.DEST_DISCORD | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] public void show_level(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) @@ -102,7 +100,7 @@ namespace Bot.CommandSystem MHE(source, client, "Hi secondlife:///app/agent/" + agentKey.ToString() + "/about !! Your authorization level is " + level.ToString()); } - [CommandGroup("show_version", 0, 0, "Outputs the bot version", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] + [CommandGroup("show_version", 0, "Outputs the bot version", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] public void show_version(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) @@ -112,7 +110,7 @@ namespace Bot.CommandSystem - [CommandGroup("show_admins", 4, 0, "Outputs all admin users", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] + [CommandGroup("show_admins", 4, "Outputs all admin users", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] public void show_admins(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { @@ -124,15 +122,15 @@ namespace Bot.CommandSystem } - [CommandGroup("terminate_bot", 5, 0, "", Destinations.DEST_LOCAL | Destinations.DEST_AGENT | Destinations.DEST_DISCORD | Destinations.DEST_GROUP)] + [CommandGroup("terminate_bot", 5, "", Destinations.DEST_LOCAL | Destinations.DEST_AGENT | Destinations.DEST_DISCORD | Destinations.DEST_GROUP)] public void PerformExit(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { MHE(source, client, "Bot exit initiated."); BotSession.Instance.EnqueueExit = true; } // !!help - [CommandGroup("!help", 1, 0, "Prints the entire help registry", Destinations.DEST_AGENT |Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] - [CommandGroup("bot.help", 1, 0, "Alias to !help", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] + [CommandGroup("!help", 1, "Prints the entire help registry", Destinations.DEST_AGENT |Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] + [CommandGroup("bot.help", 1, "Alias to !help", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] public void PrintAllHelp(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { if (MainConfiguration.Instance.UseSSL) @@ -141,14 +139,14 @@ namespace Bot.CommandSystem MHE(source, client, $"All commands viewable at: http://{MainConfiguration.Instance.WebServerIP}:{MainConfiguration.Instance.WebServerPort}/help"); } // !help "command" - [CommandGroup("help", 0, 1, "Prints help for one command", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP )] + [CommandGroup("help", 0, "Prints help for one command", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP )] public void PrintHelp(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { CommandRegistry.Instance.PrintHelp(source, additionalArgs[0], client); } - [CommandGroup("disable", 6, 1, "disable [string] - Disables a command", Destinations.DEST_AGENT | Destinations.DEST_GROUP | Destinations.DEST_LOCAL)] + [CommandGroup("disable", 6, "disable [string] - Disables a command", Destinations.DEST_AGENT | Destinations.DEST_GROUP | Destinations.DEST_LOCAL)] public void DisableCmd(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { if (!MainConfiguration.Instance.DisabledCommands.Contains(additionalArgs[0])) @@ -164,7 +162,7 @@ namespace Bot.CommandSystem } - [CommandGroup("enable", 6, 1, "enable [string] - Enables a command", Destinations.DEST_AGENT | Destinations.DEST_GROUP | Destinations.DEST_LOCAL)] + [CommandGroup("enable", 6, "enable [string] - Enables a command", Destinations.DEST_AGENT | Destinations.DEST_GROUP | Destinations.DEST_LOCAL)] public void EnableCmd(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { if (MainConfiguration.Instance.DisabledCommands.Contains(additionalArgs[0])) diff --git a/CommandSystem/CommandGroup.cs b/CommandSystem/CommandGroup.cs index af25656..f4d24d7 100644 --- a/CommandSystem/CommandGroup.cs +++ b/CommandSystem/CommandGroup.cs @@ -11,17 +11,15 @@ namespace Bot.CommandSystem public string Command; public int minLevel; public MethodInfo AssignedMethod; - public int arguments = 0; public CommandHelp cmdUsage; public Destinations CommandSource; - public CommandGroup(string Command, int minLevel, int argCount, string HelpText, Destinations SourceType) + public CommandGroup(string Command, int minLevel, string HelpText, Destinations SourceType) { this.Command = Command; this.minLevel = minLevel; - arguments = argCount; CommandSource = SourceType; - cmdUsage = new CommandHelp(Command, minLevel, argCount, HelpText, SourceType); + cmdUsage = new CommandHelp(Command, minLevel, HelpText, SourceType); } } diff --git a/CommandSystem/CommandHelp.cs b/CommandSystem/CommandHelp.cs index 4ae3169..50560c0 100644 --- a/CommandSystem/CommandHelp.cs +++ b/CommandSystem/CommandHelp.cs @@ -25,21 +25,20 @@ namespace Bot.CommandSystem { public string Name; public int minLevel; - public int args; public string Text; public string sources; public Destinations dests_allowed; } public string GetUsage() { - return "_\nCommand [" + h.Name + "]\n" + h.sources + "\nMinimum Level Required [" + h.minLevel.ToString() + "]\nTotal Arguments [" + h.args.ToString() + "]\nUsage: " + h.Text; + return "_\nCommand [" + h.Name + "]\n" + h.sources + "\nMinimum Level Required [" + h.minLevel.ToString() + "]\nUsage: " + h.Text; } public string RawUsage() { return "Usage: " + h.Text; } - public CommandHelp(string CmdName, int minLevel, int argCount, string HelpText, Destinations DESTS) + public CommandHelp(string CmdName, int minLevel, string HelpText, Destinations DESTS) { h = new Help(); string Applicable = "Command can be used in ["; @@ -51,7 +50,6 @@ namespace Bot.CommandSystem if (Applicable.Substring(Applicable.Length - 1, 1) == " ") Applicable = Applicable.Substring(0, Applicable.Length - 2) + "]"; h.dests_allowed = DESTS; - h.args = argCount; h.Name = CmdName; h.minLevel = minLevel; if (HelpText == "") HelpText = NoAdditionalArguments; diff --git a/CommandSystem/CommandRegistry.cs b/CommandSystem/CommandRegistry.cs index 9c70e12..74acfd1 100644 --- a/CommandSystem/CommandRegistry.cs +++ b/CommandSystem/CommandRegistry.cs @@ -234,9 +234,9 @@ namespace Bot.CommandSystem return; } var ovj = Activator.CreateInstance(cgX.AssignedMethod.DeclaringType); - string[] additionalArgs = new string[cgX.arguments]; + string[] additionalArgs = new string[cmdStruct.Length-1]; // no longer use a hardcoded argument length IgnoreCount = cgX.arguments; - for (int i = 1; i <= cgX.arguments; i++) + for (int i = 1; i <= cmdStruct.Length; i++) { additionalArgs[i - 1] = cmdStruct[pos + i]; } diff --git a/GroupKeepAlive.cs b/GroupKeepAlive.cs index 0fd44c1..036055c 100644 --- a/GroupKeepAlive.cs +++ b/GroupKeepAlive.cs @@ -26,7 +26,6 @@ namespace Bot else { BotSession.Instance.grid.Self.RequestJoinGroupChat(groups.Key); - MHE(Destinations.DEST_LOCAL, UUID.Zero, "I lost the group chat session for secondlife:///app/group/" + groups.Key.ToString() + "/about - Attempting to rejoin the group chat"); } } } @@ -100,7 +99,6 @@ namespace Bot if (count >= 5) { - MH(Destinations.DEST_LOCAL, UUID.Zero, "Aborting group refresh attempt. Too many errors - Resetting cache and retrying"); GroupsEvent.Reset(); GroupsCache = new Dictionary(); BotSession.Instance.grid.Groups.CurrentGroups -= Groups_CurrentGroups; @@ -154,8 +152,6 @@ namespace Bot public void run() { - MHE(Destinations.DEST_LOCAL, UUID.Zero, $"Plugin [{ProgramName}]: {ProgramVersion} has been initialized"); - BotSession.Instance.grid.Groups.CurrentGroups += Groups_CurrentGroups; BotSession.Instance.grid.Groups.GroupRoleDataReply += CacheGroupRoles; diff --git a/GroupLog.cs b/GroupLog.cs index a5eff56..bd5c927 100644 --- a/GroupLog.cs +++ b/GroupLog.cs @@ -80,7 +80,7 @@ namespace Bot private static readonly object _fileRead = new object(); [CommandGroupMaster("Logging")] - [CommandGroup("search_log", 5, 2, "search_log [groupName] [search_term] - Searches for the search term in all logs relating to the group name (Use a underscore to show where spaces are!). The search term may also include the pipe (|) delimiter to include more than 1 word.", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP | Destinations.DEST_DISCORD)] + [CommandGroup("search_log", 5, "search_log [groupName] [search_term] - Searches for the search term in all logs relating to the group name (Use a underscore to show where spaces are!). The search term may also include the pipe (|) delimiter to include more than 1 word.", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP | Destinations.DEST_DISCORD)] public void search_log(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) diff --git a/Level System/Auth.cs b/Level System/Auth.cs index a21dade..9161b1b 100644 --- a/Level System/Auth.cs +++ b/Level System/Auth.cs @@ -16,7 +16,7 @@ namespace Bot class Auth : BaseCommands { - [CommandGroup("auth_user", 5, 2, "Authorizes a user to have command access. Arguments are user (UUID), and Level (int)", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] + [CommandGroup("auth_user", 5, "Authorizes a user to have command access. Arguments are user (UUID), and Level (int)", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] public void set_auth(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) diff --git a/Program.cs b/Program.cs index 390346d..a45d967 100644 --- a/Program.cs +++ b/Program.cs @@ -578,7 +578,7 @@ namespace Bot private ManualResetEvent profile_get = new ManualResetEvent(false); private Avatar.AvatarProperties Properties_AV; - [CommandGroup("set_profile_text", 75, 1, "set_profile_text [text:Base64] - Sets the profile text", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] + [CommandGroup("set_profile_text", 6, "set_profile_text [text:Base64] - Sets the profile text", Destinations.DEST_AGENT | Destinations.DEST_LOCAL)] public void setProfileText(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { MHE(source, client, "Setting..."); diff --git a/WebHookServer/HookCmds.cs b/WebHookServer/HookCmds.cs index 27be0d9..0f3aa13 100644 --- a/WebHookServer/HookCmds.cs +++ b/WebHookServer/HookCmds.cs @@ -58,7 +58,7 @@ namespace Bot.WebHookServer } - [CommandGroup("webhook_auth", 4, 2, "webhook_auth [github_name] [y/n]", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] + [CommandGroup("webhook_auth", 4, "webhook_auth [github_name] [y/n]", Destinations.DEST_AGENT | Destinations.DEST_LOCAL | Destinations.DEST_GROUP)] public void WebHookAuthMgr(UUID client, int level, string[] additionalArgs, Destinations source, UUID agentKey, string agentName) { MainConfiguration cfg = MainConfiguration.Instance;