From c390fd0b353e047dc035f55d0d60fb06c877f4ce Mon Sep 17 00:00:00 2001 From: Zontreck Date: Mon, 20 Apr 2020 16:37:36 -0700 Subject: [PATCH] allow bot to appear in group logs --- Assembly/ASMInfo.cs | 4 +- Bot.csproj | 5 +++ CommandSystem/BaseHooks.cs | 21 ++++++++++ CommandSystem/CommandManager.cs | 9 ++++- GroupLog.cs | 69 +++++++++++++++++++++++++++++++-- Program.cs | 7 ++-- 6 files changed, 105 insertions(+), 10 deletions(-) diff --git a/Assembly/ASMInfo.cs b/Assembly/ASMInfo.cs index 9eb7a48..92b622d 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("© 2020 Tara Piccari")] -[assembly: AssemblyFileVersion("5.587")] +[assembly: AssemblyFileVersion("5.592")] [assembly: AssemblyDescription("Second Life Bot - BotCore5")] @@ -15,7 +15,7 @@ namespace Bot.Assemble public class ASMInfo { public static string BotName = "ZBotCore"; - public static double BotVer = 5.587; + public static double BotVer = 5.592; public static string GitPassword { get diff --git a/Bot.csproj b/Bot.csproj index 97bf129..bc70864 100644 --- a/Bot.csproj +++ b/Bot.csproj @@ -6,6 +6,11 @@ true false false + Debug;Release;DebPub + + + + bin\debpub diff --git a/CommandSystem/BaseHooks.cs b/CommandSystem/BaseHooks.cs index a22517e..21c2166 100644 --- a/CommandSystem/BaseHooks.cs +++ b/CommandSystem/BaseHooks.cs @@ -123,5 +123,26 @@ namespace Bot.CommandSystem MHE(source, client, "secondlife:///app/agent/" + MainConfiguration.Instance.BotAdmins.ElementAt(i).Key.ToString() + "/about [" + MainConfiguration.Instance.BotAdmins.ElementAt(i).Value.ToString() + "] " + MainConfiguration.Instance.BotAdmins.ElementAt(i).Key.ToString()); } } + + + [CommandGroup("terminate_bot", 5, 0, "", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_CONSOLE_INFO | MessageHandler.Destinations.DEST_DISCORD)] + public void PerformExit(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + MHE(source, client, "Bot exit initiated."); + MHE(MessageHandler.Destinations.DEST_ACTION, UUID.Zero, "{'type':'exit'}"); + } + // !!help + [CommandGroup("!help", 0, 0, "Prints the entire help registry", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP | MessageHandler.Destinations.DEST_CONSOLE_INFO)] + [CommandGroup("bot.help", 0, 0, "Alias to !help", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP)] + public void PrintAllHelp(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + MHE(source, client, "All commands viewable at: https://zontreck.dev:35591/help"); + } + // !help "command" + [CommandGroup("help", 0, 1, "Prints help for one command", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP | MessageHandler.Destinations.DEST_CONSOLE_INFO)] + public void PrintHelp(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) + { + registry.PrintHelp(source, additionalArgs[0], client); + } } } diff --git a/CommandSystem/CommandManager.cs b/CommandSystem/CommandManager.cs index bd6a98b..7442fc4 100644 --- a/CommandSystem/CommandManager.cs +++ b/CommandSystem/CommandManager.cs @@ -78,8 +78,15 @@ namespace Bot.CommandSystem string GroupName = client.Groups.GroupName2KeyCache[fromID]; GroupLog.Instance.WriteLogEntry(GroupName, "secondlife:///app/agent/" + agentKey.ToString() + "/about (" + agentName + ") : " + request); + + + if (agentKey == client.Self.AgentID) return false; + } + else { + agentKey = fromID; + + if (agentKey == client.Self.AgentID) return false; } - else { agentKey = fromID; } if (request.Substring(0, 1) != "!") { diff --git a/GroupLog.cs b/GroupLog.cs index 4e70948..cd9224b 100644 --- a/GroupLog.cs +++ b/GroupLog.cs @@ -4,8 +4,8 @@ using System.Text; using System.IO; using Bot.CommandSystem; using OpenMetaverse; - - +using Bot.WebHookServer; +using System.Collections.Specialized; namespace Bot { @@ -53,7 +53,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.", Bot.MessageHandler.Destinations.DEST_AGENT | Bot.MessageHandler.Destinations.DEST_LOCAL)] + [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.", Bot.MessageHandler.Destinations.DEST_AGENT | Bot.MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_GROUP | MessageHandler.Destinations.DEST_DISCORD)] public void search_log(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) @@ -92,5 +92,68 @@ namespace Bot MHE(source, client, ".\n \n[Search Completed]"); } + + + + [WebhookAttribs("/viewlog/%", HTTPMethod = "GET")] + public WebhookRegistry.HTTPResponseData View_Log(List arguments, string body, string method, NameValueCollection headers) + { + WebhookRegistry.HTTPResponseData rd = new WebhookRegistry.HTTPResponseData(); + + string FinalOutput = ""; + lock (_fileRead) + { + try + { + + foreach (string s in File.ReadLines("GroupChatLogs/" + Uri.UnescapeDataString(arguments[0]) + ".log")) + { + string tmp = s; + string[] Ltmp = tmp.Split(' '); + tmp = ""; + foreach (string K in Ltmp) + { + if (K.StartsWith("secondlife://")) + { + // DO NOT ADD TO OUTPUT + } + else + { + tmp += K + " "; + } + } + + FinalOutput += tmp + "
"; + + } + rd.Status = 200; + rd.ReplyString = FinalOutput; + rd.ReturnContentType = "text/html"; + } + catch (Exception e) + { + rd.Status = 418; + rd.ReplyString = "You burned... the tea"; + } + } + + return rd; + } + + [WebhookAttribs("/logs", HTTPMethod = "GET")] + public WebhookRegistry.HTTPResponseData List_Logs(List arguments, string body, string method, NameValueCollection headers) + { + WebhookRegistry.HTTPResponseData hrd = new WebhookRegistry.HTTPResponseData(); + hrd.Status = 200; + hrd.ReplyString = "

Group Chat Logs

"; + DirectoryInfo di = new DirectoryInfo("GroupChatLogs"); + foreach (FileInfo fi in di.GetFiles()) + { + hrd.ReplyString += "
" + fi.Name + ""; + } + hrd.ReturnContentType = "text/html"; + + return hrd; + } } } diff --git a/Program.cs b/Program.cs index 98bb115..65ea04a 100644 --- a/Program.cs +++ b/Program.cs @@ -644,7 +644,7 @@ namespace Bot */ } - [CommandGroup("load_dll", 5, 1, "load_dll [DLL_Name] - Loads a DLL and searches for entry points", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT)] + [CommandGroup("load_dll", 5, 1, "load_dll [DLL_Name] - Loads a DLL and searches for entry points", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_CONSOLE_INFO)] public void load_DLL(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) { // Load DLL @@ -661,7 +661,7 @@ namespace Bot } - [CommandGroup("unload_dll", 5, 1, "unload_dll [DLL_Name] - Prevents DLL from reloading at next reboot", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT)] + [CommandGroup("unload_dll", 5, 1, "unload_dll [DLL_Name] - Prevents DLL from reloading at next reboot", MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_CONSOLE_INFO)] public void unload_DLL(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) { // Load DLL @@ -674,7 +674,7 @@ namespace Bot cfg.Save(); } - [CommandGroup("assign", 75, 1, "assign [DLL Name] - Sets the active DLL", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL)] + [CommandGroup("assign", 75, 1, "assign [DLL Name] - Sets the active DLL", MessageHandler.Destinations.DEST_AGENT | MessageHandler.Destinations.DEST_LOCAL | MessageHandler.Destinations.DEST_CONSOLE_INFO)] public void SetActiveProgram(UUID client, int level, GridClient grid, string[] additionalArgs, MessageHandler.MessageHandleEvent MHE, MessageHandler.Destinations source, CommandRegistry registry, UUID agentKey, string agentName) { MHE(MessageHandler.Destinations.DEST_ACTION, UUID.Zero, "{\"type\":\"assignProgram\",\"newProgram\":\"" + additionalArgs[0] + "\"}"); @@ -735,7 +735,6 @@ namespace Bot private static void onChatRecv(object sender, ChatEventArgs e) { if (e.Message == "" || e.Message == "typing") return; - if (e.SourceID == client.Self.AgentID) return; string eMe = e.Message; Dictionary dstuf = new Dictionary();