From eb1f45f3303512f338804d5c3cd8859577af6e7b Mon Sep 17 00:00:00 2001 From: Madpeter <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 27 Jun 2024 23:09:44 +0100 Subject: [PATCH] add support to create wiki files while running in debug --- SecondBotEvents/Commands/Animation.cs | 3 + SecondBotEvents/Commands/Avatars.cs | 1 + SecondBotEvents/Commands/Chat.cs | 1 + SecondBotEvents/Commands/Core.cs | 1 + SecondBotEvents/Commands/Dialogs.cs | 1 + SecondBotEvents/Commands/Discord.cs | 1 + SecondBotEvents/Commands/Estate.cs | 5 +- SecondBotEvents/Commands/Friends.cs | 1 + SecondBotEvents/Commands/Funds.cs | 3 +- SecondBotEvents/Commands/Group.cs | 1 + SecondBotEvents/Commands/Info.cs | 1 + SecondBotEvents/Commands/Inventory.cs | 1 + SecondBotEvents/Commands/Movement.cs | 1 + SecondBotEvents/Commands/Notecard.cs | 1 + SecondBotEvents/Commands/ParcelCommands.cs | 1 + SecondBotEvents/Commands/Self.cs | 3 +- SecondBotEvents/Commands/StreamAdmin.cs | 1 + SecondBotEvents/EventsSecondBot.cs | 23 +-- .../Properties/Resources.Designer.cs | 63 +++++++ SecondBotEvents/Properties/Resources.resx | 120 +++++++++++++ SecondBotEvents/SecondBotEvents.csproj | 21 +++ SecondBotEvents/Services/HttpService.cs | 18 +- SecondBotEvents/Static/template.html | 54 ++++++ SecondBotEvents/WikiService.cs | 157 ++++++++++++++++++ 24 files changed, 465 insertions(+), 18 deletions(-) create mode 100644 SecondBotEvents/Properties/Resources.Designer.cs create mode 100644 SecondBotEvents/Properties/Resources.resx create mode 100644 SecondBotEvents/Static/template.html create mode 100644 SecondBotEvents/WikiService.cs diff --git a/SecondBotEvents/Commands/Animation.cs b/SecondBotEvents/Commands/Animation.cs index f47e317..433004a 100644 --- a/SecondBotEvents/Commands/Animation.cs +++ b/SecondBotEvents/Commands/Animation.cs @@ -3,8 +3,11 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { + [ClassInfo("Animations and Gestures")] internal class AnimationCommands : CommandsAPI { + + public AnimationCommands(EventsSecondBot setmaster) : base(setmaster) { } diff --git a/SecondBotEvents/Commands/Avatars.cs b/SecondBotEvents/Commands/Avatars.cs index fc07bfa..26e8afc 100644 --- a/SecondBotEvents/Commands/Avatars.cs +++ b/SecondBotEvents/Commands/Avatars.cs @@ -6,6 +6,7 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { + [ClassInfo("Avatars near me and Key2Name and Name2Key lookups")] public class Avatars : CommandsAPI { public Avatars(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Chat.cs b/SecondBotEvents/Commands/Chat.cs index 67efb6f..792f301 100644 --- a/SecondBotEvents/Commands/Chat.cs +++ b/SecondBotEvents/Commands/Chat.cs @@ -4,6 +4,7 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { + [ClassInfo("Text based interaction,message status and history")] public class Chat : CommandsAPI { public Chat(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Core.cs b/SecondBotEvents/Commands/Core.cs index daaf416..24081c9 100644 --- a/SecondBotEvents/Commands/Core.cs +++ b/SecondBotEvents/Commands/Core.cs @@ -2,6 +2,7 @@ namespace SecondBotEvents.Commands { + [ClassInfo("Used to test interaction with the bot... hello world for avartars")] public class Core : CommandsAPI { public Core(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Dialogs.cs b/SecondBotEvents/Commands/Dialogs.cs index 352f35d..d62a663 100644 --- a/SecondBotEvents/Commands/Dialogs.cs +++ b/SecondBotEvents/Commands/Dialogs.cs @@ -4,6 +4,7 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { + [ClassInfo("Script dialog box interaction / events when displayed")] public class Dialogs : CommandsAPI { public Dialogs(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Discord.cs b/SecondBotEvents/Commands/Discord.cs index 710c832..2a220a1 100644 --- a/SecondBotEvents/Commands/Discord.cs +++ b/SecondBotEvents/Commands/Discord.cs @@ -5,6 +5,7 @@ using System.Linq; namespace SecondBotEvents.Commands { + [ClassInfo("Control discord from the grid")] public class DiscordCommands : CommandsAPI { public DiscordCommands(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Estate.cs b/SecondBotEvents/Commands/Estate.cs index e344c9a..8644225 100644 --- a/SecondBotEvents/Commands/Estate.cs +++ b/SecondBotEvents/Commands/Estate.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { + [ClassInfo("Look after a sim as the estate manager")] public class Estate : CommandsAPI { public Estate(EventsSecondBot setmaster) : base(setmaster) @@ -13,7 +14,7 @@ namespace SecondBotEvents.Commands [About("Sends the message to the current sim")] [ReturnHints("restarting")] [ReturnHintsFailure("Not an estate manager here")] - [ReturnHintsFailure("canceled")] + [ReturnHints("canceled")] [ArgHints("delay", "How long to delay the restart for (30 to 240 secs) - defaults to 240 if out of bounds \n" + "set to 0 if your canceling!")] [ArgHints("mode", "true to start a restart, false to cancel")] @@ -44,7 +45,7 @@ namespace SecondBotEvents.Commands [ReturnHintsFailure("Message empty")] [ReturnHints("ok")] [ArgHints("message", "What the message is")] - public object SimMessage(string message, string token) + public object SimMessage(string message) { if (SecondbotHelpers.notempty(message) == false) { diff --git a/SecondBotEvents/Commands/Friends.cs b/SecondBotEvents/Commands/Friends.cs index b9b9fa0..2046499 100644 --- a/SecondBotEvents/Commands/Friends.cs +++ b/SecondBotEvents/Commands/Friends.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { + [ClassInfo("The power of friendship")] public class Friends : CommandsAPI { public Friends(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Funds.cs b/SecondBotEvents/Commands/Funds.cs index db5f3d1..db57bab 100644 --- a/SecondBotEvents/Commands/Funds.cs +++ b/SecondBotEvents/Commands/Funds.cs @@ -4,6 +4,7 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { + [ClassInfo("Money makes the world go round")] public class Funds : CommandsAPI { public Funds(EventsSecondBot setmaster) : base(setmaster) @@ -12,7 +13,7 @@ namespace SecondBotEvents.Commands [About("Requests the current balance and requests the balance to update.")] [ReturnHints("Current fund level")] [ReturnHintsFailure("Funds commands are disabled")] - public object Balance(string token) + public object Balance() { if (master.CommandsService.myConfig.GetAllowFundsCommands() == false) { diff --git a/SecondBotEvents/Commands/Group.cs b/SecondBotEvents/Commands/Group.cs index aa448d4..d0a7b42 100644 --- a/SecondBotEvents/Commands/Group.cs +++ b/SecondBotEvents/Commands/Group.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { + [ClassInfo("Control groups with ease")] public class GroupCommands : CommandsAPI { public GroupCommands(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Info.cs b/SecondBotEvents/Commands/Info.cs index f431d23..497d262 100644 --- a/SecondBotEvents/Commands/Info.cs +++ b/SecondBotEvents/Commands/Info.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; namespace SecondBotEvents.Commands { + [ClassInfo("What is going on with the bot")] public class Info : CommandsAPI { public Info(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs index 7bde09b..939f014 100644 --- a/SecondBotEvents/Commands/Inventory.cs +++ b/SecondBotEvents/Commands/Inventory.cs @@ -11,6 +11,7 @@ using System.Linq; namespace SecondBotEvents.Commands { + [ClassInfo("Inventory controls for sending items and so on")] public class InventoryCommands : CommandsAPI { public InventoryCommands(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Movement.cs b/SecondBotEvents/Commands/Movement.cs index a17c379..0d6b189 100644 --- a/SecondBotEvents/Commands/Movement.cs +++ b/SecondBotEvents/Commands/Movement.cs @@ -7,6 +7,7 @@ using System.Threading; namespace SecondBotEvents.Commands { + [ClassInfo("Dont like this place lets try somewhere else")] public class Movement : CommandsAPI { public Movement(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Notecard.cs b/SecondBotEvents/Commands/Notecard.cs index 2ebe502..29acd1c 100644 --- a/SecondBotEvents/Commands/Notecard.cs +++ b/SecondBotEvents/Commands/Notecard.cs @@ -4,6 +4,7 @@ using SecondBotEvents.Services; namespace SecondBotEvents.Commands { + [ClassInfo("Why this is not a built in script command I will never know, but its due to needing this that the bot was made")] public class Notecard : CommandsAPI { public Notecard(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/ParcelCommands.cs b/SecondBotEvents/Commands/ParcelCommands.cs index f1f6b5c..b2244de 100644 --- a/SecondBotEvents/Commands/ParcelCommands.cs +++ b/SecondBotEvents/Commands/ParcelCommands.cs @@ -9,6 +9,7 @@ using static OpenMetaverse.ParcelManager; namespace SecondBotEvents.Commands { + [ClassInfo("Control the land under our feet")] public partial class ParcelCommands : CommandsAPI { public ParcelCommands(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/Commands/Self.cs b/SecondBotEvents/Commands/Self.cs index 3c0dde4..b8e6841 100644 --- a/SecondBotEvents/Commands/Self.cs +++ b/SecondBotEvents/Commands/Self.cs @@ -6,6 +6,7 @@ using System.Linq; namespace SecondBotEvents.Commands { + [ClassInfo("The more we know about our self the better we are")] public class Self : CommandsAPI { public Self(EventsSecondBot setmaster) : base(setmaster) @@ -150,7 +151,7 @@ namespace SecondBotEvents.Commands [About("Gets the last 5 commands issued to the bot")] [ReturnHints("list of commands")] - public object GetLastCommands(string token) + public object GetLastCommands() { List reply = new List(); foreach(CommandHistory A in master.DataStoreService.GetCommandHistory()) diff --git a/SecondBotEvents/Commands/StreamAdmin.cs b/SecondBotEvents/Commands/StreamAdmin.cs index 31bc6c4..a916859 100644 --- a/SecondBotEvents/Commands/StreamAdmin.cs +++ b/SecondBotEvents/Commands/StreamAdmin.cs @@ -6,6 +6,7 @@ using System; namespace SecondBotEvents.Commands { + [ClassInfo("Interface for streamadmin to create notecards, you will prob never need this")] public class StreamAdmin : CommandsAPI { public StreamAdmin(EventsSecondBot setmaster) : base(setmaster) diff --git a/SecondBotEvents/EventsSecondBot.cs b/SecondBotEvents/EventsSecondBot.cs index f08c41b..ca60329 100644 --- a/SecondBotEvents/EventsSecondBot.cs +++ b/SecondBotEvents/EventsSecondBot.cs @@ -11,20 +11,23 @@ namespace SecondBotEvents { static void Main(string[] args) { - LogFormater.Info("Welcome to Secondbot [Events build] version: " + AssemblyInfo.GetGitHash()); - EventsSecondBot worker = new EventsSecondBot(args); +#if (DEBUG) + new WikiMake(); +#endif + LogFormater.Info("Welcome to Secondbot [Events build] version: " + AssemblyInfo.GetGitHash()); + EventsSecondBot worker = new EventsSecondBot(args); - while(worker.Exit() == false) - { - if(worker.Ready == true) + while (worker.Exit() == false) { - worker.Status(); + if (worker.Ready == true) + { + worker.Status(); + } + Thread.Sleep(1000); } - Thread.Sleep(1000); + LogFormater.Warn("Shutdown in 5 secs"); + Thread.Sleep(5000); } - LogFormater.Warn("Shutdown in 5 secs"); - Thread.Sleep(5000); - } } public class EventsSecondBot diff --git a/SecondBotEvents/Properties/Resources.Designer.cs b/SecondBotEvents/Properties/Resources.Designer.cs new file mode 100644 index 0000000..fceacbe --- /dev/null +++ b/SecondBotEvents/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace SecondBotEvents.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("SecondBotEvents.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/SecondBotEvents/Properties/Resources.resx b/SecondBotEvents/Properties/Resources.resx new file mode 100644 index 0000000..1af7de1 --- /dev/null +++ b/SecondBotEvents/Properties/Resources.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/SecondBotEvents/SecondBotEvents.csproj b/SecondBotEvents/SecondBotEvents.csproj index dceb712..3b44039 100644 --- a/SecondBotEvents/SecondBotEvents.csproj +++ b/SecondBotEvents/SecondBotEvents.csproj @@ -9,6 +9,9 @@ Linux settings.env + + + @@ -25,4 +28,22 @@ + + + True + True + Resources.resx + + + + + ResXFileCodeGenerator + Resources.Designer.cs + + + + + Always + + \ No newline at end of file diff --git a/SecondBotEvents/Services/HttpService.cs b/SecondBotEvents/Services/HttpService.cs index 113bd5b..979ce98 100644 --- a/SecondBotEvents/Services/HttpService.cs +++ b/SecondBotEvents/Services/HttpService.cs @@ -231,6 +231,16 @@ namespace SecondBotEvents.Services } + [AttributeUsage(AttributeTargets.Class)] + public class ClassInfo : Attribute + { + public string classinfo = ""; + public ClassInfo(string classinfo) + { + this.classinfo = classinfo; + } + } + [AttributeUsage(AttributeTargets.Method)] public class About : Attribute @@ -246,7 +256,6 @@ namespace SecondBotEvents.Services public class ReturnHints : Attribute { public string hint = ""; - public bool good = true; public ReturnHints(string hint) { this.hint = hint; @@ -254,11 +263,12 @@ namespace SecondBotEvents.Services } [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] - public class ReturnHintsFailure : ReturnHints + public class ReturnHintsFailure : Attribute { - public ReturnHintsFailure(string hint) : base(hint) + public string hint = ""; + public ReturnHintsFailure(string hint) { - this.good = false; + this.hint = hint; } } diff --git a/SecondBotEvents/Static/template.html b/SecondBotEvents/Static/template.html new file mode 100644 index 0000000..7acd3c1 --- /dev/null +++ b/SecondBotEvents/Static/template.html @@ -0,0 +1,54 @@ + + + + + + [[PAGETITLE]] + + + + +
+ +
+ [[CONTENT]] +
+
+ + + diff --git a/SecondBotEvents/WikiService.cs b/SecondBotEvents/WikiService.cs new file mode 100644 index 0000000..686f38d --- /dev/null +++ b/SecondBotEvents/WikiService.cs @@ -0,0 +1,157 @@ +using OpenMetaverse.ImportExport.Collada14; +using RestSharp.Extensions; +using SecondBotEvents.Services; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using System.Reflection; +using System.Resources; +using System.Security.Policy; +using System.Text; +using System.Threading.Tasks; +using static log4net.Appender.RollingFileAppender; + +namespace SecondBotEvents +{ + public class WikiMake + { + protected SimpleIO IO = new SimpleIO(); + protected string version = ""; + protected string htmltemplate = ""; + public WikiMake() + { + IO.ChangeRoot("Static"); + htmltemplate = IO.ReadFile("template.html"); + version = AssemblyInfo.GetGitHash(); + LogFormater.Info("Creating wiki files"); + IO.ChangeRoot("wiki"); + makehome(); + } + + protected void makehome() + { + + Dictionary commandmodules = http_commands_helper.getCommandModules(); + string content = "
"; + foreach (KeyValuePair entry in commandmodules) + { + Type endpointtype = entry.Value; + string namespaceworker = entry.Key.ToLower(); + string url = namespaceworker + ".html"; + int commandcount = 0; + foreach (MethodInfo M in endpointtype.GetMethods()) + { + foreach (CustomAttributeData At in M.CustomAttributes) + { + if (At.AttributeType.Name == "About") + { + commandcount++; + break; + } + } + } + string about = entry.Value.GetAttribute().classinfo; + string card = "
" + + "
" + + "
" + namespaceworker.FirstCharToUpper() + "
" + + "

" + about + "

" + + "View " + commandcount.ToString() + " commands" + + "
" + + "
"; + content = content + card; + makecommandlist(endpointtype, namespaceworker, about); + } + makefile("index", content, "Index"); + } + + protected void makecommandlist(Type endpoint, string namespaceworker, string aboutnamespace) + { + string content = "
<- Back to command sections
" + + "

"+namespaceworker.FirstCharToUpper()+"

"+ aboutnamespace + "

" + +"
"; + content = content + ""; + content = content + ""; + foreach (MethodInfo M in endpoint.GetMethods()) + { + bool isCallable = false; + string about = ""; + foreach (CustomAttributeData At in M.CustomAttributes) + { + if (At.AttributeType.Name == "About") + { + about = M.GetAttribute().about; + isCallable = true; + break; + } + } + if(isCallable == false) + { + continue; + } + string url = "command" + M.Name.ToLower() + ".html"; + content = content + ""; + content = content + ""; + content = content + ""; + makecommandfile(namespaceworker, M, about); + } + content = content + "
CommandAbout
" + M.Name + "" + about + "
"; + makefile(namespaceworker, content, "Command list for "+ namespaceworker.FirstCharToUpper()); + } + + protected void makecommandfile(string namespaceworker, MethodInfo method, string methodabout) + { + string content = "
<- Back to "+namespaceworker.FirstCharToUpper()+"
" + + "

" + method.Name + "

" + methodabout + "

" + + "
"; + + + Dictionary hints = new Dictionary(); + foreach (ArgHints At in method.GetCustomAttributes()) + { + hints.Add(At.name, At.about); + } + + if (method.GetParameters().Length > 0) + { + content = content + "
Args
"; + content = content + ""; + content = content + ""; + foreach (ParameterInfo pram in method.GetParameters()) + { + content = content + ""; + content = content + ""; + string hinttext = ""; + if (hints.ContainsKey(pram.Name) == true) + { + hinttext = hints[pram.Name]; + } + content = content + ""; + } + content = content + "
NameHint
" + pram.Name + "" + hinttext + "
"; + } + + content = content + "
Return hints
    "; + foreach (ReturnHints At in method.GetCustomAttributes()) + { + content = content + "
  • ☑ "+At.hint+"
  • "; + } + foreach (ReturnHintsFailure At in method.GetCustomAttributes()) + { + content = content + "
  • ❌ "+ At.hint+"
  • "; + } + content = content + "
"; + makefile("command"+method.Name.ToLower(), content, "Command info for " + method.Name); + } + + protected void makefile(string file, string content, string title) + { + string pagecontent = htmltemplate; + pagecontent = pagecontent.Replace("[[PAGETITLE]]", "Secondbot [Events] command wiki / "+title); + pagecontent = pagecontent.Replace("[[BUILDVERSION]]", version); + pagecontent = pagecontent.Replace("[[BUILDDATE]]", "Wiki created:"+DateTime.Now.ToString("dd/MM/yyyy")); + pagecontent = pagecontent.Replace("[[CONTENT]]", content); + IO.WriteFile(file+".html", pagecontent); + } + } +}