From 3576958eb58b35eb9e1b38a488635a509b36d267 Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Sun, 7 Feb 2021 16:40:00 +0000 Subject: [PATCH] Replaces the doc objects with method info Much better --- CLI/HttpService/Chat.cs | 9 +- CLI/HttpService/{Secondbot.cs => Core.cs} | 122 +++-- CLI/HttpService/Group.cs | 19 +- CLI/HttpService/HttpAsService.cs | 61 ++- CLI/HttpService/Im.cs | 21 +- CLI/HttpService/Inventory.cs | 39 +- CLI/WikiMake/wikimake.cs | 544 ++++------------------ 7 files changed, 304 insertions(+), 511 deletions(-) rename CLI/HttpService/{Secondbot.cs => Core.cs} (58%) diff --git a/CLI/HttpService/Chat.cs b/CLI/HttpService/Chat.cs index 5b3c8cf..b2b94b2 100644 --- a/CLI/HttpService/Chat.cs +++ b/CLI/HttpService/Chat.cs @@ -11,10 +11,12 @@ using Newtonsoft.Json; namespace BetterSecondBot.HttpService { - public class SecondbotChat : WebApiControllerWithTokens + public class HttpApiLocalchat : WebApiControllerWithTokens { - public SecondbotChat(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HttpApiLocalchat(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + [About("fetchs the last 20 localchat messages")] + [ReturnHints("array string")] [Route(HttpVerbs.Get, "/localchathistory/{token}")] public object localchatHistory(string token) { @@ -25,6 +27,9 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("sends a message to localchat")] + [ArgHints("message","Text", "the message to send")] + [ReturnHints("array string")] [Route(HttpVerbs.Post, "/localchatsay/{token}")] public object localchatSay(string token, [FormField] string message) { diff --git a/CLI/HttpService/Secondbot.cs b/CLI/HttpService/Core.cs similarity index 58% rename from CLI/HttpService/Secondbot.cs rename to CLI/HttpService/Core.cs index cb448b9..fb6a98d 100644 --- a/CLI/HttpService/Secondbot.cs +++ b/CLI/HttpService/Core.cs @@ -13,15 +13,23 @@ using Newtonsoft.Json; namespace BetterSecondBot.HttpService { - public class SecondbotCoreWebAPi : WebApiControllerWithTokens + + + public class HttpApiCore : WebApiControllerWithTokens { protected JsonConfig config; - public SecondbotCoreWebAPi(JsonConfig myconfig, SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) + public HttpApiCore(JsonConfig myconfig, SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { config = myconfig; } + + [About("Requests a new token (Vaild for 10 mins)
to use with all other requests")] + [NeedsToken(false)] + [ReturnHints("A new token with full system scope")] + [ArgHints("authcode", "text", "the first 10 chars of SHA1(unixtime+WebUIkey)
unixtime can be +- 30 of the bots time.")] + [ArgHints("unixtimegiven", "number", "the unixtime you made this request")] [Route(HttpVerbs.Post, "/gettoken")] public Object GetToken([FormField] string authcode, [FormField] string unixtimegiven) { @@ -45,6 +53,9 @@ namespace BetterSecondBot.HttpService return BasicReply("Authcode not accepted"); } + + [About("Gets the friendslist
Formated as follows
friendreplyobject
")] + [ReturnHints("array UUID = friendreplyobject")] [Route(HttpVerbs.Get, "/friends/{token}")] public object Friends(string token) { @@ -55,6 +66,12 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("uses the AutoPilot to move to a location")] + [ReturnHints("Error Unable to AutoPilot to location")] + [ReturnHints("Accepted")] + [ArgHints("x", "URLARG", "X location to AutoPilot to")] + [ArgHints("y", "URLARG", "y location to AutoPilot to")] + [ArgHints("z", "URLARG", "z location to AutoPilot to")] [Route(HttpVerbs.Get, "/walkto/{x}/{y}/{z}/{token}")] public object WalkTo(string x, string y, string z, string token) { @@ -70,7 +87,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } - + [About("Attempts to play a gesture")] + [ReturnHints("Invaild gesture UUID for arg 1")] + [ReturnHints("Accepted")] + [ArgHints("gesture", "URLARG", "Inventory UUID of the gesture")] [Route(HttpVerbs.Get, "/gesture/{gesture}/{token}")] public object Gesture(string gesture, string token) { @@ -86,6 +106,13 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Attempt to teleport to a new region")] + [ReturnHints("Error Unable to Teleport to location")] + [ReturnHints("Accepted")] + [ArgHints("region", "URLARG", "the name of the region we are going to")] + [ArgHints("x", "URLARG", "X location to teleport to")] + [ArgHints("y", "URLARG", "y location to teleport to")] + [ArgHints("z", "URLARG", "z location to teleport to")] [Route(HttpVerbs.Get, "/teleport/{region}/{x}/{y}/{z}/{token}")] public object Teleport(string region,string x, string y, string z, string token) { @@ -101,8 +128,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } - - + [About("Fetchs the regions map tile")] + [ReturnHints("Unable to find region")] + [ReturnHints("Texture UUID")] + [ArgHints("regionname", "URLARG", "the name of the region we are fetching")] [Route(HttpVerbs.Get, "/regiontile/{regionname}/{token}")] public object Regiontile(string regionname, string token) { @@ -120,34 +149,42 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("an improved version of near me with extra details
NearMeDetails is a object formated as follows
")] + [ReturnHints("array NearMeDetails")] + [ReturnHints("Error not in a sim")] [Route(HttpVerbs.Get, "/nearmewithdetails/{token}")] public object NearmeWithDetails(string token) { - if (bot.GetClient.Network.CurrentSim != null) + if (tokens.Allow(token, getClientIP()) == true) { - List BetterNearMe = new List(); - - Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy(); - foreach (Avatar av in avcopy.Values) + if (bot.GetClient.Network.CurrentSim != null) { - if (av.ID != bot.GetClient.Self.AgentID) + List BetterNearMe = new List(); + Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy(); + foreach (Avatar av in avcopy.Values) { - NearMeDetails details = new NearMeDetails(); - details.id = av.ID.ToString(); - details.name = av.Name; - details.x = (int)Math.Round(av.Position.X); - details.y = (int)Math.Round(av.Position.Y); - details.z = (int)Math.Round(av.Position.Z); - details.range = (int)Math.Round(Vector3.Distance(av.Position,bot.GetClient.Self.SimPosition)); - BetterNearMe.Add(details); + if (av.ID != bot.GetClient.Self.AgentID) + { + NearMeDetails details = new NearMeDetails(); + details.id = av.ID.ToString(); + details.name = av.Name; + details.x = (int)Math.Round(av.Position.X); + details.y = (int)Math.Round(av.Position.Y); + details.z = (int)Math.Round(av.Position.Z); + details.range = (int)Math.Round(Vector3.Distance(av.Position, bot.GetClient.Self.SimPosition)); + BetterNearMe.Add(details); + } } + return BasicReply(JsonConvert.SerializeObject(BetterNearMe)); } - return BasicReply(JsonConvert.SerializeObject(BetterNearMe)); + return BasicReply("Error not in a sim"); } return BasicReply("Token not accepted"); } - + [About("returns a list of all known avatars nearby")] + [ReturnHints("array UUID = Name")] + [ReturnHints("Error not in a sim")] [Route(HttpVerbs.Get, "/nearme/{token}")] public object Nearme(string token) { @@ -171,12 +208,19 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Used to check HTTP connections")] + [ReturnHints("world")] + [NeedsToken(false)] [Route(HttpVerbs.Get, "/hello")] public object Hello() { return BasicReply("world"); } + + [About("Removes the given token from the accepted token pool")] + [ReturnHints("Failed to remove token")] + [ReturnHints("ok")] [Route(HttpVerbs.Get, "/logout/{token}")] public object Logout(string token) { @@ -187,6 +231,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + + + [About("Fetchs the current bot")] + [ReturnHints("The build ID of the bot")] [Route(HttpVerbs.Get, "/version/{token}")] public object Version(string token) { @@ -197,6 +245,8 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Fetchs the name of the bot")] + [ReturnHints("Firstname Lastname")] [Route(HttpVerbs.Get, "/name/{token}")] public object Name(string token) { @@ -207,32 +257,48 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Fetchs the current region name")] + [ReturnHints("Regionname")] + [ReturnHints("Error not in a sim")] [Route(HttpVerbs.Get, "/regionname/{token}")] public object Regionname(string token) { if (tokens.Allow(token, getClientIP()) == true) { - return BasicReply(bot.GetClient.Network.CurrentSim.Name); + if(bot.GetClient.Network.CurrentSim != null) + { + return BasicReply(bot.GetClient.Network.CurrentSim.Name); + } + return BasicReply("Error not in a sim"); } return BasicReply("Token not accepted"); } - + [About("Fetchs the current location of the bot")] + [ReturnHints("array of X,Y,Z values")] + [ReturnHints("Error not in a sim")] [Route(HttpVerbs.Get, "/location/{token}")] public object Location(string token) { if (tokens.Allow(token, getClientIP()) == true) { - Dictionary pos = new Dictionary(); - pos.Add("x",(int)Math.Round(bot.GetClient.Self.SimPosition.X)); - pos.Add("y", (int)Math.Round(bot.GetClient.Self.SimPosition.Y)); - pos.Add("z", (int)Math.Round(bot.GetClient.Self.SimPosition.Z)); - return BasicReply(JsonConvert.SerializeObject(pos)); + if (bot.GetClient.Network.CurrentSim != null) + { + Dictionary pos = new Dictionary(); + pos.Add("x", (int)Math.Round(bot.GetClient.Self.SimPosition.X)); + pos.Add("y", (int)Math.Round(bot.GetClient.Self.SimPosition.Y)); + pos.Add("z", (int)Math.Round(bot.GetClient.Self.SimPosition.Z)); + return BasicReply(JsonConvert.SerializeObject(pos)); + } + return BasicReply("Error not in a sim"); } return BasicReply("Token not accepted"); } + [About("Makes a request to the core commands lib
See LSL example on how to create a core command auth code")] + [ArgHints("Request Body", "JsonObject", "Command: string
Args: string[]
AuthCode: string")] + [ReturnHints("accepted")] [Route(HttpVerbs.Post, "/command/{token}")] public async Task command(string token) { diff --git a/CLI/HttpService/Group.cs b/CLI/HttpService/Group.cs index b0fb945..c16da48 100644 --- a/CLI/HttpService/Group.cs +++ b/CLI/HttpService/Group.cs @@ -11,10 +11,12 @@ using Newtonsoft.Json; namespace BetterSecondBot.HttpService { - public class SecondbotGroup : WebApiControllerWithTokens + public class HttpApiGroup : WebApiControllerWithTokens { - public SecondbotGroup(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HttpApiGroup(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + [About("fetchs a list of all groups known to the bot")] + [ReturnHints("array UUID=name")] [Route(HttpVerbs.Get, "/listgroups/{token}")] public object listgroups(string token) { @@ -30,6 +32,8 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("fetchs a list of all groups with unread messages")] + [ReturnHints("array UUID")] [Route(HttpVerbs.Get, "/listgroupswithunread/{token}")] public object listgroupswithunread(string group, string token) { @@ -40,6 +44,8 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("checks if there are any groups with unread messages")] + [ReturnHints("True|False")] [Route(HttpVerbs.Get, "/haveunreadgroupchat/{token}")] public object haveunreadgroupchat(string token) { @@ -50,6 +56,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("fetchs the groupchat history")] + [ArgHints("group", "URLARG", "UUID of the group")] + [ReturnHints("Group UUID invaild")] + [ReturnHints("Group Chat")] [Route(HttpVerbs.Get, "/getgroupchat/{group}/{token}")] public object getgroupchat(string group, string token) { @@ -64,6 +74,11 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("sends a message to the groupchat")] + [ArgHints("group", "URLARG", "UUID of the group")] + [ArgHints("message", "Text", "the message to send")] + [ReturnHints("Group UUID invaild")] + [ReturnHints("Processing")] [Route(HttpVerbs.Post, "/sendgroupchat/{group}/{token}")] public object sendgroupchat(string group, string token, [FormField] string message) { diff --git a/CLI/HttpService/HttpAsService.cs b/CLI/HttpService/HttpAsService.cs index e1cd5ec..715dc1c 100644 --- a/CLI/HttpService/HttpAsService.cs +++ b/CLI/HttpService/HttpAsService.cs @@ -49,19 +49,19 @@ namespace BetterSecondBot.HttpService // .WithRegexRules("HTTP exception 404") //) .WithWebApi("/inventory", m => m - .WithController(() => new SecondbotInventory(Bot, Tokens)) + .WithController(() => new HttpApiInventory(Bot, Tokens)) ) .WithWebApi("/chat", m => m - .WithController(() => new SecondbotChat(Bot, Tokens)) + .WithController(() => new HttpApiLocalchat(Bot, Tokens)) ) .WithWebApi("/groups", m => m - .WithController(() => new SecondbotGroup(Bot, Tokens)) + .WithController(() => new HttpApiGroup(Bot, Tokens)) ) .WithWebApi("/ims", m => m - .WithController(() => new SecondbotIm(Bot, Tokens)) + .WithController(() => new HttpApiIM(Bot, Tokens)) ) .WithWebApi("/core", m => m - .WithController(() => new SecondbotCoreWebAPi(Config, Bot, Tokens))) + .WithController(() => new HttpApiCore(Config, Bot, Tokens))) .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" }))); return server; @@ -69,6 +69,55 @@ namespace BetterSecondBot.HttpService } + + + [AttributeUsage(AttributeTargets.Method)] + public class About : Attribute + { + public string about = ""; + public About(string about) + { + this.about = about; + } + } + + [AttributeUsage(AttributeTargets.Method)] + public class NeedsToken : Attribute + { + public bool needsToken = true; + public NeedsToken(bool needsToken) + { + this.needsToken = needsToken; + } + } + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class ReturnHints : Attribute + { + public string hint = ""; + public ReturnHints(string hint) + { + this.hint = hint; + } + } + + [AttributeUsage(AttributeTargets.Method, AllowMultiple = true)] + public class ArgHints : Attribute + { + public string name = ""; + public string typename = ""; + public string about = ""; + + public ArgHints(string name,string typename, string about) + { + this.name = name; + this.typename = typename; + this.about = about; + } + } + + + public class TokenStorage { protected Dictionary tokens = new Dictionary(); @@ -150,6 +199,8 @@ namespace BetterSecondBot.HttpService { protected TokenStorage tokens; protected SecondBot bot; + public bool needsToken { get; set; } + protected Object BasicReply(string input) { diff --git a/CLI/HttpService/Im.cs b/CLI/HttpService/Im.cs index b30db6e..a2dec57 100644 --- a/CLI/HttpService/Im.cs +++ b/CLI/HttpService/Im.cs @@ -11,10 +11,13 @@ using Newtonsoft.Json; namespace BetterSecondBot.HttpService { - public class SecondbotIm : WebApiControllerWithTokens + public class HttpApiIM : WebApiControllerWithTokens { - public SecondbotIm(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HttpApiIM(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("gets a full list of all chat windows")] + [ReturnHints("array UUID = Name")] [Route(HttpVerbs.Get, "/chatwindows/{token}")] public object chatwindows(string token) { @@ -25,6 +28,8 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("gets a list of chat windows with unread messages")] + [ReturnHints("array of UUID")] [Route(HttpVerbs.Get, "/listwithunread/{token}")] public object listwithunread(string group, string token) { @@ -43,6 +48,8 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("gets if there are any unread im messages at all")] + [ReturnHints("True|False")] [Route(HttpVerbs.Get, "/haveunreadims/{token}")] public object haveunreadims(string token) { @@ -62,6 +69,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("gets the chat from the selected window")] + [ArgHints("window", "URLARG", "the UUID of the chat window")] + [ReturnHints("Window UUID invaild")] + [ReturnHints("Array of text")] [Route(HttpVerbs.Get, "/getimchat/{window}/{token}")] public object getimchat(string window, string token) { @@ -76,8 +87,12 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("sends a im to the selected avatar")] + [ArgHints("avatar", "URLARG", "a UUID or Firstname Lastname")] + [ArgHints("message", "Text", "the message to send")] + [ReturnHints("ok")] [Route(HttpVerbs.Post, "/sendimchat/{avatar}/{token}")] - public object sendgroupchat(string avatar, string token, [FormField] string message) + public object sendimchat(string avatar, string token, [FormField] string message) { if (tokens.Allow(token, getClientIP()) == true) { diff --git a/CLI/HttpService/Inventory.cs b/CLI/HttpService/Inventory.cs index 0093f71..51fea85 100644 --- a/CLI/HttpService/Inventory.cs +++ b/CLI/HttpService/Inventory.cs @@ -10,11 +10,13 @@ using OpenMetaverse; namespace BetterSecondBot.HttpService { - public class SecondbotInventory : WebApiControllerWithTokens + public class HttpApiInventory : WebApiControllerWithTokens { - public SecondbotInventory(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } - + public HttpApiInventory(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + [About("rezs the item at the bots current location")] + [ReturnHints("True|False")] + [ArgHints("item", "URLARG", "UUID of item to rez")] [Route(HttpVerbs.Get, "/rezobject/{item}/{token}")] public object rezobject(string item, string token, [FormField] string newname) { @@ -26,7 +28,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } - + [About("renames a folder or inventory item")] + [ReturnHints("True|False")] + [ArgHints("item", "URLARG", "UUID of item/folder to name")] + [ArgHints("newname", "Text", "What we are changing it to")] [Route(HttpVerbs.Post, "/rename/{item}/{token}")] public object rename(string item, string token, [FormField] string newname) { @@ -38,6 +43,10 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("converts a inventory uuid to a realworld uuid
Needed for texture preview")] + [ReturnHints("Asset UUID")] + [ReturnHints("Failed")] + [ArgHints("item", "URLARG", "inventory level UUID of item")] [Route(HttpVerbs.Get, "/realuuid/{item}/{token}")] public object realuuid(string item, string token) { @@ -56,6 +65,11 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("sends a item to an avatar")] + [ReturnHints("True|False")] + [ReturnHints("Failed")] + [ArgHints("item", "URLARG", "UUID of item")] + [ArgHints("avatar", "URLARG", "a UUID or Firstname Lastname")] [Route(HttpVerbs.Get, "/send/{item}/{avatar}/{token}")] public object send(string item, string avatar, string token) { @@ -71,6 +85,12 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Removes a item/folder from inventory (Make sure you set the isfolder flag correctly!)")] + [ReturnHints("True|False")] + [ReturnHints("Failed - isfolder must be True or False")] + [ReturnHints("Failed - item must be a vaild UUID")] + [ArgHints("item", "URLARG", "UUID of item")] + [ArgHints("isfolder", "URLARG", "True or False if this is a folder")] [Route(HttpVerbs.Get, "/delete/{item}/{isfolder}/{token}")] public object delete(string item,string isfolder, string token) { @@ -92,6 +112,9 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Requests the inventory folder layout as a json object InventoryMapFolder
Formated as follows
InventoryMapItem
  • id: UUID
  • name: String
  • subfolders: InventoryMapFolder[]
")] + [ReturnHints("array of InventoryMapFolder")] + [ReturnHints("Error")] [Route(HttpVerbs.Get, "/folders/{token}")] public object folders(string token) { @@ -99,11 +122,15 @@ namespace BetterSecondBot.HttpService { string reply = HelperInventory.MapFolderJson(bot); if(reply != null) return BasicReply(reply); - return BasicReply("error"); + return BasicReply("Error"); } return BasicReply("Token not accepted"); } + [About("Requests the contents of a folder as an array of InventoryMapItem
Formated as follows
InventoryMapItem
  • id: UUID
  • name: String
  • typename: String
")] + [ReturnHints("array of InventoryMapItem")] + [ReturnHints("Invaild folder UUID")] + [ArgHints("folderUUID", "URLARG", "the folder to fetch (Found via: inventory/folders)")] [Route(HttpVerbs.Get, "/contents/{folderUUID}/{token}")] public object Contents(string folderUUID, string token) { @@ -119,8 +146,6 @@ namespace BetterSecondBot.HttpService } - } - } diff --git a/CLI/WikiMake/wikimake.cs b/CLI/WikiMake/wikimake.cs index ca42921..1f3829e 100644 --- a/CLI/WikiMake/wikimake.cs +++ b/CLI/WikiMake/wikimake.cs @@ -1,8 +1,10 @@ -using BetterSecondBotShared.API; +using BetterSecondBot.HttpService; +using BetterSecondBotShared.API; using BetterSecondBotShared.IO; using BetterSecondBotShared.Json; using BetterSecondBotShared.logs; using BetterSecondBotShared.Static; +using EmbedIO; using System; using System.Collections.Generic; using System.Reflection; @@ -487,57 +489,83 @@ namespace BetterSecondBot.WikiMake public class HTTPendpoint { protected List endpoints = new List(); + + + public void createEndpoint(string name, Type Api) + { + Endpoint Endpoint = new Endpoint(); + Endpoint.name = name; + foreach (MethodInfo M in Api.GetMethods()) + { + APIcall C = new APIcall(); + CustomAttributeData httpverb = null; + CustomAttributeData NeedsToken = null; + CustomAttributeData About = null; + List ArgHints = new List(); + List ReturnValues = new List(); + + foreach (CustomAttributeData At in M.CustomAttributes) + { + if (At.AttributeType.Name == "RouteAttribute") + { + httpverb = At; + } + else if (At.AttributeType.Name == "NeedsToken") + { + NeedsToken = At; + } + else if (At.AttributeType.Name == "About") + { + About = At; + } + else if (At.AttributeType.Name == "ArgHints") + { + ArgHints.Add(At); + } + else if (At.AttributeType.Name == "ReturnHints") + { + ReturnValues.Add(At); + } + } + if (httpverb != null) + { + C.name = M.Name.ToLowerInvariant(); + C.type = "Post"; + C.about = "Http interface command about missing"; + if (About != null) + { + C.about = About.ConstructorArguments[0].Value.ToString(); + } + if (httpverb.ConstructorArguments[0].Value is HttpVerbs.Get) + { + C.type = "Get"; + } + C.RequiresToken = true; + if (NeedsToken != null) + { + C.RequiresToken = (bool)NeedsToken.ConstructorArguments[0].Value; + } + foreach (CustomAttributeData cad in ArgHints) + { + C.values.Add(cad.ConstructorArguments[0].Value.ToString(), new KeyValuePair(cad.ConstructorArguments[1].Value.ToString(), cad.ConstructorArguments[2].Value.ToString())); + } + foreach (CustomAttributeData cad in ReturnValues) + { + C.returns.Add(cad.ConstructorArguments[0].Value.ToString()); + } + C.Setup(); + Endpoint.callable.Add(C); + } + } + endpoints.Add(Endpoint); + } public HTTPendpoint() { - Endpoint core = new Endpoint(); - core.name = "core"; - core.callable.Add(new gettoken()); - core.callable.Add(new logout()); - core.callable.Add(new version()); - core.callable.Add(new name()); - core.callable.Add(new command()); - core.callable.Add(new friends()); - core.callable.Add(new nearme()); - core.callable.Add(new hello()); - core.callable.Add(new regiontile()); - core.callable.Add(new location()); - core.callable.Add(new regionname()); - core.callable.Add(new nearmewithdetails()); - core.callable.Add(new walkto()); - core.callable.Add(new teleport()); - core.callable.Add(new gesture()); - endpoints.Add(core); - Endpoint inventory = new Endpoint(); - inventory.name = "inventory"; - inventory.callable.Add(new contents()); - inventory.callable.Add(new folders()); - inventory.callable.Add(new rename()); - inventory.callable.Add(new realuuid()); - inventory.callable.Add(new send()); - inventory.callable.Add(new delete()); - inventory.callable.Add(new rezobject()); - endpoints.Add(inventory); - Endpoint im = new Endpoint(); - im.name = "im"; - im.callable.Add(new chatwindows()); - im.callable.Add(new listwithunread()); - im.callable.Add(new haveunreadims()); - im.callable.Add(new getimchat()); - im.callable.Add(new sendimchat()); - endpoints.Add(im); - Endpoint group = new Endpoint(); - group.name = "group"; - group.callable.Add(new listgroups()); - group.callable.Add(new listgroupswithunread()); - group.callable.Add(new haveunreadgroupchat()); - group.callable.Add(new getgroupchat()); - group.callable.Add(new sendgroupchat()); - endpoints.Add(group); - Endpoint chat = new Endpoint(); - chat.name = "chat"; - chat.callable.Add(new localchathistory()); - chat.callable.Add(new localchatsay()); - endpoints.Add(chat); + createEndpoint("core", typeof(HttpApiCore)); + createEndpoint("inventory", typeof(HttpApiInventory)); + createEndpoint("im", typeof(HttpApiIM)); + createEndpoint("group", typeof(HttpApiGroup)); + createEndpoint("chat", typeof(HttpApiLocalchat)); } public string getCommandMethod(string endpoint, string command) @@ -690,19 +718,15 @@ namespace BetterSecondBot.WikiMake public List callable = new List(); } - abstract public class APIcall + public class APIcall { - public string name { get { return GetType().Name.ToLowerInvariant(); } } + public string name { get; set; } public string type = "get"; public string about = "A API call that is missing its about value"; public Dictionary> values = new Dictionary>(); public List returns = new List(); public bool RequiresToken = true; - public APIcall() - { - Setup(); - } public virtual void Setup() { if (RequiresToken == true) @@ -717,412 +741,4 @@ namespace BetterSecondBot.WikiMake } } } - - abstract public class postAPIcall : APIcall - { - public override void Setup() - { - type = "post"; - base.Setup(); - } - } - - public class gettoken : postAPIcall - { - public override void Setup() - { - RequiresToken = false; - about = "Requests a new token (Vaild for 10 mins)
to use with all other requests"; - values.Add("Authcode", new KeyValuePair("string", "the first 10 chars of SHA1(unixtime+WebUIkey)
unixtime can be +- 30 of the bots time.")); - returns = new List(); - returns.Add("Authcode not accepted"); - returns.Add("New API Token"); - base.Setup(); - } - } - - public class logout : APIcall - { - public override void Setup() - { - about = "A API call that is missing its about value"; - returns.Add("ok"); - returns.Add("Failed to remove token"); - base.Setup(); - } - } - - public class version : APIcall - { - public override void Setup() - { - about = "Gets the bots build version"; - returns.Add("Bot build version"); - base.Setup(); - } - } - - public class friends : APIcall - { - public override void Setup() - { - about = "Gets the friendslist
Formated as follows
friendreplyobject
  • name: String
  • id: String
  • online: bool
"; - returns.Add("array UUID = friendreplyobject"); - base.Setup(); - } - } - - public class nearme : APIcall - { - public override void Setup() - { - about = "returns a list of all known avatars near (same sim)>"; - returns.Add("array UUID = Name"); - base.Setup(); - } - } - - public class hello : APIcall - { - public override void Setup() - { - RequiresToken = false; - about = "used to test you can talk to the api but mostly pointless."; - returns.Add("world"); - base.Setup(); - } - } - - public class name : APIcall - { - public override void Setup() - { - about = "Gets the name of the bot"; - returns.Add("Fistname Lastname"); - base.Setup(); - } - } - - public class gesture : APIcall - { - public override void Setup() - { - about = "Attempts to play a gesture"; - values.Add("gesture", new KeyValuePair("URLARG", "UUID of the gesture")); - returns.Add("Accepted"); - returns.Add("Invaild gesture UUID for arg 1"); - base.Setup(); - } - } - - public class command : postAPIcall - { - public override void Setup() - { - about = "Makes a request to the core commands lib"; - values.Add( - "body", - new KeyValuePair( - "JsonObject", - "A JSON object formated as follows
Command: string
Args: string[]
AuthCode: string
========
See LSL example on how to create a core command auth code") - ); - returns.Add("accepted"); - base.Setup(); - } - } - - public class contents : APIcall - { - public override void Setup() - { - about = "Requests the contents of a folder as an array of InventoryMapItem
Formated as follows
InventoryMapItem
  • id: UUID
  • name: String
  • typename: String
"; - values.Add( - "folderUUID", - new KeyValuePair( - "URLARG", - "the folder to fetch (Found via: inventory/folders)") - ); - returns.Add("array of InventoryMapItem"); - base.Setup(); - } - } - - public class folders : APIcall - { - public override void Setup() - { - about = "Requests the inventory folder layout as a json object InventoryMapFolder
Formated as follows
InventoryMapItem
  • id: UUID
  • name: String
  • subfolders: InventoryMapFolder[]
"; - returns.Add("array of InventoryMapFolder"); - base.Setup(); - } - } - - public class rename : postAPIcall - { - public override void Setup() - { - about = "renames a folder or inventory item"; - returns.Add("true|false"); - values.Add("item", new KeyValuePair("URLARG", "UUID of the item/folder we are working on")); - values.Add("newname", new KeyValuePair("string", "What we are setting")); - base.Setup(); - } - } - - public class realuuid : APIcall - { - public override void Setup() - { - about = "converts a inventory uuid to a realworld uuid
Needed for texture preview"; - returns.Add("Failed"); - returns.Add("UUID"); - values.Add("item", new KeyValuePair("URLARG", "UUID of the item/folder we are working on")); - base.Setup(); - } - } - - public class send : APIcall - { - public override void Setup() - { - about = "sends a item to an avatar"; - returns.Add("Failed"); - returns.Add("UUID"); - values.Add("item", new KeyValuePair("URLARG", "UUID of the item we are working on")); - values.Add("avatar", new KeyValuePair("URLARG", "a UUID or Firstname Lastname")); - base.Setup(); - } - } - - public class delete : APIcall - { - public override void Setup() - { - about = "Removes a item/folder from inventory (Make sure you set the isfolder flag correctly!)"; - returns.Add("Failed"); - returns.Add("UUID"); - values.Add("item", new KeyValuePair("URLARG", "UUID of the item/folder we are working on")); - values.Add("isfolder", new KeyValuePair("URLARG", "true or false if this is a folder")); - base.Setup(); - } - } - - public class chatwindows : APIcall - { - public override void Setup() - { - about = "gets a full list of all chat windows"; - returns.Add("array UUID = Name"); - base.Setup(); - } - } - - public class listwithunread : APIcall - { - public override void Setup() - { - about = "gets a list of chat windows with unread messages"; - returns.Add("array of UUID"); - base.Setup(); - } - } - - public class haveunreadims : APIcall - { - public override void Setup() - { - about = "gets if there are any unread im messages at all"; - returns.Add("true|false"); - base.Setup(); - } - } - - public class getimchat : APIcall - { - public override void Setup() - { - about = "gets the chat from the selected window"; - values.Add("window", new KeyValuePair("URLARG", "the UUID of the chat window")); - returns.Add("Chat contents"); - returns.Add("Window UUID invaild"); - base.Setup(); - } - } - - public class sendimchat : postAPIcall - { - public override void Setup() - { - about = "sends a im to the selected avatar"; - values.Add("avatar", new KeyValuePair("URLARG", "a UUID or Firstname Lastname")); - values.Add("message", new KeyValuePair("string", "the message to send")); - returns.Add("ok"); - base.Setup(); - } - } - - public class listgroups : APIcall - { - public override void Setup() - { - about = "fetchs a list of all groups known to the bot"; - returns.Add("array UUID=name"); - base.Setup(); - } - } - - public class listgroupswithunread : APIcall - { - public override void Setup() - { - about = "fetchs a list of all groups with unread messages"; - returns.Add("array UUID"); - base.Setup(); - } - } - - public class haveunreadgroupchat : APIcall - { - public override void Setup() - { - about = "checks if there are any groups with unread messages"; - returns.Add("true|false"); - base.Setup(); - } - } - - public class getgroupchat : APIcall - { - public override void Setup() - { - about = "fetchs the groupchat history"; - values.Add("group", new KeyValuePair("URLARG", "UUID of the group")); - returns.Add("Group UUID invaild"); - returns.Add("Group Chat"); - base.Setup(); - } - } - - public class sendgroupchat : postAPIcall - { - public override void Setup() - { - about = "sends a message to the groupchat"; - values.Add("group", new KeyValuePair("URLARG", "UUID of the group")); - values.Add("message ", new KeyValuePair("string", "the message to send")); - returns.Add("Group UUID invaild"); - returns.Add("Processing"); - base.Setup(); - } - } - - public class localchathistory : APIcall - { - public override void Setup() - { - about = "fetchs the last 20 localchat messages"; - returns.Add("array string"); - base.Setup(); - } - } - - public class location : APIcall - { - public override void Setup() - { - about = "Fetchs the current location of the bot"; - returns.Add("array of X,Y,Z values"); - base.Setup(); - } - } - - public class walkto : APIcall - { - public override void Setup() - { - about = "uses the AutoPilot to move to a location"; - values.Add("x", new KeyValuePair("URLARG", "X location to AutoPilot to")); - values.Add("y", new KeyValuePair("URLARG", "Y location to AutoPilot to")); - values.Add("z", new KeyValuePair("URLARG", "Z location to AutoPilot to")); - returns.Add("Error Unable to AutoPilot to location"); - returns.Add("Accepted"); - base.Setup(); - } - } - - - public class teleport : APIcall - { - public override void Setup() - { - about = "uses the AutoPilot to move to a location"; - values.Add("region", new KeyValuePair("URLARG", "the name of the region we are going to")); - values.Add("x", new KeyValuePair("URLARG", "X location")); - values.Add("y", new KeyValuePair("URLARG", "Y location")); - values.Add("z", new KeyValuePair("URLARG", "Z location")); - returns.Add("Error Unable to Teleport to location"); - returns.Add("Accepted"); - base.Setup(); - } - } - - public class regionname : APIcall - { - public override void Setup() - { - about = "Fetchs the current region name"; - returns.Add("string regionname"); - base.Setup(); - } - } - - public class nearmewithdetails : APIcall - { - public override void Setup() - { - about = "an improved version of near me with extra details
NearMeDetails is a object formated as follows
  • id
  • name
  • x
  • y
  • z
  • range
"; - returns.Add("array NearMeDetails"); - base.Setup(); - } - } - - - - public class regiontile : APIcall - { - public override void Setup() - { - about = "Fetchs the regions map tile"; - values.Add("region", new KeyValuePair("URLARG", "string name of region")); - returns.Add("Unable to find region"); - returns.Add("Texture UUID"); - base.Setup(); - } - } - - public class rezobject : APIcall - { - public override void Setup() - { - about = "rezs the item at the bots current location"; - values.Add("item", new KeyValuePair("URLARG", "UUID of item to rez")); - returns.Add("true|false"); - base.Setup(); - } - } - - - public class localchatsay : postAPIcall - { - public override void Setup() - { - about = "sends a message to localchat"; - values.Add("message ", new KeyValuePair("string", "the message to send")); - returns.Add("see->localchathistory"); - base.Setup(); - } - } - - - }