From 82b451c15e9ecd9fbc0348b70d71b74042521261 Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Tue, 16 Feb 2021 12:44:16 +0000 Subject: [PATCH 1/5] wip --- BetterSecondbot/HttpService/Animation.cs | 79 +++++ BetterSecondbot/HttpService/Avatars.cs | 112 +++++++ BetterSecondbot/HttpService/Chat.cs | 54 +++- BetterSecondbot/HttpService/Core.cs | 105 +----- BetterSecondbot/HttpService/Dialogs.cs | 99 ++++++ BetterSecondbot/HttpService/Discord.cs | 105 ++++++ BetterSecondbot/HttpService/Estate.cs | 8 +- BetterSecondbot/HttpService/HttpAsService.cs | 64 +++- BetterSecondbot/HttpService/Im.cs | 82 ++--- BetterSecondbot/WikiMake/wikimake.cs | 5 - Core/Commands/Animation/PlayGesture.cs | 25 -- Core/Commands/Animation/addToAnimations.cs | 33 -- Core/Commands/Animation/resetAnimations.cs | 12 - Core/Commands/Avatars/NearMe.cs | 35 -- Core/Commands/Avatars/PayAvatar.cs | 40 --- Core/Commands/Chat/LocalChatHistory.cs | 19 -- Core/Commands/Chat/im.cs | 35 -- Core/Commands/Chat/say.cs | 44 --- Core/Commands/Dialogs/DialogRelay.cs | 46 --- Core/Commands/Dialogs/DialogResponce.cs | 25 -- Core/Commands/Dialogs/DialogTrack.cs | 22 -- Core/Commands/DiscordAPI/AddRole.cs | 53 ---- Core/Commands/DiscordAPI/Ban_Member.cs | 54 ---- Core/RLV/Blacklist/getblacklist.cs | 75 ----- Core/RLV/Blacklist/versionnumbl.cs | 31 -- Core/RLV/Camera/camavdist.cs | 11 - Core/RLV/Camera/camdistmax.cs | 10 - Core/RLV/Camera/camdistmin.cs | 10 - Core/RLV/Camera/camdrawalphamax.cs | 10 - Core/RLV/Camera/camdrawalphamin.cs | 10 - Core/RLV/Camera/camdrawcolor.cs | 10 - Core/RLV/Camera/camdrawmax.cs | 10 - Core/RLV/Camera/camdrawmin.cs | 10 - Core/RLV/Camera/camtextures.cs | 10 - Core/RLV/Camera/camunlock.cs | 10 - Core/RLV/Camera/camzoommax.cs | 10 - Core/RLV/Camera/camzoommin.cs | 10 - Core/RLV/Camera/getcam_avdistmax.cs | 11 - Core/RLV/Camera/getcam_avdistmin.cs | 12 - Core/RLV/Camera/getcam_fov.cs | 12 - Core/RLV/Camera/getcam_fovmax.cs | 12 - Core/RLV/Camera/getcam_fovmin.cs | 11 - Core/RLV/Camera/getcam_zoommin.cs | 12 - Core/RLV/Camera/setcam_avdistmax.cs | 11 - Core/RLV/Camera/setcam_avdistmin.cs | 12 - Core/RLV/Camera/setcam_fov.cs | 11 - Core/RLV/Camera/setcam_fovmax.cs | 11 - Core/RLV/Camera/setcam_fovmin.cs | 11 - Core/RLV/Camera/setcam_textures.cs | 11 - Core/RLV/Camera/setcam_unlock.cs | 12 - Core/RLV/Chat/chatnormal.cs | 10 - Core/RLV/Chat/chatshout.cs | 10 - Core/RLV/Chat/chatwhisper.cs | 10 - Core/RLV/Chat/recvchat.cs | 37 --- Core/RLV/Chat/recvchat_sec.cs | 10 - Core/RLV/Chat/recvchatfrom.cs | 10 - Core/RLV/Chat/redirchat.cs | 10 - Core/RLV/Chat/sendchat.cs | 10 - Core/RLV/Chat/sendgesture.cs | 10 - Core/RLV/Emotes/emote.cs | 10 - Core/RLV/Emotes/recvemote.cs | 38 --- Core/RLV/Emotes/recvemote_sec.cs | 11 - Core/RLV/Emotes/rediremote.cs | 11 - Core/RLV/InstantMessages/sendim.cs | 37 --- Core/RLV/InstantMessages/sendim_sec.cs | 18 -- Core/RLV/Miscellaneous/clear.cs | 17 - Core/RLV/Miscellaneous/getstatus.cs | 51 --- Core/RLV/Miscellaneous/getstatusall.cs | 58 ---- Core/RLV/Miscellaneous/notify.cs | 43 --- Core/RLV/Miscellaneous/permissive.cs | 28 -- Core/RLV/Movement/adjustheight.cs | 44 --- Core/RLV/Movement/alwaysrun.cs | 10 - Core/RLV/Movement/fly.cs | 10 - Core/RLV/Movement/setrot.cs | 23 -- Core/RLV/Movement/temprun.cs | 11 - Core/RLV/PrivateChannels/sendchannel.cs | 10 - .../RLV/PrivateChannels/sendchannel_except.cs | 11 - Core/RLV/PrivateChannels/sendchannel_sec.cs | 11 - Core/RLV/RLV_commandlib.cs | 230 -------------- Core/RLV/Sitting/getsitid.cs | 31 -- Core/RLV/Sitting/sit.cs | 30 -- Core/RLV/Sitting/unsit.cs | 23 -- Core/RLV/Version/version.cs | 27 -- Core/RLV/Version/versionnew.cs | 27 -- Core/RLV/Version/versionnum.cs | 27 -- Core/bottypes/AVstorageBot.cs | 84 ----- Core/bottypes/RLVbot.cs | 298 ------------------ Core/bottypes/chatrelay.cs | 2 +- Core/bottypes/loadorder.txt | 3 +- 89 files changed, 556 insertions(+), 2327 deletions(-) create mode 100644 BetterSecondbot/HttpService/Animation.cs create mode 100644 BetterSecondbot/HttpService/Avatars.cs create mode 100644 BetterSecondbot/HttpService/Dialogs.cs create mode 100644 BetterSecondbot/HttpService/Discord.cs delete mode 100644 Core/Commands/Animation/PlayGesture.cs delete mode 100644 Core/Commands/Animation/addToAnimations.cs delete mode 100644 Core/Commands/Animation/resetAnimations.cs delete mode 100644 Core/Commands/Avatars/NearMe.cs delete mode 100644 Core/Commands/Avatars/PayAvatar.cs delete mode 100644 Core/Commands/Chat/LocalChatHistory.cs delete mode 100644 Core/Commands/Chat/im.cs delete mode 100644 Core/Commands/Chat/say.cs delete mode 100644 Core/Commands/Dialogs/DialogRelay.cs delete mode 100644 Core/Commands/Dialogs/DialogResponce.cs delete mode 100644 Core/Commands/Dialogs/DialogTrack.cs delete mode 100644 Core/Commands/DiscordAPI/AddRole.cs delete mode 100644 Core/Commands/DiscordAPI/Ban_Member.cs delete mode 100644 Core/RLV/Blacklist/getblacklist.cs delete mode 100644 Core/RLV/Blacklist/versionnumbl.cs delete mode 100644 Core/RLV/Camera/camavdist.cs delete mode 100644 Core/RLV/Camera/camdistmax.cs delete mode 100644 Core/RLV/Camera/camdistmin.cs delete mode 100644 Core/RLV/Camera/camdrawalphamax.cs delete mode 100644 Core/RLV/Camera/camdrawalphamin.cs delete mode 100644 Core/RLV/Camera/camdrawcolor.cs delete mode 100644 Core/RLV/Camera/camdrawmax.cs delete mode 100644 Core/RLV/Camera/camdrawmin.cs delete mode 100644 Core/RLV/Camera/camtextures.cs delete mode 100644 Core/RLV/Camera/camunlock.cs delete mode 100644 Core/RLV/Camera/camzoommax.cs delete mode 100644 Core/RLV/Camera/camzoommin.cs delete mode 100644 Core/RLV/Camera/getcam_avdistmax.cs delete mode 100644 Core/RLV/Camera/getcam_avdistmin.cs delete mode 100644 Core/RLV/Camera/getcam_fov.cs delete mode 100644 Core/RLV/Camera/getcam_fovmax.cs delete mode 100644 Core/RLV/Camera/getcam_fovmin.cs delete mode 100644 Core/RLV/Camera/getcam_zoommin.cs delete mode 100644 Core/RLV/Camera/setcam_avdistmax.cs delete mode 100644 Core/RLV/Camera/setcam_avdistmin.cs delete mode 100644 Core/RLV/Camera/setcam_fov.cs delete mode 100644 Core/RLV/Camera/setcam_fovmax.cs delete mode 100644 Core/RLV/Camera/setcam_fovmin.cs delete mode 100644 Core/RLV/Camera/setcam_textures.cs delete mode 100644 Core/RLV/Camera/setcam_unlock.cs delete mode 100644 Core/RLV/Chat/chatnormal.cs delete mode 100644 Core/RLV/Chat/chatshout.cs delete mode 100644 Core/RLV/Chat/chatwhisper.cs delete mode 100644 Core/RLV/Chat/recvchat.cs delete mode 100644 Core/RLV/Chat/recvchat_sec.cs delete mode 100644 Core/RLV/Chat/recvchatfrom.cs delete mode 100644 Core/RLV/Chat/redirchat.cs delete mode 100644 Core/RLV/Chat/sendchat.cs delete mode 100644 Core/RLV/Chat/sendgesture.cs delete mode 100644 Core/RLV/Emotes/emote.cs delete mode 100644 Core/RLV/Emotes/recvemote.cs delete mode 100644 Core/RLV/Emotes/recvemote_sec.cs delete mode 100644 Core/RLV/Emotes/rediremote.cs delete mode 100644 Core/RLV/InstantMessages/sendim.cs delete mode 100644 Core/RLV/InstantMessages/sendim_sec.cs delete mode 100644 Core/RLV/Miscellaneous/clear.cs delete mode 100644 Core/RLV/Miscellaneous/getstatus.cs delete mode 100644 Core/RLV/Miscellaneous/getstatusall.cs delete mode 100644 Core/RLV/Miscellaneous/notify.cs delete mode 100644 Core/RLV/Miscellaneous/permissive.cs delete mode 100644 Core/RLV/Movement/adjustheight.cs delete mode 100644 Core/RLV/Movement/alwaysrun.cs delete mode 100644 Core/RLV/Movement/fly.cs delete mode 100644 Core/RLV/Movement/setrot.cs delete mode 100644 Core/RLV/Movement/temprun.cs delete mode 100644 Core/RLV/PrivateChannels/sendchannel.cs delete mode 100644 Core/RLV/PrivateChannels/sendchannel_except.cs delete mode 100644 Core/RLV/PrivateChannels/sendchannel_sec.cs delete mode 100644 Core/RLV/RLV_commandlib.cs delete mode 100644 Core/RLV/Sitting/getsitid.cs delete mode 100644 Core/RLV/Sitting/sit.cs delete mode 100644 Core/RLV/Sitting/unsit.cs delete mode 100644 Core/RLV/Version/version.cs delete mode 100644 Core/RLV/Version/versionnew.cs delete mode 100644 Core/RLV/Version/versionnum.cs delete mode 100644 Core/bottypes/RLVbot.cs diff --git a/BetterSecondbot/HttpService/Animation.cs b/BetterSecondbot/HttpService/Animation.cs new file mode 100644 index 0000000..c503689 --- /dev/null +++ b/BetterSecondbot/HttpService/Animation.cs @@ -0,0 +1,79 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; + +namespace BetterSecondBot.HttpService +{ + public class HttpApiAnimation : WebApiControllerWithTokens + { + public HttpApiAnimation(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Toggles if animation requests from this avatar (used for remote poseballs) are accepted")] + [ReturnHints("Granted perm animation")] + [ReturnHints("Removed perm animation")] + [ReturnHints("avatar lookup")] + [ArgHints("avatar", "URLARG", "UUID (or Firstname Lastname)")] + [Route(HttpVerbs.Get, "/AddToAllowAnimations/{avatar}/{token}")] + public object AddToAllowAnimations(string avatar, string token) + { + if (tokens.Allow(token, "animation", "addtoallowanimations", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return BasicReply("avatar lookup"); + } + if (bot.Accept_action_from("animation", avataruuid) == false) + { + bot.Add_action_from("animation", avataruuid); + return BasicReply("Granted perm animation"); + } + bot.Remove_action_from("animation", avataruuid, true); + return BasicReply("Removed perm animation"); + } + + [About("Attempts to play a gesture")] + [ReturnHints("Error with gesture")] + [ReturnHints("Accepted")] + [ArgHints("gesture", "URLARG", "Inventory UUID of the gesture")] + [Route(HttpVerbs.Get, "/PlayGesture/{gesture}/{token}")] + public object PlayGesture(string gesture, string token) + { + if (tokens.Allow(token, "animation", "gesture", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (UUID.TryParse(gesture, out UUID gestureUUID) == false) + { + return BasicReply("Error with gesture"); + } + InventoryItem itm = bot.GetClient.Inventory.FetchItem(gestureUUID, bot.GetClient.Self.AgentID, (3 * 1000)); + bot.GetClient.Self.PlayGesture(itm.AssetUUID); + return BasicReply("Accepted"); + } + + [About("Resets the animation stack for the bot")] + [ReturnHints("Accepted")] + [Route(HttpVerbs.Get, "/ResetAnimations/{token}")] + public object ResetAnimations(string token) + { + if (tokens.Allow(token, "animation", "resetanimations", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + bot.ResetAnimations(); + return BasicReply("Accepted"); + } + + } +} diff --git a/BetterSecondbot/HttpService/Avatars.cs b/BetterSecondbot/HttpService/Avatars.cs new file mode 100644 index 0000000..62903dc --- /dev/null +++ b/BetterSecondbot/HttpService/Avatars.cs @@ -0,0 +1,112 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Avatars : WebApiControllerWithTokens + { + public HTTP_Avatars(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [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 (tokens.Allow(token, "avatars", "nearmewithdetails", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim == null) + { + return BasicReply("Error not in a sim"); + } + List BetterNearMe = new List(); + Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy(); + foreach (Avatar av in avcopy.Values) + { + 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)); + } + + [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) + { + if (tokens.Allow(token, "avatars", "nearme", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim == null) + { + return BasicReply("Error not in a sim"); + } + Dictionary NearMe = new Dictionary(); + Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy(); + foreach (Avatar av in avcopy.Values) + { + if (av.ID != bot.GetClient.Self.AgentID) + { + NearMe.Add(av.ID, av.Name); + } + } + return BasicReply(JsonConvert.SerializeObject(NearMe)); + } + + + [About("Makes the bot pay a avatar")] + [ReturnHints("Accepted")] + [ReturnHints("avatar lookup")] + [ReturnHints("Invaild amount")] + [ReturnHints("Transfer funds to avatars disabled")] + [Route(HttpVerbs.Get, "/PayAvatar/{avatar}/{amount}/{token}")] + public object PayAvatar(string avatar,string amount,string token) + { + if (tokens.Allow(token, "avatars", "payavatar", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bot.GetAllowFunds == false) + { + return BasicReply("Transfer funds to avatars disabled"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return BasicReply("avatar lookup"); + } + if (int.TryParse(amount, out int amountvalue) == false) + { + return BasicReply("Invaild amount"); + } + if(amountvalue < 1) + { + return BasicReply("Invaild amount"); + } + bot.GetClient.Self.GiveAvatarMoney(avataruuid, amountvalue); + return BasicReply("Accepted"); + } + } +} diff --git a/BetterSecondbot/HttpService/Chat.cs b/BetterSecondbot/HttpService/Chat.cs index fe7f7a0..1ddf9bc 100644 --- a/BetterSecondbot/HttpService/Chat.cs +++ b/BetterSecondbot/HttpService/Chat.cs @@ -8,6 +8,7 @@ using System.Collections.Generic; using System.Text; using OpenMetaverse; using Newtonsoft.Json; +using BetterSecondBotShared.Static; namespace BetterSecondBot.HttpService { @@ -17,8 +18,8 @@ namespace BetterSecondBot.HttpService [About("fetchs the last 20 localchat messages")] [ReturnHints("array string")] - [Route(HttpVerbs.Get, "/localchathistory/{token}")] - public object localchatHistory(string token) + [Route(HttpVerbs.Get, "/LocalChatHistory/{token}")] + public object LocalChatHistory(string token) { if (tokens.Allow(token, "chat", "localchathistory", getClientIP()) == true) { @@ -30,15 +31,52 @@ namespace BetterSecondBot.HttpService [About("sends a message to localchat")] [ArgHints("message", "URLARG", "the message to send")] [ReturnHints("array string")] - [Route(HttpVerbs.Post, "/localchatsay/{token}")] - public object localchatSay(string token, [FormField] string message) + [ReturnHints("Message empty")] + [ReturnHints("Invaild channel")] + [Route(HttpVerbs.Post, "/Say/{channel}/{token}")] + public object Say(string channel,[FormField] string message,string token) { - if (tokens.Allow(token, "chat", "localchatsay", getClientIP()) == true) + if (tokens.Allow(token, "chat", "localchatsay", getClientIP()) == false) { - bot.GetCommandsInterface.Call("say", message); - return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory())); + return BasicReply("Token not accepted"); } - return BasicReply("Token not accepted"); + if (helpers.notempty(message) == false) + { + return BasicReply("Message empty"); + } + if(int.TryParse(channel,out int channelnum) == false) + { + return BasicReply("Invaild channel"); + } + bot.GetClient.Self.Chat(message, channelnum, ChatType.Normal); + return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory())); + + } + + [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")] + [ReturnHints("Message empty")] + [ReturnHints("avatar lookup")] + [Route(HttpVerbs.Post, "/IM/{avatar}/{token}")] + public object IM(string avatar, [FormField] string message, string token) + { + if (tokens.Allow(token, "chat", "im", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + ProcessAvatar(avatar); + if(avataruuid == UUID.Zero) + { + return BasicReply("avatar lookup"); + } + if (helpers.notempty(message) == false) + { + return BasicReply("Message empty"); + } + bot.SendIM(avataruuid, message); + return BasicReply("ok"); } } diff --git a/BetterSecondbot/HttpService/Core.cs b/BetterSecondbot/HttpService/Core.cs index 07aa2a2..3defd91 100644 --- a/BetterSecondbot/HttpService/Core.cs +++ b/BetterSecondbot/HttpService/Core.cs @@ -12,9 +12,6 @@ using Newtonsoft.Json; namespace BetterSecondBot.HttpService { - - - public class HttpApiCore : WebApiControllerWithTokens { @@ -30,7 +27,7 @@ namespace BetterSecondBot.HttpService [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")] + [Route(HttpVerbs.Post, "/GetToken")] public Object GetToken([FormField] string authcode, [FormField] string unixtimegiven) { long now = helpers.UnixTimeNow(); @@ -56,7 +53,7 @@ namespace BetterSecondBot.HttpService [About("Gets the friendslist
Formated as follows
friendreplyobject
  • name: String
  • id: String
  • online: bool
")] [ReturnHints("array UUID = friendreplyobject")] - [Route(HttpVerbs.Get, "/friends/{token}")] + [Route(HttpVerbs.Get, "/Friends/{token}")] public object Friends(string token) { if (tokens.Allow(token, "core", "friends", getClientIP()) == true) @@ -72,7 +69,7 @@ namespace BetterSecondBot.HttpService [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}")] + [Route(HttpVerbs.Get, "/WalkTo/{x}/{y}/{z}/{token}")] public object WalkTo(string x, string y, string z, string token) { if (tokens.Allow(token, "core", "walkto", getClientIP()) == true) @@ -87,24 +84,7 @@ 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) - { - if (tokens.Allow(token, "core", "gesture", getClientIP()) == true) - { - bool status = bot.GetCommandsInterface.Call("PlayGesture", gesture); - if (status == true) - { - return BasicReply("Accepted"); - } - return BasicReply("Error with gesture"); - } - return BasicReply("Token not accepted"); - } + [About("Attempt to teleport to a new region")] [ReturnHints("Error Unable to Teleport to location")] @@ -113,7 +93,7 @@ namespace BetterSecondBot.HttpService [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}")] + [Route(HttpVerbs.Get, "/Teleport/{region}/{x}/{y}/{z}/{token}")] public object Teleport(string region,string x, string y, string z, string token) { if (tokens.Allow(token, "core", "teleport", getClientIP()) == true) @@ -132,7 +112,7 @@ namespace BetterSecondBot.HttpService [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}")] + [Route(HttpVerbs.Get, "/Regiontile/{regionname}/{token}")] public object Regiontile(string regionname, string token) { if (tokens.Allow(token, "core", "regiontile", getClientIP()) == true) @@ -149,69 +129,12 @@ 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
  • id
  • name
  • x
  • y
  • z
  • range
")] - [ReturnHints("array NearMeDetails")] - [ReturnHints("Error not in a sim")] - [Route(HttpVerbs.Get, "/nearmewithdetails/{token}")] - public object NearmeWithDetails(string token) - { - if (tokens.Allow(token, "core", "nearmewithdetails", getClientIP()) == true) - { - if (bot.GetClient.Network.CurrentSim != null) - { - List BetterNearMe = new List(); - Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy(); - foreach (Avatar av in avcopy.Values) - { - 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("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) - { - if (tokens.Allow(token, "core", "nearme", getClientIP()) == true) - { - if (bot.GetClient.Network.CurrentSim != null) - { - Dictionary NearMe = new Dictionary(); - Dictionary avcopy = bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy(); - foreach (Avatar av in avcopy.Values) - { - if (av.ID != bot.GetClient.Self.AgentID) - { - NearMe.Add(av.ID, av.Name); - } - } - return BasicReply(JsonConvert.SerializeObject(NearMe)); - } - return BasicReply("Error not in a sim"); - } - return BasicReply("Token not accepted"); - } [About("Used to check HTTP connections")] [ReturnHints("world")] [NeedsToken(false)] - [Route(HttpVerbs.Get, "/hello")] + [Route(HttpVerbs.Get, "/Hello")] public object Hello() { return BasicReply("world"); @@ -221,7 +144,7 @@ namespace BetterSecondBot.HttpService [About("Removes the given token from the accepted token pool")] [ReturnHints("Failed to remove token")] [ReturnHints("ok")] - [Route(HttpVerbs.Get, "/logout/{token}")] + [Route(HttpVerbs.Get, "/Logout/{token}")] public object Logout(string token) { if (tokens.Allow(token, "core", "logout", getClientIP()) == true) @@ -235,7 +158,7 @@ namespace BetterSecondBot.HttpService [About("Fetchs the current bot")] [ReturnHints("The build ID of the bot")] - [Route(HttpVerbs.Get, "/version/{token}")] + [Route(HttpVerbs.Get, "/Version/{token}")] public object Version(string token) { if (tokens.Allow(token, "core", "version", getClientIP()) == true) @@ -247,7 +170,7 @@ namespace BetterSecondBot.HttpService [About("Fetchs the name of the bot")] [ReturnHints("Firstname Lastname")] - [Route(HttpVerbs.Get, "/name/{token}")] + [Route(HttpVerbs.Get, "/Name/{token}")] public object Name(string token) { if (tokens.Allow(token, "core", "name", getClientIP()) == true) @@ -260,7 +183,7 @@ namespace BetterSecondBot.HttpService [About("Fetchs the current region name")] [ReturnHints("Regionname")] [ReturnHints("Error not in a sim")] - [Route(HttpVerbs.Get, "/regionname/{token}")] + [Route(HttpVerbs.Get, "/Regionname/{token}")] public object Regionname(string token) { if (tokens.Allow(token, "core", "regionname", getClientIP()) == true) @@ -277,7 +200,7 @@ namespace BetterSecondBot.HttpService [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}")] + [Route(HttpVerbs.Get, "/Location/{token}")] public object Location(string token) { if (tokens.Allow(token, "core", "location", getClientIP()) == true) @@ -301,8 +224,8 @@ namespace BetterSecondBot.HttpService [ReturnHints("accepted")] [ReturnHints("Auth not accepted")] [ReturnHints("Failed")] - [Route(HttpVerbs.Post, "/command/{token}")] - public async Task command(string token) + [Route(HttpVerbs.Post, "/Command/{token}")] + public async Task Command(string token) { if (tokens.Allow(token, "core", "command", getClientIP()) == true) { diff --git a/BetterSecondbot/HttpService/Dialogs.cs b/BetterSecondbot/HttpService/Dialogs.cs new file mode 100644 index 0000000..e016faa --- /dev/null +++ b/BetterSecondbot/HttpService/Dialogs.cs @@ -0,0 +1,99 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Dialogs : WebApiControllerWithTokens + { + public HTTP_Dialogs(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Updates the relay target (you can have 1 of each type)
Clear will disable them all")] + [ReturnHints("cleared")] + [ReturnHints("set/avatar")] + [ReturnHints("set/http")] + [ReturnHints("set/channel")] + [ReturnHints("Not a vaild option")] + [ArgHints("target","URLARG", "Options: Channel (Any number),Avatar UUID,HTTPurl
Clear")] + [Route(HttpVerbs.Get, "/DialogRelay/{target}/{token}")] + public object DialogRelay(string target,string token) + { + if (tokens.Allow(token, "dialogs", "DialogRelay", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (target == "clear") + { + bot.SetRelayDialogsAvatar(UUID.Zero); + bot.SetRelayDialogsChannel(0); + bot.SetRelayDialogsHTTP(""); + return BasicReply("cleared"); + } + ProcessAvatar(target); + if (avataruuid != UUID.Zero) + { + bot.SetRelayDialogsAvatar(avataruuid); + return BasicReply("set/avatar"); + } + if (target.StartsWith("http") == true) + { + bot.SetRelayDialogsHTTP(target); + return BasicReply("set/http"); + } + if (int.TryParse(target, out int channel) == true) + { + bot.SetRelayDialogsChannel(channel); + return BasicReply("set/channel"); + } + return BasicReply("Not a vaild option"); + + } + + [About("Makes the bot interact with the dialog [dialogid] with the button [buttontext]")] + [ReturnHints("true")] + [ReturnHints("false")] + [ReturnHints("bad dialog id")] + [ArgHints("target", "URLARG", "Options: Channel (Any number),Avatar UUID,HTTPurl
Clear")] + [Route(HttpVerbs.Get, "/DialogResponce/{dialogid}/{buttontext}/{token}")] + public object DialogResponce(string dialogid, string buttontext, string token) + { + if (tokens.Allow(token, "dialogs", "DialogResponce", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (int.TryParse(dialogid, out int dialogidnum) == false) + { + return BasicReply("bad dialog id"); + } + return BasicReply(bot.DialogReply(dialogidnum, buttontext).ToString()); + } + + [About("Should the bot track dialogs and send them to the relays setup?")] + [ReturnHints("updated")] + [ReturnHints("bad status")] + [ArgHints("status", "URLARG", "true or false")] + [Route(HttpVerbs.Get, "/DialogTrack/{status}/{token}")] + public object DialogTrack(string status, string token) + { + if (tokens.Allow(token, "dialogs", "DialogTrack", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bool.TryParse(status, out bool statuscode) == false) + { + return BasicReply("bad status"); + } + bot.SetTrackDialogs(statuscode); + return BasicReply("updated"); + } + + } +} diff --git a/BetterSecondbot/HttpService/Discord.cs b/BetterSecondbot/HttpService/Discord.cs new file mode 100644 index 0000000..598a42b --- /dev/null +++ b/BetterSecondbot/HttpService/Discord.cs @@ -0,0 +1,105 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; +using Discord.WebSocket; +using System.Threading.Tasks; +using Discord; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Discord : WebApiControllerWithTokens + { + public HTTP_Discord(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Adds a discord server role to the selected member")] + [ReturnHints("Discord client not ready")] + [ReturnHints("true")] + [ReturnHints("false")] + [ArgHints("serverid","URLARG","the server id to apply this action to")] + [ArgHints("roleid", "URLARG", "the role id we are giving")] + [ArgHints("memberid", "URLARG", "who we are giving it to")] + [Route(HttpVerbs.Get, "/Discord_AddRole/{serverid}/{roleid}/{memberid}/{token}")] + public object Discord_AddRole(string serverid,string roleid,string memberid,string token) + { + if (tokens.Allow(token, "discord", "Discord_AddRole", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bot.discordReady() == false) + { + return BasicReply("Discord client not ready"); + } + return BasicReply(addRoleToMember(serverid, roleid, memberid).Result.ToString()); + } + + [About("Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list")] + [ReturnHints("Discord client not ready")] + [ReturnHints("true")] + [ReturnHints("false")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("memberid", "URLARG", "who we are giving it to")] + [ArgHints("why", "string", "why they are being banned")] + [Route(HttpVerbs.Get, "/Discord_BanMember/{serverid}/{memberid}/{token}")] + public object Discord_BanMember(string serverid, string memberid, [FormField] string why, string token) + { + if (tokens.Allow(token, "discord", "Discord_BanMember", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bot.discordReady() == false) + { + return BasicReply("Discord client not ready"); + } + return BasicReply(BanMember(serverid, memberid, why).Result.ToString()); + } + + + protected async Task BanMember(string givenserverid, string givenmemberid, string why) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return false; + } + if (ulong.TryParse(givenmemberid, out ulong memberid) == false) + { + return false; + } + SocketGuild server = Discord.GetGuild(serverid); + SocketGuildUser user = server.GetUser(memberid); + await user.BanAsync(7, why); + return true; + } + + + protected async Task addRoleToMember(string givenserverid, string givenroleid, string givenmemberid) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return false; + } + if (ulong.TryParse(givenroleid, out ulong roleid) == false) + { + return false; + } + if (ulong.TryParse(givenmemberid, out ulong memberid) == false) + { + return false; + } + SocketGuild server = Discord.GetGuild(serverid); + SocketRole role = server.GetRole(roleid); + SocketGuildUser user = server.GetUser(memberid); + await user.AddRoleAsync(role); // ? Irole seems to accept SocketRole ? + return true; + } + } +} diff --git a/BetterSecondbot/HttpService/Estate.cs b/BetterSecondbot/HttpService/Estate.cs index 2ca799b..863fd4b 100644 --- a/BetterSecondbot/HttpService/Estate.cs +++ b/BetterSecondbot/HttpService/Estate.cs @@ -20,8 +20,8 @@ namespace BetterSecondBot.HttpService [About("Requests the estate banlist")] [ReturnHints("")] - [Route(HttpVerbs.Get, "/banlist/{token}")] - public Object Banlist(string token) + [Route(HttpVerbs.Get, "/GetEstateBanList/{token}")] + public Object GetEstateBanList(string token) { if (tokens.Allow(token, "estate", "banlist", getClientIP()) == true) { @@ -38,9 +38,9 @@ namespace BetterSecondBot.HttpService [ArgHints("avatar", "URLARG", "the uuid avatar you wish to ban")] [ArgHints("mode", "URLARG", "What action would you like to take
Defaults to remove if not given \"add\"")] [ArgHints("global", "URLARG", "if true this the ban/unban will be applyed to all estates the bot has access to")] - [Route(HttpVerbs.Get, "/update-banlist/{avatar}/{mode}/{global}/{token}")] + [Route(HttpVerbs.Get, "/UpdateEstateBanlist/{avatar}/{mode}/{global}/{token}")] - public Object UpdateBanlist(string avatar, string mode, string global, string token) + public Object UpdateEstateBanlist(string avatar, string mode, string global, string token) { if (tokens.Allow(token, "estate", "banlist-add", getClientIP()) == true) { diff --git a/BetterSecondbot/HttpService/HttpAsService.cs b/BetterSecondbot/HttpService/HttpAsService.cs index a09fd92..de0762d 100644 --- a/BetterSecondbot/HttpService/HttpAsService.cs +++ b/BetterSecondbot/HttpService/HttpAsService.cs @@ -14,6 +14,9 @@ using EmbedIO.Routing; using BetterSecondBotShared.logs; using BetterSecondBotShared.IO; using Newtonsoft.Json; +using OpenMetaverse; +using System.Reflection; +using System.Linq; namespace BetterSecondBot.HttpService { @@ -145,7 +148,7 @@ namespace BetterSecondBot.HttpService if (killedLogger == false) { killedLogger = true; - Logger.UnregisterLogger(); + Swan.Logging.Logger.UnregisterLogger(); } using (var server = CreateWebServer(Config.Http_Host)) { @@ -259,6 +262,24 @@ namespace BetterSecondBot.HttpService protected Dictionary scopedtokens = new Dictionary(); + protected List OneTimeTokens = new List(); + + public string OneTimeToken() + { + bool known = true; + string last = ""; + while (known == true) + { + last = helpers.GetSHA1(last + helpers.UnixTimeNow() + new Random().Next(13256).ToString()).Substring(0, 10); + if(OneTimeTokens.Contains(last) == false) + { + known = false; + OneTimeTokens.Add(last); + } + } + return last; + } + public void AddScopedToken(string code, scopedTokenInfo info) { scopedtokens.Add(code, info); @@ -308,6 +329,11 @@ namespace BetterSecondBot.HttpService return true; } } + if(OneTimeTokens.Contains(code) == true) + { + OneTimeTokens.Remove(code); + return true; + } return ScopeAllow(code, workgroup, command); } @@ -370,7 +396,43 @@ namespace BetterSecondBot.HttpService protected TokenStorage tokens; protected SecondBot bot; public bool needsToken { get; set; } + protected UUID avataruuid = UUID.Zero; + protected string CallMethod(string name,string[] args) + { + MethodInfo[] methods = this.GetType().GetMethods(); + MethodInfo found = null; + foreach(MethodInfo M in methods) + { + if(M.Name == name) + { + found = M; + break; + } + } + if(found == null) + { + return "Failed:Not Found"; + } + List settings = new List(args); + settings.Add(tokens.OneTimeToken()); + if(found.GetParameters().Length != settings.Count) + { + return "Failed:Incorrect args"; + } + string reply = (string)found.Invoke(this, settings.Cast().ToArray()); + return "Passed:"+ reply; + } + protected void ProcessAvatar(string avatar) + { + string[] bits = avatar.Split(' '); + avataruuid = UUID.Zero; + if (bits.Length == 2) + { + avatar = bot.FindAvatarName2Key(avatar); + } + UUID.TryParse(avatar, out avataruuid); + } protected Object BasicReply(string input) { diff --git a/BetterSecondbot/HttpService/Im.cs b/BetterSecondbot/HttpService/Im.cs index feaee26..ee0d79e 100644 --- a/BetterSecondbot/HttpService/Im.cs +++ b/BetterSecondbot/HttpService/Im.cs @@ -15,17 +15,16 @@ namespace BetterSecondBot.HttpService { 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) { - if (tokens.Allow(token, "im", "chatwindows", getClientIP()) == true) + if (tokens.Allow(token, "im", "chatwindows", getClientIP()) == false) { - return BasicReply(JsonConvert.SerializeObject(bot.GetIMChatWindowKeyNames())); + return BasicReply("Token not accepted"); } - return BasicReply("Token not accepted"); + return BasicReply(JsonConvert.SerializeObject(bot.GetIMChatWindowKeyNames())); } [About("gets a list of chat windows with unread messages")] @@ -33,19 +32,19 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/listwithunread/{token}")] public object listwithunread(string group, string token) { - if (tokens.Allow(token, "im", "listwithunread", getClientIP()) == true) + if (tokens.Allow(token, "im", "listwithunread", getClientIP()) == false) { - List unreadimwindows = new List(); - foreach (UUID window in bot.IMChatWindows()) - { - if (bot.ImChatWindowHasUnread(window) == true) - { - unreadimwindows.Add(window); - } - } - return BasicReply(JsonConvert.SerializeObject(unreadimwindows)); + return BasicReply("Token not accepted"); } - return BasicReply("Token not accepted"); + List unreadimwindows = new List(); + foreach (UUID window in bot.IMChatWindows()) + { + if (bot.ImChatWindowHasUnread(window) == true) + { + unreadimwindows.Add(window); + } + } + return BasicReply(JsonConvert.SerializeObject(unreadimwindows)); } [About("gets if there are any unread im messages at all")] @@ -53,20 +52,20 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/haveunreadims/{token}")] public object haveunreadims(string token) { - if (tokens.Allow(token, "im", "haveunreadims", getClientIP()) == true) + if (tokens.Allow(token, "im", "haveunreadims", getClientIP()) == false) { - bool reply = false; - foreach(UUID window in bot.IMChatWindows()) - { - if(bot.ImChatWindowHasUnread(window) == true) - { - reply = true; - break; - } - } - return BasicReply(reply.ToString()); + return BasicReply("Token not accepted"); } - return BasicReply("Token not accepted"); + bool reply = false; + foreach (UUID window in bot.IMChatWindows()) + { + if (bot.ImChatWindowHasUnread(window) == true) + { + reply = true; + break; + } + } + return BasicReply(reply.ToString()); } [About("gets the chat from the selected window")] @@ -76,32 +75,15 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/getimchat/{window}/{token}")] public object getimchat(string window, string token) { - if (tokens.Allow(token, "im", "getimchat", getClientIP()) == true) + if (tokens.Allow(token, "im", "getimchat", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (UUID.TryParse(window, out UUID windowUUID) == false) { - if (UUID.TryParse(window, out UUID windowUUID) == true) - { - return BasicReply(JsonConvert.SerializeObject(bot.GetIMChatWindow(windowUUID))); - } return BasicReply("Window UUID invaild"); } - return BasicReply("Token not accepted"); + return BasicReply(JsonConvert.SerializeObject(bot.GetIMChatWindow(windowUUID))); } - - [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 sendimchat(string avatar, string token, [FormField] string message) - { - if (tokens.Allow(token, "im", "sendimchat", getClientIP()) == true) - { - bot.GetCommandsInterface.Call("im", avatar + "~#~" + message, UUID.Zero, "~#~"); - return BasicReply("ok"); - } - return BasicReply("Token not accepted"); - } - - } } diff --git a/BetterSecondbot/WikiMake/wikimake.cs b/BetterSecondbot/WikiMake/wikimake.cs index 7ceb9e9..fcb9b60 100644 --- a/BetterSecondbot/WikiMake/wikimake.cs +++ b/BetterSecondbot/WikiMake/wikimake.cs @@ -293,11 +293,6 @@ namespace BetterSecondBot.WikiMake api_reports.Add("Core", new KeyValuePair(cmd.ApiCommandsCount, "Good")); InterfaceWiki("Core", cmd, true); - // RLVapi - BetterSecondBot.RLV.RLVcontrol RLVapi = new BetterSecondBot.RLV.RLVcontrol(null); - api_reports.Add("RLVapi", new KeyValuePair(RLVapi.ApiCommandsCount, "Limited")); - InterfaceWiki("RLVapi", RLVapi, true); - // HTTP HTTPWiki(); diff --git a/Core/Commands/Animation/PlayGesture.cs b/Core/Commands/Animation/PlayGesture.cs deleted file mode 100644 index 56fd4e4..0000000 --- a/Core/Commands/Animation/PlayGesture.cs +++ /dev/null @@ -1,25 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Animation -{ - public class PlayGesture : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "UUID" }; } } - public override string[] ArgHints { get { return new[] { "The UUID of the gesture to play" }; } } - public override string Helpfile { get { return "Triggers a gesture [once]"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID gesture) == true) - { - InventoryItem itm = bot.GetClient.Inventory.FetchItem(gesture, bot.GetClient.Self.AgentID, (3 * 1000)); - bot.GetClient.Self.PlayGesture(itm.AssetUUID); - return true; - } - return Failed("Invaild gesture UUID for arg 1"); - } - return false; - } - } -} diff --git a/Core/Commands/Animation/addToAnimations.cs b/Core/Commands/Animation/addToAnimations.cs deleted file mode 100644 index 1bf9078..0000000 --- a/Core/Commands/Animation/addToAnimations.cs +++ /dev/null @@ -1,33 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Animation -{ - public class AddToAllowAnimations : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar UUID or Firstname Lastname" }; } } - public override string Helpfile { get { return "Toggles if animation requests from this avatar (used for remote poseballs) are accepted
Case sensitive also requires Lastname"; } } - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID avatar) == true) - { - if(bot.Accept_action_from("animation",avatar) == false) - { - bot.Add_action_from("animation", avatar); - InfoBlob = "Granted perm animation"; - } - else - { - bot.Remove_action_from("animation", avatar,true); - InfoBlob = "Removed perm animation"; - } - return true; - } - return Failed("Invaild avatar for arg 1"); - } - return false; - } - } -} diff --git a/Core/Commands/Animation/resetAnimations.cs b/Core/Commands/Animation/resetAnimations.cs deleted file mode 100644 index 8b673b3..0000000 --- a/Core/Commands/Animation/resetAnimations.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace BetterSecondBot.Commands.Animation -{ - public class ResetAnimations : CoreCommand - { - public override string Helpfile { get { return "Resets the animation stack for the bot"; } } - public override bool CallFunction(string[] args) - { - bot.ResetAnimations(); - return true; - } - } -} diff --git a/Core/Commands/Avatars/NearMe.cs b/Core/Commands/Avatars/NearMe.cs deleted file mode 100644 index 4b301cc..0000000 --- a/Core/Commands/Avatars/NearMe.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; - -namespace BetterSecondBot.Commands.Avatars -{ - class RoleCreate : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Gets a list of avatars near the bot"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - Dictionary collection = new Dictionary(); - foreach(Avatar av in bot.GetClient.Network.CurrentSim.ObjectsAvatars.Copy().Values) - { - Vector3 pos = new Vector3(1, 1, 1); - if(bot.GetClient.Network.CurrentSim.AvatarPositions.ContainsKey(av.ID) == true) - { - pos = bot.GetClient.Network.CurrentSim.AvatarPositions[av.ID]; - } - Dictionary entrys = new Dictionary(); - entrys.Add("Username",av.Name); - entrys.Add("Pos", pos.X.ToString() + "," + pos.Y.ToString() + "," + pos.Z.ToString()); - collection.Add(av.ID.ToString(), JsonConvert.SerializeObject(entrys)); - } - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], "ok", CommandName, collection); - } - return false; - } - } -} diff --git a/Core/Commands/Avatars/PayAvatar.cs b/Core/Commands/Avatars/PayAvatar.cs deleted file mode 100644 index 268124d..0000000 --- a/Core/Commands/Avatars/PayAvatar.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; - - -namespace BetterSecondBot.Commands.Avatars -{ - public class PayAvatar : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Amount to pay"}; } } - public override string Helpfile { get { return "Makes the bot pay a avatar"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetAllowFunds == true) - { - if (UUID.TryParse(args[0], out UUID avataruuid) == true) - { - if (int.TryParse(args[1], out int amount) == true) - { - if (amount > 0) - { - bot.GetClient.Self.GiveAvatarMoney(avataruuid, amount); - return true; - } - } - return Failed("Invaild amount"); - } - return Failed("Invaild avatar UUID"); - } - return Failed("Transfer funds to avatars disabled"); - } - return false; - } - } -} diff --git a/Core/Commands/Chat/LocalChatHistory.cs b/Core/Commands/Chat/LocalChatHistory.cs deleted file mode 100644 index d0fc35d..0000000 --- a/Core/Commands/Chat/LocalChatHistory.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Linq; -using Newtonsoft.Json; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Chat -{ - class LocalChatHistory : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Gets the last 20 localchat messages the bot has."; } } - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], JsonConvert.SerializeObject(bot.getLocalChatHistory()), CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Chat/im.cs b/Core/Commands/Chat/im.cs deleted file mode 100644 index 3396199..0000000 --- a/Core/Commands/Chat/im.cs +++ /dev/null @@ -1,35 +0,0 @@ -using OpenMetaverse; -using BetterSecondBotShared.Static; - -namespace BetterSecondBot.Commands.Chat -{ - class IM : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "Text" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]","Message" }; } } - public override string Helpfile { get { return "Makes the bot send a IM to an avatar
Example: IM|||289c3e36-69b3-40c5-9229-0c6a5d230766~#~Hello Mad I am a bot"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target_av) == true) - { - if (helpers.notempty(args[1]) == true) - { - bot.SendIM(target_av, args[1]); - return true; - } - else - { - return Failed("Arg 2 is empty"); - } - } - else - { - return Failed("Not a vaild UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Chat/say.cs b/Core/Commands/Chat/say.cs deleted file mode 100644 index e07ff91..0000000 --- a/Core/Commands/Chat/say.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Linq; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Chat -{ - class Say : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Mixed","Text","Text" }; } } - public override string[] ArgHints { get { return new[] { "Message or channel","Message","Chat level" }; } } - public override string Helpfile { get { return "Makes the bot talk via chat
Example: say|||Hello
Example: say|||12~#~Goodbye
Example: say|||12~#~Goodbye~#~Shout
Chat levels [Arg 3]:
Whisper
Shout"; } } - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - string message = args[0]; - int channel = 0; - ChatType ChatLevel = ChatType.Normal; - if (args.Count() >= 2) - { - message = args[1]; - int.TryParse(args[0], out channel); - if (args.Count() == 3) - { - if (args[2] == "Shout") - { - ChatLevel = ChatType.Shout; - } - else if (args[2] == "Whisper") - { - ChatLevel = ChatType.Whisper; - } - } - } - if (channel == 0) - { - bot.AddToLocalChat(bot.GetClient.Self.Name, message); - } - bot.GetClient.Self.Chat(message, channel, ChatLevel); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Dialogs/DialogRelay.cs b/Core/Commands/Dialogs/DialogRelay.cs deleted file mode 100644 index c4e2714..0000000 --- a/Core/Commands/Dialogs/DialogRelay.cs +++ /dev/null @@ -1,46 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Dialogs -{ - class DialogRelay : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Smart" }; } } - public override string[] ArgHints { get { return new[] { "Channel (Any number),Avatar UUID,Avatar name,HTTPurl
Clear" }; } } - public override string Helpfile { get { return "Updates the relay target (you can have 1 of each type)
Clear will disable them all"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(args[0] != "Clear") - { - if (UUID.TryParse(args[0], out UUID avatar) == true) - { - bot.SetRelayDialogsAvatar(avatar); - } - else if (args[0].StartsWith("http") == true) - { - bot.SetRelayDialogsHTTP(args[0]); - } - else if (int.TryParse(args[0], out int channel) == true) - { - bot.SetRelayDialogsChannel(channel); - } - else - { - return Failed("Not a vaild option"); - } - return true; - } - else - { - bot.SetRelayDialogsAvatar(UUID.Zero); - bot.SetRelayDialogsChannel(0); - bot.SetRelayDialogsHTTP(""); - return true; - } - } - return false; - } - } - -} diff --git a/Core/Commands/Dialogs/DialogResponce.cs b/Core/Commands/Dialogs/DialogResponce.cs deleted file mode 100644 index eadf43f..0000000 --- a/Core/Commands/Dialogs/DialogResponce.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace BetterSecondBot.Commands.Dialogs -{ - class DialogResponce : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Number","Text" }; } } - public override string[] ArgHints { get { return new[] { "DialogID","Button to click" }; } } - public override string Helpfile { get { return "Makes the bot interact with the dialog [ARG 1] with the button [ARG 2]"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (int.TryParse(args[0], out int dialogid) == true) - { - return bot.DialogReply(dialogid, args[1]); - } - else - { - return Failed("Invaild dialog id"); - } - } - return false; - } - } - -} diff --git a/Core/Commands/Dialogs/DialogTrack.cs b/Core/Commands/Dialogs/DialogTrack.cs deleted file mode 100644 index 36f65db..0000000 --- a/Core/Commands/Dialogs/DialogTrack.cs +++ /dev/null @@ -1,22 +0,0 @@ -namespace BetterSecondBot.Commands.Dialogs -{ - class DialogTrack : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Status" }; } } - public override string Helpfile { get { return "Should the bot track dialogs and send them to the relays setup?"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(bool.TryParse(args[0],out bool status) == true) - { - bot.SetTrackDialogs(status); - return true; - } - } - return false; - } - } - -} diff --git a/Core/Commands/DiscordAPI/AddRole.cs b/Core/Commands/DiscordAPI/AddRole.cs deleted file mode 100644 index 8887c88..0000000 --- a/Core/Commands/DiscordAPI/AddRole.cs +++ /dev/null @@ -1,53 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_AddRole : CoreCommand_4arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id", "Member id" }; } } - public override string Helpfile { get { return "Adds the selected role to the member"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool reply = addRoleToMember(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task addRoleToMember(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if(ulong.TryParse(args[2], out ulong roleid) == true) - { - if (ulong.TryParse(args[3], out ulong memberid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketRole role = server.GetRole(roleid); - SocketGuildUser user = server.GetUser(memberid); - await user.AddRoleAsync(role); // ? Irole seems to accept SocketRole ? - return true; - } - } - } - return false; - } - } -} diff --git a/Core/Commands/DiscordAPI/Ban_Member.cs b/Core/Commands/DiscordAPI/Ban_Member.cs deleted file mode 100644 index 1485016..0000000 --- a/Core/Commands/DiscordAPI/Ban_Member.cs +++ /dev/null @@ -1,54 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_BanMember : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number","Text" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Member id","Optional why message" }; } } - public override string Helpfile { get { return "Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list "; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool reply = BanMember(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task BanMember(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong memberid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketGuildUser user = server.GetUser(memberid); - string why = "Secondbot API ban - see your own logs"; - if (args.Length == 4) - { - why = args[3]; - } - await user.BanAsync(7, why); - return true; - } - } - return false; - } - } -} diff --git a/Core/RLV/Blacklist/getblacklist.cs b/Core/RLV/Blacklist/getblacklist.cs deleted file mode 100644 index 1e7b9ad..0000000 --- a/Core/RLV/Blacklist/getblacklist.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Blacklist -{ - public class GetBlacklist : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int channel; - string filter = ""; - if(args.Length == 2) - { - if(int.TryParse(args[1], out channel) == true) - { - filter = args[0]; - } - } - else - { - int.TryParse(args[0], out channel); - } - if (channel >= 0) - { - string sendim = ""; - string recvim = ""; - if (filter == "") - { - sendim = String.Join('|', bot.Getblacklist_sendim); - recvim = String.Join('|', bot.Getblacklist_recvim); - } - else - { - string addon = ""; - foreach (string a in bot.Getblacklist_sendim) - { - if (a.Contains(filter) == true) - { - sendim = "" + sendim + "" + addon + "" + a + ""; - addon = "|"; - } - } - addon = ""; - foreach (string a in bot.Getblacklist_recvim) - { - if (a.Contains(filter) == true) - { - recvim = "" + recvim + "" + addon + "" + a + ""; - addon = "|"; - } - } - } - if (sendim == "") - { - sendim = "#"; - } - if (recvim == "") - { - recvim = "#"; - } - bot.GetClient.Self.Chat("" + sendim + "," + recvim + "", channel, OpenMetaverse.ChatType.Normal); - return true; - } - else - { - return Failed("Invaild channel given"); - } - } - return false; - } - } -} diff --git a/Core/RLV/Blacklist/versionnumbl.cs b/Core/RLV/Blacklist/versionnumbl.cs deleted file mode 100644 index efa4439..0000000 --- a/Core/RLV/Blacklist/versionnumbl.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Blacklist -{ - public class VersionNumBL : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - _ = int.TryParse(args[0], out int channel); - if (channel >= 0) - { - string sendim = String.Join('|', bot.Getblacklist_sendim); - string recvim = String.Join('|', bot.Getblacklist_recvim); - if (sendim == "") { sendim = "#"; } - if (recvim == "") { recvim = "#"; } - bot.GetClient.Self.Chat("209000," + sendim + "," + recvim + "", channel, OpenMetaverse.ChatType.Normal); - return true; - } - else - { - return Failed("Invaild channel given"); - } - } - return false; - } - } -} diff --git a/Core/RLV/Camera/camavdist.cs b/Core/RLV/Camera/camavdist.cs deleted file mode 100644 index a96c182..0000000 --- a/Core/RLV/Camera/camavdist.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamAvDist : RLV_UUID_flag_arg_yn - { - - } -} diff --git a/Core/RLV/Camera/camdistmax.cs b/Core/RLV/Camera/camdistmax.cs deleted file mode 100644 index 52a3cc2..0000000 --- a/Core/RLV/Camera/camdistmax.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDistMax : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camdistmin.cs b/Core/RLV/Camera/camdistmin.cs deleted file mode 100644 index b57aaec..0000000 --- a/Core/RLV/Camera/camdistmin.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDistMin : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camdrawalphamax.cs b/Core/RLV/Camera/camdrawalphamax.cs deleted file mode 100644 index 686157f..0000000 --- a/Core/RLV/Camera/camdrawalphamax.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDrawAlphaMax : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camdrawalphamin.cs b/Core/RLV/Camera/camdrawalphamin.cs deleted file mode 100644 index 5b45105..0000000 --- a/Core/RLV/Camera/camdrawalphamin.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDrawAlphaMin : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camdrawcolor.cs b/Core/RLV/Camera/camdrawcolor.cs deleted file mode 100644 index 8dec3b2..0000000 --- a/Core/RLV/Camera/camdrawcolor.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDrawColor : RLV_UUID_flag_4arg_yn - { - } -} diff --git a/Core/RLV/Camera/camdrawmax.cs b/Core/RLV/Camera/camdrawmax.cs deleted file mode 100644 index 18b5d98..0000000 --- a/Core/RLV/Camera/camdrawmax.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDrawMax : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camdrawmin.cs b/Core/RLV/Camera/camdrawmin.cs deleted file mode 100644 index 38632a1..0000000 --- a/Core/RLV/Camera/camdrawmin.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamDrawMin : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camtextures.cs b/Core/RLV/Camera/camtextures.cs deleted file mode 100644 index 5e158d7..0000000 --- a/Core/RLV/Camera/camtextures.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamTextures : RLV_UUID_flag_optional_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camunlock.cs b/Core/RLV/Camera/camunlock.cs deleted file mode 100644 index 17d6f43..0000000 --- a/Core/RLV/Camera/camunlock.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamUnlock : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Camera/camzoommax.cs b/Core/RLV/Camera/camzoommax.cs deleted file mode 100644 index a25a2e0..0000000 --- a/Core/RLV/Camera/camzoommax.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamZoomMax : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/camzoommin.cs b/Core/RLV/Camera/camzoommin.cs deleted file mode 100644 index ea0ed2e..0000000 --- a/Core/RLV/Camera/camzoommin.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class CamZoomMin : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Camera/getcam_avdistmax.cs b/Core/RLV/Camera/getcam_avdistmax.cs deleted file mode 100644 index d65c1e1..0000000 --- a/Core/RLV/Camera/getcam_avdistmax.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class GetCam_AvDistMax : RLV_UUID_flag_get - { - public override string LookupFlag { get { return "camavdistmax"; } } - } -} diff --git a/Core/RLV/Camera/getcam_avdistmin.cs b/Core/RLV/Camera/getcam_avdistmin.cs deleted file mode 100644 index 307de2c..0000000 --- a/Core/RLV/Camera/getcam_avdistmin.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class GetCam_AvDistMin : RLV_UUID_flag_get - { - public override string LookupFlag { get { return "camavdistmin"; } } - - } -} diff --git a/Core/RLV/Camera/getcam_fov.cs b/Core/RLV/Camera/getcam_fov.cs deleted file mode 100644 index e156c99..0000000 --- a/Core/RLV/Camera/getcam_fov.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class GetCam_Fov : RLV_UUID_flag_get - { - public override string LookupFlag { get { return "camfov"; } } - - } -} diff --git a/Core/RLV/Camera/getcam_fovmax.cs b/Core/RLV/Camera/getcam_fovmax.cs deleted file mode 100644 index 5ec4670..0000000 --- a/Core/RLV/Camera/getcam_fovmax.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class GetCam_FovMax : RLV_UUID_flag_get - { - public override string LookupFlag { get { return "camfovmax"; } } - - } -} diff --git a/Core/RLV/Camera/getcam_fovmin.cs b/Core/RLV/Camera/getcam_fovmin.cs deleted file mode 100644 index 0f275e8..0000000 --- a/Core/RLV/Camera/getcam_fovmin.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class GetCam_FovMin : RLV_UUID_flag_get - { - public override string LookupFlag { get { return "camfovmin"; } } - } -} diff --git a/Core/RLV/Camera/getcam_zoommin.cs b/Core/RLV/Camera/getcam_zoommin.cs deleted file mode 100644 index b516e4c..0000000 --- a/Core/RLV/Camera/getcam_zoommin.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class GetCam_ZoomMin : RLV_UUID_flag_get - { - public override string LookupFlag { get { return "camzoommin"; } } - - } -} diff --git a/Core/RLV/Camera/setcam_avdistmax.cs b/Core/RLV/Camera/setcam_avdistmax.cs deleted file mode 100644 index 5a1cd04..0000000 --- a/Core/RLV/Camera/setcam_avdistmax.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_AvDistMax : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "camavdistmax"; } } - } -} diff --git a/Core/RLV/Camera/setcam_avdistmin.cs b/Core/RLV/Camera/setcam_avdistmin.cs deleted file mode 100644 index b43a550..0000000 --- a/Core/RLV/Camera/setcam_avdistmin.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_AvDistMin : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "camavdistmin"; } } - - } -} diff --git a/Core/RLV/Camera/setcam_fov.cs b/Core/RLV/Camera/setcam_fov.cs deleted file mode 100644 index 8ab0cad..0000000 --- a/Core/RLV/Camera/setcam_fov.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_Fov : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "camfov"; } } - } -} diff --git a/Core/RLV/Camera/setcam_fovmax.cs b/Core/RLV/Camera/setcam_fovmax.cs deleted file mode 100644 index add8c0b..0000000 --- a/Core/RLV/Camera/setcam_fovmax.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_FovMax : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "camfovmax"; } } - } -} diff --git a/Core/RLV/Camera/setcam_fovmin.cs b/Core/RLV/Camera/setcam_fovmin.cs deleted file mode 100644 index a5241b8..0000000 --- a/Core/RLV/Camera/setcam_fovmin.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_FovMin : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "camfovmin"; } } - } -} diff --git a/Core/RLV/Camera/setcam_textures.cs b/Core/RLV/Camera/setcam_textures.cs deleted file mode 100644 index 7c77360..0000000 --- a/Core/RLV/Camera/setcam_textures.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_Textures : RLV_UUID_flag_optional_arg_yn - { - public override string SetFlagName { get { return "camtextures"; } } - } -} diff --git a/Core/RLV/Camera/setcam_unlock.cs b/Core/RLV/Camera/setcam_unlock.cs deleted file mode 100644 index f4b6ff8..0000000 --- a/Core/RLV/Camera/setcam_unlock.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Camera -{ - public class SetCam_Unlock : RLV_UUID_flag_yn - { - public override string SetFlagName { get { return "camunlock"; } } - - } -} diff --git a/Core/RLV/Chat/chatnormal.cs b/Core/RLV/Chat/chatnormal.cs deleted file mode 100644 index 2100f9c..0000000 --- a/Core/RLV/Chat/chatnormal.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class ChatNormal : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Chat/chatshout.cs b/Core/RLV/Chat/chatshout.cs deleted file mode 100644 index d4dc08e..0000000 --- a/Core/RLV/Chat/chatshout.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class ChatShout : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Chat/chatwhisper.cs b/Core/RLV/Chat/chatwhisper.cs deleted file mode 100644 index cc67044..0000000 --- a/Core/RLV/Chat/chatwhisper.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class ChatWhisper : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Chat/recvchat.cs b/Core/RLV/Chat/recvchat.cs deleted file mode 100644 index 459a54f..0000000 --- a/Core/RLV/Chat/recvchat.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Chat -{ - public class RecvChat : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (args.Length == 1) - { - if (args[0] == "y") - { - bot.SetLock("recvchat_channel_zero_lock", false); - return true; - } - else if (args[0] == "n") - { - bot.SetLock("recvchat_channel_zero_lock", true); - return true; - } - return Failed("y/n only"); - } - else if (args.Length == 2) - { - if (UUID.TryParse(args[0], out UUID rec_uuid) == true) - { - return SetFlag(args[1], "set", rec_uuid); - } - return Failed("Unable to process target UUID"); - } - return Failed("Unsupported number of args"); - } - } -} diff --git a/Core/RLV/Chat/recvchat_sec.cs b/Core/RLV/Chat/recvchat_sec.cs deleted file mode 100644 index 95a9f09..0000000 --- a/Core/RLV/Chat/recvchat_sec.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class RecvChat_Sec : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Chat/recvchatfrom.cs b/Core/RLV/Chat/recvchatfrom.cs deleted file mode 100644 index da1908f..0000000 --- a/Core/RLV/Chat/recvchatfrom.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class RecvChatFrom : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Chat/redirchat.cs b/Core/RLV/Chat/redirchat.cs deleted file mode 100644 index 59e79d0..0000000 --- a/Core/RLV/Chat/redirchat.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class RedirChat : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/Chat/sendchat.cs b/Core/RLV/Chat/sendchat.cs deleted file mode 100644 index 1dfed9a..0000000 --- a/Core/RLV/Chat/sendchat.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class SendChat : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Chat/sendgesture.cs b/Core/RLV/Chat/sendgesture.cs deleted file mode 100644 index b913717..0000000 --- a/Core/RLV/Chat/sendgesture.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Chat -{ - public class SendGesture : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Emotes/emote.cs b/Core/RLV/Emotes/emote.cs deleted file mode 100644 index 5cea1a0..0000000 --- a/Core/RLV/Emotes/emote.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Emotes -{ - public class Emote : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Emotes/recvemote.cs b/Core/RLV/Emotes/recvemote.cs deleted file mode 100644 index 9cf4f61..0000000 --- a/Core/RLV/Emotes/recvemote.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Emotes -{ - public class RecvEmote : RLV_UUID_flag_optional_arg_yn - { - public override bool AsExceptionRule { get { return true; } } - public override bool CallFunction(string[] args) - { - if (args.Length == 1) - { - if (args[0] == "y") - { - bot.SetLock("recvemote_lock", false); - return true; - } - else if (args[0] == "n") - { - bot.SetLock("recvemote_lock", true); - return true; - } - return Failed("y/n only"); - } - else if (args.Length == 2) - { - if (UUID.TryParse(args[0], out UUID rec_uuid) == true) - { - return SetFlag(args[1], "set", rec_uuid); - } - return Failed("Unable to process target UUID"); - } - return Failed("Unsupported number of args"); - } - } -} diff --git a/Core/RLV/Emotes/recvemote_sec.cs b/Core/RLV/Emotes/recvemote_sec.cs deleted file mode 100644 index d3adec6..0000000 --- a/Core/RLV/Emotes/recvemote_sec.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Emotes -{ - public class RecvEmote_Sec : RLV_UUID_flag_yn - { - public override string SetFlagName { get { return "recvemote"; } } - } -} diff --git a/Core/RLV/Emotes/rediremote.cs b/Core/RLV/Emotes/rediremote.cs deleted file mode 100644 index 7050c13..0000000 --- a/Core/RLV/Emotes/rediremote.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Emotes -{ - public class RedirEmote : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return CommandName; } } - } -} diff --git a/Core/RLV/InstantMessages/sendim.cs b/Core/RLV/InstantMessages/sendim.cs deleted file mode 100644 index 12306b9..0000000 --- a/Core/RLV/InstantMessages/sendim.cs +++ /dev/null @@ -1,37 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.InstantMessages -{ - public class SendIm : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (args.Length == 1) - { - if (args[0] == "y") - { - bot.SetLock("sendim_lock", false); - return true; - } - else if (args[0] == "n") - { - bot.SetLock("sendim_lock", true); - return true; - } - return Failed("y/n only"); - } - else if (args.Length == 2) - { - if (UUID.TryParse(args[0], out UUID rec_uuid) == true) - { - return SetFlag(args[1], "set", rec_uuid); - } - return Failed("Unable to process target UUID"); - } - return Failed("Unsupported number of args"); - } - } -} diff --git a/Core/RLV/InstantMessages/sendim_sec.cs b/Core/RLV/InstantMessages/sendim_sec.cs deleted file mode 100644 index 0285f89..0000000 --- a/Core/RLV/InstantMessages/sendim_sec.cs +++ /dev/null @@ -1,18 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.InstantMessages -{ - public class SendIm_Sec : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (args[0] == "y") { bot.SetLock("sendim_lock", false); } - else if (args[0] == "n") { bot.SetLock("sendim_lock", true); } - else { return Failed("y/n only"); } - return true; - } - } -} \ No newline at end of file diff --git a/Core/RLV/Miscellaneous/clear.cs b/Core/RLV/Miscellaneous/clear.cs deleted file mode 100644 index 0d6a02d..0000000 --- a/Core/RLV/Miscellaneous/clear.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Miscellaneous -{ - public class Clear : RLV_command - { - public override bool CallFunction(string[] args) - { - bot.Clearrule(false, caller_uuid); - bot.Clearrule(true, caller_uuid); - return true; - } - } -} diff --git a/Core/RLV/Miscellaneous/getstatus.cs b/Core/RLV/Miscellaneous/getstatus.cs deleted file mode 100644 index fa11842..0000000 --- a/Core/RLV/Miscellaneous/getstatus.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Miscellaneous -{ - public class GetStatus : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - string part = "#"; - string split = "/"; - int channel = -1; - if (args.Length == 1) - { - _ = int.TryParse(args[0], out channel); - } - else if (args.Length == 2) - { - part = args[0]; - _ = int.TryParse(args[1], out channel); - } - else if (args.Length == 3) - { - part = args[0]; - split = args[1]; - _ = int.TryParse(args[2], out channel); - } - if (channel > -1) - { - string reply = ""; - string addon = ""; - if (bot.Getuuid_rules.ContainsKey(caller_uuid) == true) - { - foreach (string rule in bot.Getuuid_rules[caller_uuid].Keys) - { - if ((part == "#") || (rule.Contains(part) == true)) - { - reply = "" + reply + "" + addon + "" + rule + ""; - addon = split; - } - } - } - bot.GetClient.Self.Chat(reply, channel, ChatType.Normal); - return true; - } - return Failed("Invaild channel given"); - } - } -} diff --git a/Core/RLV/Miscellaneous/getstatusall.cs b/Core/RLV/Miscellaneous/getstatusall.cs deleted file mode 100644 index 2a8c5f7..0000000 --- a/Core/RLV/Miscellaneous/getstatusall.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Miscellaneous -{ - public class GetStatusAll : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - string part = "#"; - string split = "/"; - int channel = -1; - if (args.Length == 1) - { - int.TryParse(args[0], out channel); - } - else if (args.Length == 2) - { - part = args[0]; - int.TryParse(args[1], out channel); - } - else if (args.Length == 3) - { - part = args[0]; - split = args[1]; - int.TryParse(args[2], out channel); - } - if (channel > -1) - { - string reply = ""; - string addon = ""; - foreach (UUID a in bot.Getuuid_rules.Keys) - { - foreach (string rule in bot.Getuuid_rules[a].Keys) - { - if ((part == "#") || (rule.Contains(part) == true)) - { - reply = "" + reply + "" + addon + "" + rule + ""; - addon = split; - } - } - } - bot.GetClient.Self.Chat(reply, channel, ChatType.Normal); - return true; - } - else - { - Failed("Invaild channel given"); - } - } - return false; - } - } -} diff --git a/Core/RLV/Miscellaneous/notify.cs b/Core/RLV/Miscellaneous/notify.cs deleted file mode 100644 index e576035..0000000 --- a/Core/RLV/Miscellaneous/notify.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Miscellaneous -{ - public class Notify : RLV_command_2arg - { - public override bool CallFunction(string[] args) - { - _ = int.TryParse(args[0], out int channel); - if (channel >= 0) - { - string word = "#"; - string action; - if (args.Length == 3) - { - word = args[1]; - action = args[2]; - } - else - { - action = args[1]; - } - if ((action == "add") || (action == "n")) - { - bot.NotifyUpdate(true, word, channel); - return true; - } - else if ((action == "rem") || (action == "y")) - { - bot.NotifyUpdate(false, word, channel); - return true; - } - else - { - return Failed("unknown action add/rem only! Action:" + action + " Channel:" + channel.ToString() + " Word: " + word + ""); - } - } - return Failed("Invaild channel given"); - } - } -} diff --git a/Core/RLV/Miscellaneous/permissive.cs b/Core/RLV/Miscellaneous/permissive.cs deleted file mode 100644 index f139ecc..0000000 --- a/Core/RLV/Miscellaneous/permissive.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Miscellaneous -{ - public class Permissive : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - string action = args[0]; - if ((action == "y") || (action == "n")) - { - if (action == "n") - { - bot.SetPermissiveMode(caller_uuid, true); - } - else if (action == "y") - { - bot.SetPermissiveMode(caller_uuid, false); - } - return true; - } - return Failed("Permissive requires y/n!"); - } - } -} diff --git a/Core/RLV/Movement/adjustheight.cs b/Core/RLV/Movement/adjustheight.cs deleted file mode 100644 index d85a251..0000000 --- a/Core/RLV/Movement/adjustheight.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Movement -{ - public class AdjustHeight : RLV_command_3arg - { - public override bool CallFunction(string[] args) - { - int distance_pelvis_to_foot_in_meters = 0; - double factor = 0; - double offset = 0; - if (args[^1] == "force") - { - if(args.Length == 3) - { - int.TryParse(args[0], out distance_pelvis_to_foot_in_meters); - double.TryParse(args[1], out factor); - } - else if (args.Length == 4) - { - int.TryParse(args[0], out distance_pelvis_to_foot_in_meters); - double.TryParse(args[1], out factor); - double.TryParse(args[2], out offset); - } - Double hh = distance_pelvis_to_foot_in_meters * factor; - hh += offset; - if (hh > 2.0) - { - hh = 2.0; - } - else if (hh < -2.0) - { - hh = -2.0; - } - bot.GetClient.Self.SetHoverHeight(hh); - return true; - } - return Failed("Required magic word force missing"); - } - - } -} diff --git a/Core/RLV/Movement/alwaysrun.cs b/Core/RLV/Movement/alwaysrun.cs deleted file mode 100644 index 46394dd..0000000 --- a/Core/RLV/Movement/alwaysrun.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Movement -{ - public class AlwaysRun : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Movement/fly.cs b/Core/RLV/Movement/fly.cs deleted file mode 100644 index 92cfbe4..0000000 --- a/Core/RLV/Movement/fly.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Movement -{ - public class Fly : RLV_UUID_flag_yn - { - } -} diff --git a/Core/RLV/Movement/setrot.cs b/Core/RLV/Movement/setrot.cs deleted file mode 100644 index c1eacda..0000000 --- a/Core/RLV/Movement/setrot.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.RLV.Movement -{ - public class SetRot : RLV_command_2arg - { - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (args[1] == "force") - { - return bot.GetCommandsInterface.Call("rotateto", args[0], UUID.Zero); - } - return Failed("magic word force is required [dont ask me]"); - } - return false; - } - } -} diff --git a/Core/RLV/Movement/temprun.cs b/Core/RLV/Movement/temprun.cs deleted file mode 100644 index 57b895b..0000000 --- a/Core/RLV/Movement/temprun.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Movement -{ - public class TempRun : RLV_UUID_flag_yn - { - - } -} diff --git a/Core/RLV/PrivateChannels/sendchannel.cs b/Core/RLV/PrivateChannels/sendchannel.cs deleted file mode 100644 index c9209f5..0000000 --- a/Core/RLV/PrivateChannels/sendchannel.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.PrivateChannels -{ - public class SendChannel : RLV_UUID_flag_arg_yn - { - } -} diff --git a/Core/RLV/PrivateChannels/sendchannel_except.cs b/Core/RLV/PrivateChannels/sendchannel_except.cs deleted file mode 100644 index 005906c..0000000 --- a/Core/RLV/PrivateChannels/sendchannel_except.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.PrivateChannels -{ - public class SendChannel_Except : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "sendchannel"; } } - } -} diff --git a/Core/RLV/PrivateChannels/sendchannel_sec.cs b/Core/RLV/PrivateChannels/sendchannel_sec.cs deleted file mode 100644 index fe07add..0000000 --- a/Core/RLV/PrivateChannels/sendchannel_sec.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.PrivateChannels -{ - public class SendChannel_Sec : RLV_UUID_flag_arg_yn - { - public override string SetFlagName { get { return "sendchannel"; } } - } -} diff --git a/Core/RLV/RLV_commandlib.cs b/Core/RLV/RLV_commandlib.cs deleted file mode 100644 index 5500654..0000000 --- a/Core/RLV/RLV_commandlib.cs +++ /dev/null @@ -1,230 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using BetterSecondBot.bottypes; -using BetterSecondBotShared.API; -using BetterSecondBotShared.logs; - -namespace BetterSecondBot.RLV -{ - public class RLVcontrol : API_supported_interface - { - protected RLVbot bot; - protected UUID last_caller_uuid = UUID.Zero; - protected string last_caller_name = ""; - - public void SetCallerDetails(UUID callerUUID, string callerName) - { - last_caller_name = callerName; - last_caller_uuid = callerUUID; - } - - public RLVcontrol(RLVbot linktobot) - { - bot = linktobot; - API_type = typeof(RLV_command); - LoadCommandsList(); - } - - protected List suppress_warning = new List(); - public bool Call(string command, string[] args) - { - command = command.ToLowerInvariant(); - RLV_command cmd = (RLV_command)GetCommand(command); - if (cmd != null) - { - if (args.Length >= cmd.Min_Required_args) - { - cmd.Setup(bot, last_caller_uuid, last_caller_name); - return cmd.CallFunction(args); - } - else - { - LogFormater.Warn("[RLVapi/Failed] " + command + ": Incorrect number of args"); - } - } - else - { - if(suppress_warning.Contains(command) == false) - { - suppress_warning.Add(command); - LogFormater.Warn("[RLVapi/Failed] " + command + ": I have no fucking idea what you are talking about"); - } - } - return false; - } - } - public abstract class RLV_command_1arg : RLV_command - { - public override int Min_Required_args { get { return 1; } } - } - public abstract class RLV_command_2arg : RLV_command - { - public override int Min_Required_args { get { return 2; } } - } - public abstract class RLV_command_3arg : RLV_command - { - public override int Min_Required_args { get { return 3; } } - } - public abstract class RLV_command_4arg : RLV_command - { - public override int Min_Required_args { get { return 4; } } - } - public abstract class RLV_command : API_interface - { - public override string Helpfile { get { return "[Class helpfile] an RLV_command."; } } - public virtual string SetFlagName { get { return CommandName.ToLowerInvariant(); } } - protected RLVbot bot; - protected UUID caller_uuid = UUID.Zero; - protected string caller_name = ""; - - public virtual bool AsExceptionRule { get { return false; } } - - - public void Setup(RLVbot setBot, UUID callerUUID, string callerName) - { - bot = setBot; - caller_name = callerName; - caller_uuid = callerUUID; - } - - public virtual bool CallFunction(string[] args) - { - return Failed("Function not overridden"); - } - - public bool Failed(string why_failed) - { - LogFormater.Warn("[RLVapi/Failed] " + CommandName + ": " + why_failed); - return false; - } - - protected bool SetFlag(string signal,string arg) - { - return SetFlag(signal, arg, caller_uuid); - } - protected bool SetFlag(string signal, string arg,UUID caller) - { - if ((signal == "y") || (signal == "rem")) - { - return bot.RemoveRule(AsExceptionRule, SetFlagName, caller); - } - else if ((signal == "n") || (signal == "add")) - { - return bot.UpdateRule(AsExceptionRule, SetFlagName, arg, caller); - } - return Failed("[RLV/Debug] arg only accepts y/n or add/rem for control signaling [Sig: " + signal+" Arg: "+arg+"]"); - } - } - public abstract class RLV_1arg_force : RLV_command_1arg - { - public override string Helpfile { get { return "[Class helpfile] Requires you send =force at the end of the command..."; } } - public override string[] ArgTypes { get { return new[] { "TEXT" }; } } - public override string[] ArgHints { get { return new[] { "The word force"}; } } - - public override bool CallFunction(string[] args) - { - if (args.Length > 0) - { - if (args[0] == "force") - { - return true; - } - return Failed("Magic word force is missing"); - } - return Failed("[RLV/WARN] RLV_1arg_force invaild number of args"); - } - } - - - public abstract class RLV_UUID_flag_4arg_yn : RLV_UUID_flag_optional_arg_yn - { - public override int Min_Required_args { get { return 4; } } - public override string Helpfile { get { return "[Class helpfile] RLV / 4arg"; } } - public override string[] ArgTypes { get { return new[] { "Unknown", "Unknown", "Unknown", "Unknown" }; } } - public override string[] ArgHints { get { return new[] { "Unknown", "Unknown", "Unknown", "Unknown" }; } } - } - - public abstract class RLV_UUID_flag_optional_arg_yn : RLV_command_1arg - { - public override string Helpfile { get { return "[Class helpfile] RLV / UUID_flag_optional_arg_yn"; } } - public override string[] ArgTypes { get { return new[] { "Unknown", "Unknown"}; } } - public override string[] ArgHints { get { return new[] { "Unknown", "Unknown" }; } } - - public override bool CallFunction(string[] args) - { - if (args.Length == 2) - { - return SetFlag(args[^1], args[0]); - } - else if (args.Length > 0) - { - return SetFlag(args[^1], "set"); - } - return Failed("[RLV/WARN] RLV_UUID_flag_optional_arg_yn invaild number of args"); - } - } - - public abstract class RLV_UUID_flag_yn : RLV_command_1arg - { - public override string Helpfile { get { return "[Class helpfile] RLV / UUID_flag_yn "; } } - public override string[] ArgTypes { get { return new[] { "Unknown", "Unknown" }; } } - public override string[] ArgHints { get { return new[] { "Unknown", "Unknown" }; } } - public override bool CallFunction(string[] args) - { - if (args.Length >= 1) - { - return SetFlag(args[0], "set"); - } - return Failed("[RLV/WARN] RLV_UUID_flag_yn invaild number of args"); - } - } - public abstract class RLV_UUID_flag_get : RLV_command_1arg - { - public abstract string LookupFlag { get; } - public override string Helpfile { get { return "[Class helpfile]
Gets the flag value "+LookupFlag+" and returns it on channel [ARG 1]"; } } - public override string[] ArgTypes { get { return new[] { "Number"}; } } - public override string[] ArgHints { get { return new[] { "Channel" }; } } - public override bool CallFunction(string[] args) - { - if (args.Length == 1) - { - _ = int.TryParse(args[0], out int channel); - if (channel >= 0) - { - if (bot.Getuuid_rules.ContainsKey(caller_uuid) == true) - { - if (bot.Getuuid_rules[caller_uuid].ContainsKey(LookupFlag) == true) - { - bot.GetClient.Self.Chat(bot.Getuuid_rules[caller_uuid][LookupFlag], channel, ChatType.Normal); - } - } - return true; - } - else - { - return Failed("Channel number not vaild"); - } - } - return Failed("[RLV/WARN] RLV_UUID_flag_get invaild number of args"); - } - } - public abstract class RLV_UUID_flag_arg_yn : RLV_command_2arg - { - public override string Helpfile { get { return "[Class helpfile]
RLV / UUID_flag_arg_yn
When clearing please set [ARG 1] to Anything
Flags are tracked per object"; } } - public override string[] ArgTypes { get { return new[] { "Mixed", "Flag" }; } } - public override string[] ArgHints { get { return new[] { "The arg value you are setting", "[Y/N] or [Rem/Add]" }; } } - public override bool CallFunction(string[] args) - { - if (args.Length == 2) - { - return SetFlag(args[1], args[0]); - } - return Failed("[RLV/WARN] RLV_UUID_flag_arg_yn invaild number of args"); - } - } - - -} diff --git a/Core/RLV/Sitting/getsitid.cs b/Core/RLV/Sitting/getsitid.cs deleted file mode 100644 index 0a21e11..0000000 --- a/Core/RLV/Sitting/getsitid.cs +++ /dev/null @@ -1,31 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Sitting -{ - class GetSitId : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - _ = int.TryParse(args[0], out int channel); - if (channel > -1) - { - if(bot.GetClient.Self.SittingOn > 0) - { - if(bot.GetClient.Network.CurrentSim.ObjectsPrimitives.ContainsKey(bot.GetClient.Self.SittingOn)) - { - Primitive obj = bot.GetClient.Network.CurrentSim.ObjectsPrimitives[bot.GetClient.Self.SittingOn]; - - bot.GetClient.Self.Chat(obj.ID.ToString(), channel, OpenMetaverse.ChatType.Normal); - return true; - } - } - bot.GetClient.Self.Chat(UUID.Zero.ToString(), channel, OpenMetaverse.ChatType.Normal); - return true; - } - return Failed("Invaild channel given"); - } - } -} diff --git a/Core/RLV/Sitting/sit.cs b/Core/RLV/Sitting/sit.cs deleted file mode 100644 index 40e910c..0000000 --- a/Core/RLV/Sitting/sit.cs +++ /dev/null @@ -1,30 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Sitting -{ - public class Sit : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (args.Length == 1) - { - return SetFlag(args[0], "set"); - } - else if (args.Length == 2) - { - if (args[1] == "force") - { - return bot.GetCommandsInterface.Call("BotSit", args[0], UUID.Zero); - } - else - { - return Failed("Magic keyword force missing."); - } - } - return Failed("Badly formatted command."); - } - } -} diff --git a/Core/RLV/Sitting/unsit.cs b/Core/RLV/Sitting/unsit.cs deleted file mode 100644 index 00f2b53..0000000 --- a/Core/RLV/Sitting/unsit.cs +++ /dev/null @@ -1,23 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Sitting -{ - public class UnSit : RLV_command_1arg - { - public override bool CallFunction(string[] args) - { - if (args[0] == "force") - { - return bot.GetCommandsInterface.Call("stand", "", UUID.Zero); - } - else if ((args[0] == "y") || (args[0] == "n")) - { - return SetFlag(args[0], "set"); - } - return Failed("Magic keyword force missing."); - } - } -} diff --git a/Core/RLV/Version/version.cs b/Core/RLV/Version/version.cs deleted file mode 100644 index 4056068..0000000 --- a/Core/RLV/Version/version.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Version -{ - public class Version : RLV_command - { - public override bool CallFunction(string[] args) - { - int channel = 0; - if (args.Length == 1) - { - _ = int.TryParse(args[0], out channel); - } - if (channel >= 0) - { - bot.GetClient.Self.Chat("RestrainedLife BOT (RLVa 2.9)", channel, OpenMetaverse.ChatType.Normal); - return true; - } - else - { - return Failed("Invaild channel given"); - } - } - } -} diff --git a/Core/RLV/Version/versionnew.cs b/Core/RLV/Version/versionnew.cs deleted file mode 100644 index db3e55c..0000000 --- a/Core/RLV/Version/versionnew.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Version -{ - public class VersionNew : RLV_command - { - public override bool CallFunction(string[] args) - { - int channel = 0; - if (args.Length == 1) - { - _ = int.TryParse(args[0], out channel); - } - if (channel >= 0) - { - bot.GetClient.Self.Chat("RestrainedLove BOT (RLVa 2.9)", channel, OpenMetaverse.ChatType.Normal); - return true; - } - else - { - return Failed("Invaild channel given"); - } - } - } -} diff --git a/Core/RLV/Version/versionnum.cs b/Core/RLV/Version/versionnum.cs deleted file mode 100644 index 0e36223..0000000 --- a/Core/RLV/Version/versionnum.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.RLV.Version -{ - public class VersionNum : RLV_command - { - public override bool CallFunction(string[] args) - { - int channel = 0; - if (args.Length == 1) - { - _ = int.TryParse(args[0], out channel); - } - if (channel >= 0) - { - bot.GetClient.Self.Chat("209000", channel, OpenMetaverse.ChatType.Normal); - return true; - } - else - { - return Failed("Invaild channel given"); - } - } - } -} diff --git a/Core/bottypes/AVstorageBot.cs b/Core/bottypes/AVstorageBot.cs index b3aadab..babef89 100644 --- a/Core/bottypes/AVstorageBot.cs +++ b/Core/bottypes/AVstorageBot.cs @@ -287,38 +287,6 @@ namespace BetterSecondBot.bottypes } } - protected string httpLookupKey(string avatar_name) - { - if (myconfig.Name2Key_Enable == true) - { - var client = new RestClient(myconfig.Name2Key_Url); - var request = new RestRequest("name2key/" + avatar_name + "/" + myconfig.Name2Key_Key + "", Method.GET); - client.Timeout = 3000; // ? does this even do anything - request.Timeout = 3000; - IRestResponse endpoint_checks = client.Get(request); - if (endpoint_checks.StatusCode == System.Net.HttpStatusCode.OK) - { - try - { - namekeyservicereply server_reply = JsonConvert.DeserializeObject(endpoint_checks.Content); - if (server_reply.status == true) - { - if (server_reply.found == true) - { - AddAvatarToDB((UUID)server_reply.uuid, server_reply.name); - return server_reply.uuid; - } - } - } - catch - { - - } - } - } - return ""; - } - protected string FindAvatarUUIDInStorage(string avatar_name) { if (AvatarStorageLastUsed.ContainsKey(avatar_name) == true) @@ -355,11 +323,6 @@ namespace BetterSecondBot.bottypes { return uuid; } - uuid = httpLookupKey(avatar_name); - if (uuid != "") - { - return uuid; - } if (PendingAvatarFinds_vianame.ContainsKey(avatar_name) == false) { PendingAvatarFinds_vianame.Add(avatar_name, new KeyValuePair(helpers.UnixTimeNow(), 0)); @@ -383,38 +346,6 @@ namespace BetterSecondBot.bottypes return ""; } - protected string httpLookupName(UUID avatar_uuid) - { - if (myconfig.Name2Key_Enable == true) - { - var client = new RestClient(myconfig.Name2Key_Url); - var request = new RestRequest("key2name/" + avatar_uuid.ToString() + "/" + myconfig.Name2Key_Key + "", Method.GET); - client.Timeout = 3000; // ? does this even do anything - request.Timeout = 3000; - IRestResponse endpoint_checks = client.Get(request); - if (endpoint_checks.StatusCode == System.Net.HttpStatusCode.OK) - { - try - { - namekeyservicereply server_reply = JsonConvert.DeserializeObject(endpoint_checks.Content); - if (server_reply.status == true) - { - if (server_reply.found == true) - { - AddAvatarToDB((UUID)server_reply.uuid, server_reply.name); - return server_reply.name; - } - } - } - catch - { - - } - } - } - return ""; - } - public string FindAvatarKey2Name(UUID avatar_uuid) { @@ -423,11 +354,6 @@ namespace BetterSecondBot.bottypes { return avatar_name; } - avatar_name = httpLookupName(avatar_uuid); - if (avatar_name != "") - { - return avatar_name; - } if (PendingAvatarFinds_viauuid.ContainsKey(avatar_uuid) == false) { PendingAvatarFinds_viauuid.Add(avatar_uuid, new KeyValuePair(helpers.UnixTimeNow(), 0)); @@ -442,16 +368,6 @@ namespace BetterSecondBot.bottypes } } - public class namekeyservicereply - { - public string lookingfor { get; set; } - public string uuid { get; set; } - public string name { get; set; } - public bool found { get; set; } - public bool status { get; set; } - public string message { get; set; } - } - public class friendreplyobject { public string name; diff --git a/Core/bottypes/RLVbot.cs b/Core/bottypes/RLVbot.cs deleted file mode 100644 index 9b200a7..0000000 --- a/Core/bottypes/RLVbot.cs +++ /dev/null @@ -1,298 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using BetterSecondBotShared.Json; -using OpenMetaverse; -using BetterSecondBotShared.logs; - -namespace BetterSecondBot.bottypes -{ - public abstract class RLVbot : RLVbotHelper - { - // normal bot stuff - protected RLV.RLVcontrol RLVinterface; - public RLV.RLVcontrol GetRLVinterface { get { return RLVinterface; } } - - public override void Setup(JsonConfig config, string Version) - { - base.Setup(config, Version); - if (reconnect == false) - { - if (myconfig.Setting_AllowRLV == true) - { - Info("RLV: Enabled"); - RLVinterface = new RLV.RLVcontrol(this); - } - } - } - - protected override void ChatInputHandler(object sender, ChatEventArgs e) - { - base.ChatInputHandler(sender, e); - if (e.Type == ChatType.OwnerSay) - { - if (myconfig.Setting_AllowRLV == true) - { - if (e.Message.StartsWith("@") == true) - { - string message_text = e.Message.Substring(1); - bool permissive_allow = true; - if (permissive_allow == true) - { - string[] requested_commands = message_text.Split(','); - foreach (string R in requested_commands) - { - List args = new List(); - string command = ""; - string[] build = R.Split('='); - string[] build2 = build[0].Split(':'); - if (build2.Length == 2) - { - string[] build3 = build2[1].Split(';'); - foreach (string build_arg in build3) - { - args.Add(build_arg); - } - } - command = build2[0]; - if (build.Length == 2) - { - args.Add(build[1]); - } - if (blacklist_recvim.Contains(command) == false) - { - if (Notify.ContainsKey("#") == true) - { - foreach (int channel in Notify["#"]) - { - Client.Self.Chat("/" + message_text, channel, ChatType.Normal); - } - } - if (Notify.ContainsKey(command) == true) - { - foreach (int channel in Notify[command]) - { - Client.Self.Chat("/" + message_text, channel, ChatType.Normal); - } - } - RLVinterface.SetCallerDetails(e.SourceID, e.FromName); - RLVinterface.Call(command, args.ToArray()); - } - else - { - Debug("RLV API -> blacklisted [" + command + "]"); - } - } - } - } - } - } - } - } - - - public class RLVbotHelper : AwaitReplyEventBot - { - #region PermissiveMode - // permissive - protected bool permissive_mode = true; - protected UUID permissive_mode_set_by = UUID.Zero; - public UUID Getpermissive_mode_set_by { get { return permissive_mode_set_by; } } - - public void SetPermissiveMode(UUID caller) - { - SetPermissiveMode(caller, false); - } - public void SetPermissiveMode(UUID caller, bool status) - { - bool allow = true; - if((permissive_mode == false) && (caller != permissive_mode_set_by)) - { - allow = false; - } - if(allow == true) - { - permissive_mode = status; - if (status == false) - { - permissive_mode_set_by = UUID.Zero; - } - else - { - permissive_mode_set_by = caller; - } - } - } - #endregion - - #region blacklist - // Blacklist - protected List blacklist_sendim = new List(); - protected List blacklist_recvim = new List(); - public List Getblacklist_sendim { get { return blacklist_sendim; } } - public List Getblacklist_recvim { get { return blacklist_recvim; } } - #endregion - - #region UUID rules Exceptions - // UUID based rules / Exceptions - protected Dictionary> uuid_rules = new Dictionary>(); - protected Dictionary> uuid_exceptions = new Dictionary>(); - public Dictionary> Getuuid_rules { get { return uuid_rules; } } - public Dictionary> Getuuid_exceptions { get { return uuid_exceptions; } } - public bool Clearrule(bool as_exception, UUID soruce) - { - return RemoveRule(as_exception, null, soruce); - } - public bool UpdateRule(bool as_exception, string rule, string arg, UUID source) - { - if (as_exception == false) - { - lock (uuid_rules) - { - if (uuid_rules.ContainsKey(source) == false) - { - uuid_rules.Add(source, new Dictionary()); - } - if (uuid_rules[source].ContainsKey(rule) == true) - { - uuid_rules[source].Remove(rule); - } - uuid_rules[source].Add(rule, arg); - } - } - else - { - lock (uuid_exceptions) - { - if (uuid_exceptions.ContainsKey(source) == false) - { - uuid_exceptions.Add(source, new Dictionary()); - } - if (uuid_exceptions[source].ContainsKey(rule) == true) - { - uuid_exceptions[source].Remove(rule); - } - uuid_exceptions[source].Add(rule, arg); - } - } - return true; - } - public bool RemoveRule(bool as_exception, string rule, UUID source) - { - if (as_exception == false) - { - lock (uuid_rules) - { - if (uuid_rules.ContainsKey(source) == true) - { - if (rule != null) - { - if (uuid_rules[source].ContainsKey(rule) == true) - { - uuid_rules[source].Remove(rule); - } - if (uuid_rules[source].Count == 0) - { - uuid_rules.Remove(source); - } - } - else - { - uuid_rules.Remove(source); - } - } - } - } - else - { - lock (uuid_exceptions) - { - if (rule != null) - { - if (uuid_exceptions[source].ContainsKey(rule) == true) - { - uuid_exceptions[source].Remove(rule); - } - if (uuid_exceptions[source].Count == 0) - { - uuid_exceptions.Remove(source); - } - } - else - { - uuid_exceptions.Remove(source); - } - } - } - return true; - } - #endregion - - #region Flags - // Flags - protected bool recvchat_channel_zero_lock = true; - protected bool sendchannel_lock; - protected bool recvemote_lock; - protected bool sendim_lock; - public void SetLock(string name, bool status) - { - if (name == "sendim_lock") { sendim_lock = status; } - else if (name == "recvemote_lock") { recvemote_lock = status; } - else if (name == "sendchannel_lock") { sendchannel_lock = status; } - else if (name == "recvchat_channel_zero_lock") { recvchat_channel_zero_lock = status; } - } - #endregion - - #region Notify - // Notify - protected Dictionary> Notify = new Dictionary>(); - public Dictionary> Getnotify { get { return Notify; } } - - public void NotifyUpdate(bool Add, string word) - { - NotifyUpdate(Add, word, -1); - } - - public void NotifyUpdate(bool Add, string word,int channel) - { - lock (Notify) - { - if (Add == true) - { - if (Notify.ContainsKey(word) == false) - { - Notify.Add(word, new List()); - } - if (channel > -1) - { - if (Notify[word].Contains(channel) == false) - { - Notify[word].Add(channel); - } - } - } - else - { - if (Notify.ContainsKey(word) == true) - { - if (Notify[word].Contains(channel) == true) - { - Notify[word].Remove(channel); - if(Notify[word].Count == 0) - { - Notify.Remove(word); - } - } - if (channel == -1) - { - Notify.Remove(word); - } - - } - } - } - } - #endregion - - } -} diff --git a/Core/bottypes/chatrelay.cs b/Core/bottypes/chatrelay.cs index af7fd4a..3a3063b 100644 --- a/Core/bottypes/chatrelay.cs +++ b/Core/bottypes/chatrelay.cs @@ -6,7 +6,7 @@ using System.Linq; namespace BetterSecondBot.bottypes { - public abstract class ChatRelay : RLVbot + public abstract class ChatRelay : AwaitReplyEventBot { #region GroupIMs protected int localchatlimit = 20; diff --git a/Core/bottypes/loadorder.txt b/Core/bottypes/loadorder.txt index e820b70..4749b11 100644 --- a/Core/bottypes/loadorder.txt +++ b/Core/bottypes/loadorder.txt @@ -1,4 +1,3 @@ -SecondBot -> DialogsBot -> ChatRelay -> RLVbot -> RLVbotHelper -> -AwaitReplyEventBot -> CommandsBot -> AVstorageBot -> AttachableBot -> +SecondBot -> DialogsBot -> ChatRelay -> AwaitReplyEventBot -> CommandsBot -> AVstorageBot -> AttachableBot -> MessageSwitcherBot -> EventsBot -> VoidEventBot -> AnimationsBot -> VirtualsBot -> Log2FileBot -> ActionsAutoAcceptBot -> BasicBot \ No newline at end of file From de5f0cf173df8a285f5e4f7fc0b3cd8a6f334453 Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Wed, 17 Feb 2021 05:03:50 +0000 Subject: [PATCH 2/5] the old core is dying :( http is better thou :) --- BetterSecondbot/HttpService/Avatars.cs | 33 +- BetterSecondbot/HttpService/Core.cs | 118 +--- BetterSecondbot/HttpService/Discord.cs | 626 +++++++++++++++++- BetterSecondbot/HttpService/Estate.cs | 176 ++++- BetterSecondbot/HttpService/Friends.cs | 114 ++++ BetterSecondbot/HttpService/Funds.cs | 112 ++++ BetterSecondbot/HttpService/Group.cs | 571 +++++++++++++--- BetterSecondbot/HttpService/Home.cs | 33 + BetterSecondbot/HttpService/HttpAsService.cs | 9 +- BetterSecondbot/HttpService/Info.cs | 116 ++++ BetterSecondbot/HttpService/Self.cs | 131 ++++ .../Commands/DiscordAPI/BulkClear_Messages.cs | 75 --- Core/Commands/DiscordAPI/Dm_Member.cs | 65 -- Core/Commands/DiscordAPI/MembersList.cs | 58 -- Core/Commands/DiscordAPI/MessageChannel.cs | 43 -- Core/Commands/DiscordAPI/MuteMember.cs | 57 -- Core/Commands/DiscordAPI/RoleCreate.cs | 47 -- Core/Commands/DiscordAPI/RoleList.cs | 49 -- Core/Commands/DiscordAPI/RoleRemove.cs | 49 -- Core/Commands/DiscordAPI/Role_GetSettings.cs | 84 --- Core/Commands/DiscordAPI/Role_UpdatePerms.cs | 165 ----- Core/Commands/DiscordAPI/TextChannels_List.cs | 49 -- Core/Commands/Estate/EstateParcelReclaim.cs | 25 - Core/Commands/Estate/GetSimGlobalPos.cs | 27 - Core/Commands/Estate/GetSimTexture.cs | 25 - Core/Commands/Estate/SimMessage.cs | 26 - Core/Commands/Estate/SimRestart.cs | 45 -- Core/Commands/Friends/FriendFullPerms.cs | 42 -- Core/Commands/Friends/FriendRequest.cs | 28 - Core/Commands/Friends/Friendslist.cs | 18 - Core/Commands/Group/GroupActiveGroup.cs | 38 -- Core/Commands/Group/GroupActiveTitle.cs | 31 - Core/Commands/Group/GroupAddRole.cs | 108 --- Core/Commands/Group/GroupEject.cs | 45 -- Core/Commands/Group/GroupInvite.cs | 65 -- Core/Commands/Group/GroupInviteNoLimiter.cs | 58 -- Core/Commands/Group/GroupNotice.cs | 53 -- Core/Commands/Group/IsGroupMember.cs | 92 --- Core/Commands/Group/getGroupList.cs | 20 - Core/Commands/Group/getGroupMembers.cs | 58 -- Core/Commands/Group/getGroupRoles.cs | 50 -- Core/Commands/Group/group.cs | 58 -- Core/Commands/Group/groupchat.cs | 62 -- Core/Commands/Group/groupchatAnyUnread.cs | 11 - Core/Commands/Group/groupchatClearAll.cs | 16 - .../Commands/Group/groupchatGroupHasUnread.cs | 15 - Core/Commands/Group/groupchatHistory.cs | 22 - .../Group/groupchatListAllUnreadGroups.cs | 21 - Core/Commands/Home/GoHome.cs | 16 - Core/Commands/Home/resetAtHome.cs | 16 - Core/Commands/Info/Balance.cs | 21 - Core/Commands/Info/GetPosition.cs | 15 - Core/Commands/Info/ParcelName.cs | 16 - Core/Commands/Info/SimName.cs | 15 - Core/Commands/Info/UnixTimeNow.cs | 17 - Core/Commands/Self/CickObject.cs | 49 -- Core/Commands/Self/Help.cs | 74 --- Core/Commands/Self/PayObject.cs | 45 -- Core/Commands/Self/botVersion.cs | 15 - Core/Commands/Self/logout.cs | 3 +- Core/Commands/Self/pointAt.cs | 40 -- Core/Commands/Self/sit.cs | 37 -- Core/Commands/Self/stand.cs | 13 - Core/bottypes/EventsBot.cs | 9 + 64 files changed, 1769 insertions(+), 2471 deletions(-) create mode 100644 BetterSecondbot/HttpService/Friends.cs create mode 100644 BetterSecondbot/HttpService/Funds.cs create mode 100644 BetterSecondbot/HttpService/Home.cs create mode 100644 BetterSecondbot/HttpService/Info.cs create mode 100644 BetterSecondbot/HttpService/Self.cs delete mode 100644 Core/Commands/DiscordAPI/BulkClear_Messages.cs delete mode 100644 Core/Commands/DiscordAPI/Dm_Member.cs delete mode 100644 Core/Commands/DiscordAPI/MembersList.cs delete mode 100644 Core/Commands/DiscordAPI/MessageChannel.cs delete mode 100644 Core/Commands/DiscordAPI/MuteMember.cs delete mode 100644 Core/Commands/DiscordAPI/RoleCreate.cs delete mode 100644 Core/Commands/DiscordAPI/RoleList.cs delete mode 100644 Core/Commands/DiscordAPI/RoleRemove.cs delete mode 100644 Core/Commands/DiscordAPI/Role_GetSettings.cs delete mode 100644 Core/Commands/DiscordAPI/Role_UpdatePerms.cs delete mode 100644 Core/Commands/DiscordAPI/TextChannels_List.cs delete mode 100644 Core/Commands/Estate/EstateParcelReclaim.cs delete mode 100644 Core/Commands/Estate/GetSimGlobalPos.cs delete mode 100644 Core/Commands/Estate/GetSimTexture.cs delete mode 100644 Core/Commands/Estate/SimMessage.cs delete mode 100644 Core/Commands/Estate/SimRestart.cs delete mode 100644 Core/Commands/Friends/FriendFullPerms.cs delete mode 100644 Core/Commands/Friends/FriendRequest.cs delete mode 100644 Core/Commands/Friends/Friendslist.cs delete mode 100644 Core/Commands/Group/GroupActiveGroup.cs delete mode 100644 Core/Commands/Group/GroupActiveTitle.cs delete mode 100644 Core/Commands/Group/GroupAddRole.cs delete mode 100644 Core/Commands/Group/GroupEject.cs delete mode 100644 Core/Commands/Group/GroupInvite.cs delete mode 100644 Core/Commands/Group/GroupInviteNoLimiter.cs delete mode 100644 Core/Commands/Group/GroupNotice.cs delete mode 100644 Core/Commands/Group/IsGroupMember.cs delete mode 100644 Core/Commands/Group/getGroupList.cs delete mode 100644 Core/Commands/Group/getGroupMembers.cs delete mode 100644 Core/Commands/Group/getGroupRoles.cs delete mode 100644 Core/Commands/Group/group.cs delete mode 100644 Core/Commands/Group/groupchat.cs delete mode 100644 Core/Commands/Group/groupchatAnyUnread.cs delete mode 100644 Core/Commands/Group/groupchatClearAll.cs delete mode 100644 Core/Commands/Group/groupchatGroupHasUnread.cs delete mode 100644 Core/Commands/Group/groupchatHistory.cs delete mode 100644 Core/Commands/Group/groupchatListAllUnreadGroups.cs delete mode 100644 Core/Commands/Home/GoHome.cs delete mode 100644 Core/Commands/Home/resetAtHome.cs delete mode 100644 Core/Commands/Info/Balance.cs delete mode 100644 Core/Commands/Info/GetPosition.cs delete mode 100644 Core/Commands/Info/ParcelName.cs delete mode 100644 Core/Commands/Info/SimName.cs delete mode 100644 Core/Commands/Info/UnixTimeNow.cs delete mode 100644 Core/Commands/Self/CickObject.cs delete mode 100644 Core/Commands/Self/Help.cs delete mode 100644 Core/Commands/Self/PayObject.cs delete mode 100644 Core/Commands/Self/botVersion.cs delete mode 100644 Core/Commands/Self/pointAt.cs delete mode 100644 Core/Commands/Self/sit.cs delete mode 100644 Core/Commands/Self/stand.cs diff --git a/BetterSecondbot/HttpService/Avatars.cs b/BetterSecondbot/HttpService/Avatars.cs index 62903dc..ecba2f6 100644 --- a/BetterSecondbot/HttpService/Avatars.cs +++ b/BetterSecondbot/HttpService/Avatars.cs @@ -76,37 +76,6 @@ namespace BetterSecondBot.HttpService } - [About("Makes the bot pay a avatar")] - [ReturnHints("Accepted")] - [ReturnHints("avatar lookup")] - [ReturnHints("Invaild amount")] - [ReturnHints("Transfer funds to avatars disabled")] - [Route(HttpVerbs.Get, "/PayAvatar/{avatar}/{amount}/{token}")] - public object PayAvatar(string avatar,string amount,string token) - { - if (tokens.Allow(token, "avatars", "payavatar", getClientIP()) == false) - { - return BasicReply("Token not accepted"); - } - if (bot.GetAllowFunds == false) - { - return BasicReply("Transfer funds to avatars disabled"); - } - ProcessAvatar(avatar); - if (avataruuid == UUID.Zero) - { - return BasicReply("avatar lookup"); - } - if (int.TryParse(amount, out int amountvalue) == false) - { - return BasicReply("Invaild amount"); - } - if(amountvalue < 1) - { - return BasicReply("Invaild amount"); - } - bot.GetClient.Self.GiveAvatarMoney(avataruuid, amountvalue); - return BasicReply("Accepted"); - } + } } diff --git a/BetterSecondbot/HttpService/Core.cs b/BetterSecondbot/HttpService/Core.cs index 3defd91..4b08816 100644 --- a/BetterSecondbot/HttpService/Core.cs +++ b/BetterSecondbot/HttpService/Core.cs @@ -47,21 +47,11 @@ namespace BetterSecondBot.HttpService if(newtoken != null) return BasicReply(newtoken); } } - return BasicReply("Authcode not accepted"); + return Failure("Authcode not accepted"); } - [About("Gets the friendslist
Formated as follows
friendreplyobject
  • name: String
  • id: String
  • online: bool
")] - [ReturnHints("array UUID = friendreplyobject")] - [Route(HttpVerbs.Get, "/Friends/{token}")] - public object Friends(string token) - { - if (tokens.Allow(token, "core", "friends", getClientIP()) == true) - { - return BasicReply(bot.getJsonFriendlist()); - } - return BasicReply("Token not accepted"); - } + [About("uses the AutoPilot to move to a location")] [ReturnHints("Error Unable to AutoPilot to location")] @@ -79,9 +69,9 @@ namespace BetterSecondBot.HttpService { return BasicReply("Accepted"); } - return BasicReply("Error Unable to AutoPilot to location"); + return Failure("Error Unable to AutoPilot to location"); } - return BasicReply("Token not accepted"); + return Failure("Token not accepted"); } @@ -103,33 +93,11 @@ namespace BetterSecondBot.HttpService { return BasicReply("Accepted"); } - return BasicReply("Error Unable to Teleport to location"); + return Failure("Error Unable to Teleport to location"); } - return BasicReply("Token not accepted"); + return Failure("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) - { - if (tokens.Allow(token, "core", "regiontile", getClientIP()) == true) - { - if (bot.GetClient.Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region)) - { - return BasicReply(region.MapImageID.ToString()); - } - else - { - return BasicReply("Unable to find region"); - } - } - return BasicReply("Token not accepted"); - } - - [About("Used to check HTTP connections")] [ReturnHints("world")] @@ -144,79 +112,19 @@ namespace BetterSecondBot.HttpService [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) + [Route(HttpVerbs.Get, "/LogoutUI/{token}")] + public object LogoutUI(string token) { - if (tokens.Allow(token, "core", "logout", getClientIP()) == true) + if (tokens.Allow(token, "core", "LogoutUI", getClientIP()) == true) { return tokens.Expire(token); } - return BasicReply("Token not accepted"); + return Failure("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) - { - if (tokens.Allow(token, "core", "version", getClientIP()) == true) - { - return BasicReply(bot.MyVersion); - } - 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) - { - if (tokens.Allow(token, "core", "name", getClientIP()) == true) - { - return BasicReply(bot.GetClient.Self.FirstName + " " + bot.GetClient.Self.LastName); - } - 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, "core", "regionname", getClientIP()) == true) - { - 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, "core", "location", getClientIP()) == true) - { - 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")] @@ -240,11 +148,11 @@ namespace BetterSecondBot.HttpService { return BasicReply("accepted"); } - return BasicReply("Failed"); + return Failure("Failed"); } - return BasicReply("Auth not accepted"); + return Failure("Auth not accepted"); } - return BasicReply("Token not accepted"); + return Failure("Token not accepted"); } } diff --git a/BetterSecondbot/HttpService/Discord.cs b/BetterSecondbot/HttpService/Discord.cs index 598a42b..da52785 100644 --- a/BetterSecondbot/HttpService/Discord.cs +++ b/BetterSecondbot/HttpService/Discord.cs @@ -12,6 +12,8 @@ using System.Reflection; using Discord.WebSocket; using System.Threading.Tasks; using Discord; +using BetterSecondBotShared.Static; +using Discord.Rest; namespace BetterSecondBot.HttpService { @@ -21,8 +23,7 @@ namespace BetterSecondBot.HttpService [About("Adds a discord server role to the selected member")] [ReturnHints("Discord client not ready")] - [ReturnHints("true")] - [ReturnHints("false")] + [ReturnHints("true|false")] [ArgHints("serverid","URLARG","the server id to apply this action to")] [ArgHints("roleid", "URLARG", "the role id we are giving")] [ArgHints("memberid", "URLARG", "who we are giving it to")] @@ -31,36 +32,640 @@ namespace BetterSecondBot.HttpService { if (tokens.Allow(token, "discord", "Discord_AddRole", getClientIP()) == false) { - return BasicReply("Token not accepted"); + return Failure("Token not accepted"); } if (bot.discordReady() == false) { - return BasicReply("Discord client not ready"); + return Failure("Discord client not ready"); } return BasicReply(addRoleToMember(serverid, roleid, memberid).Result.ToString()); } [About("Adds the selected user to the ban list - Disallows rejoining untill they are removed from the list")] [ReturnHints("Discord client not ready")] - [ReturnHints("true")] - [ReturnHints("false")] + [ReturnHints("Why empty")] + [ReturnHints("true|false")] [ArgHints("serverid", "URLARG", "the server id to apply this action to")] [ArgHints("memberid", "URLARG", "who we are giving it to")] [ArgHints("why", "string", "why they are being banned")] - [Route(HttpVerbs.Get, "/Discord_BanMember/{serverid}/{memberid}/{token}")] + [Route(HttpVerbs.Post, "/Discord_BanMember/{serverid}/{memberid}/{token}")] public object Discord_BanMember(string serverid, string memberid, [FormField] string why, string token) { if (tokens.Allow(token, "discord", "Discord_BanMember", getClientIP()) == false) { - return BasicReply("Token not accepted"); + return Failure("Token not accepted"); } if (bot.discordReady() == false) { - return BasicReply("Discord client not ready"); + return Failure("Discord client not ready"); + } + if (helpers.notempty(why) == false) + { + return Failure("Why empty"); } return BasicReply(BanMember(serverid, memberid, why).Result.ToString()); } + [About("Clears messages on the server sent by the member in the last 13 days, 22hours 59mins")] + [ReturnHints("Discord client not ready")] + [ReturnHints("true|false")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("memberid", "URLARG", "who we are giving it to")] + [Route(HttpVerbs.Get, "/Discord_BulkClear_Messages/{serverid}/{memberid}/{token}")] + public object Discord_BulkClear_Messages(string serverid, string memberid, string token) + { + if (tokens.Allow(token, "discord", "Discord_BulkClear_Messages", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return ClearMessages(serverid, memberid).Result; + } + + [About("Sends a message directly to the user [They must be in the server]\n This command requires the SERVER MEMBERS INTENT found in discord app dev")] + [ReturnHints("Discord client not ready")] + [ReturnHints("true|false")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("memberid", "URLARG", "who we are giving it to")] + [ArgHints("message", "Text", "what we are sending")] + [Route(HttpVerbs.Post, "/Discord_Dm_Member/{serverid}/{memberid}/{token}")] + public object Discord_Dm_Member(string serverid, string memberid, [FormField] string message, string token) + { + if (tokens.Allow(token, "discord", "Discord_Dm_Member", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return BasicReply(MessageMember(serverid, memberid, message).Result.ToString()); + } + + [About("Returns a list of members in a server \n collection is userid: username \n if the user has set a nickname: userid: nickname|username \n" + + " This command requires Discord full client mode enabled and connected\n !!!! This command also requires: Privileged Gateway Intents / " + + "SERVER MEMBERS INTENT set to true on the discord bot api area !!!")] + [ReturnHints("Discord client not ready")] + [ReturnHints("mixed array of userid: nickname|username or userid:username")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [Route(HttpVerbs.Get, "/Discord_MembersList/{serverid}/{token}")] + public object Discord_MembersList(string serverid, string token) + { + if (tokens.Allow(token, "discord", "Discord_MembersList", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return ListMembers(serverid).Result; + } + + [About("Sends a message to the selected channel - Optional TTS usage")] + [ReturnHints("Discord client not ready")] + [ReturnHints("true|false")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("channelid", "URLARG", "the channel id to apply this action to")] + [ArgHints("tts", "URLARG", "shoud tts be enabled true or false")] + [ArgHints("message", "Text", "what we are sending")] + [Route(HttpVerbs.Post, "/Discord_MembersList/{serverid}/{tts}/{token}")] + public object Discord_MessageChannel(string serverid, string channelid, string tts, [FormField] string message, string token) + { + if (tokens.Allow(token, "discord", "Discord_MessageChannel", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + if (helpers.notempty(message) == false) + { + return Failure("message empty"); + } + return BasicReply(MessageChannel(serverid, channelid, message, tts).Result.ToString()); + } + + [About("Sends a message to the selected channel - Optional TTS usage")] + [ReturnHints("mixed array of userid: nickname|username or userid:username")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("memberid", "URLARG", "who we are giving it to")] + [ArgHints("mode", "URLARG", "should we mute them \"true\" or unmute \"false\"")] + [Route(HttpVerbs.Get, "/Discord_MuteMember/{serverid}/{memberid}/{mode}/{token}")] + public object Discord_MuteMember(string serverid, string memberid, string mode, string token) + { + if (tokens.Allow(token, "discord", "Discord_MuteMember", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return BasicReply(MuteMember(serverid, memberid, mode).Result.ToString()); + } + + [About("returns a collection of settings for the given role \n This command requires Discord full client mode enabled and connected")] + [ReturnHints("KeyPair of status: KeyPair[] item = value")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("memberid", "URLARG", "who we are giving it to")] + [ArgHints("mode", "URLARG", "should we mute them \"true\" or unmute \"false\"")] + [Route(HttpVerbs.Get, "/Discord_Role_GetSettings/{serverid}/{roleid}/{token}")] + public object Discord_Role_GetSettings(string serverid, string roleid, string token) + { + if (tokens.Allow(token, "discord", "Discord_Role_GetSettings", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return RoleSettings(serverid,roleid); + } + + [About("Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of Discord_Role_GetSettings \n" + + " This command requires Discord full client mode enabled and connected")] + [ReturnHints("true|false")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("roleid", "URLARG", "who we are giving it to")] + [ArgHints("flagscsv", "Text", "what we are setting")] + [Route(HttpVerbs.Post, "/Discord_Role_UpdatePerms/{serverid}/{roleid}/{token}")] + public object Discord_Role_UpdatePerms(string serverid, string roleid, [FormField] string flagscsv, string token) + { + if (tokens.Allow(token, "discord", "Discord_Role_UpdatePerms", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return BasicReply(UpdateRolePerms(serverid, roleid, flagscsv).Result.ToString()); + } + + [About("Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of Discord_Role_GetSettings \n" + + " This command requires Discord full client mode enabled and connected")] + [ReturnHints("KeyPair of statusmessage=roleid or 0")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [ArgHints("role", "URLARG", "the name of the role we are creating")] + [Route(HttpVerbs.Get, "/Discord_RoleCreate/{serverid}/{role}/{token}")] + public object Discord_RoleCreate(string serverid, string role, string token) + { + if (tokens.Allow(token, "discord", "Discord_RoleCreate", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return CreateRole(serverid,role).Result; + } + + [About("Returns a list of roles and their ids in collection \n This command requires Discord full client mode enabled and connected")] + [ReturnHints("KeyPair of status: KeyPair of roleid: rolename")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [Route(HttpVerbs.Get, "/Discord_RoleList/{serverid}/{token}")] + public object Discord_RoleList(string serverid, string token) + { + if (tokens.Allow(token, "discord", "Discord_RoleList", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return BasicReply(ListRoles(serverid).ToString()); + } + + [About("Remove a role from a server \n This command requires Discord full client mode enabled and connected")] + [ReturnHints("true|false")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [Route(HttpVerbs.Get, "/Discord_RoleRemove/{serverid}/{roleid}/{token}")] + public object Discord_RoleRemove(string serverid, string roleid, string token) + { + if (tokens.Allow(token, "discord", "Discord_RoleRemove", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return BasicReply(RemoveRole(serverid, roleid).Result.ToString()); + } + + [About("Returns a list of text channels in a server")] + [ReturnHints("array of channelid: name")] + [ReturnHints("Discord client not ready")] + [ArgHints("serverid", "URLARG", "the server id to apply this action to")] + [Route(HttpVerbs.Get, "/Discord_TextChannels_List/{serverid}/{roleid}/{token}")] + public object Discord_TextChannels_List(string serverid, string token) + { + if (tokens.Allow(token, "discord", "Discord_TextChannels_List", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.discordReady() == false) + { + return Failure("Discord client not ready"); + } + return ListTextChannels(serverid); + } + + + #region discord helper functions + + protected KeyValuePair> ListTextChannels(string givenserverid) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == true) + { + return new KeyValuePair>(false, new Dictionary()); + } + SocketGuild server = Discord.GetGuild(serverid); + Dictionary textChannels = new Dictionary(); + foreach (SocketTextChannel channel in server.TextChannels) + { + textChannels.Add(channel.Id.ToString(), channel.Name); + } + return new KeyValuePair>(true, textChannels); + } + + protected async Task RemoveRole(string givenserverid, string givenroleid) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return false; + } + if (ulong.TryParse(givenroleid, out ulong roleid) == false) + { + return false; + } + SocketGuild server = Discord.GetGuild(serverid); + SocketRole role = server.GetRole(roleid); + await role.DeleteAsync().ConfigureAwait(true); + return true; + } + + protected KeyValuePair> ListRoles(string givenserverid) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return new KeyValuePair>(false, new Dictionary()); + } + SocketGuild server = Discord.GetGuild(serverid); + Dictionary rolesList = new Dictionary(); + foreach (SocketRole role in server.Roles) + { + rolesList.Add(role.Id.ToString(), role.Name); + } + return new KeyValuePair>(true, rolesList); + } + + protected async Task> CreateRole(string givenserverid, string givenrole) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == true) + { + return new KeyValuePair("Unable to process server id", 0); + } + SocketGuild server = Discord.GetGuild(serverid); + RestRole role = await server.CreateRoleAsync(givenrole, new GuildPermissions(), Color.DarkRed, false, null).ConfigureAwait(true); + return new KeyValuePair("ok", role.Id); + } + + protected async Task UpdateRolePerms(string givenserverid,string givenroleid,string givenflagscsv) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return false; + } + if (ulong.TryParse(givenroleid, out ulong roleid) == true) + { + return false; + } + SocketGuild server = Discord.GetGuild(serverid); + SocketRole role = server.GetRole(roleid); + string[] bits = givenflagscsv.Split(','); + GuildPermissions NewPerms = role.Permissions; + foreach (String bit in bits) + { + string[] subbits = bit.Split('='); + if (subbits.Length == 2) + { + if (bool.TryParse(subbits[1], out bool flagValue) == true) + { + NewPerms = UpdateFlag(NewPerms, subbits[0], flagValue); + } + } + } + await role.ModifyAsync(Rp => + { + Rp.Permissions = NewPerms; + }).ConfigureAwait(true); + return true; + } + + protected GuildPermissions UpdateFlag(GuildPermissions NewPerms, string flag, bool flagValue) + { + switch (flag) + { + case "CreateInstantInvite": + NewPerms = NewPerms.Modify(flagValue); + break; + case "KickMembers": + NewPerms = NewPerms.Modify(null, flagValue); + break; + case "BanMembers": + NewPerms = NewPerms.Modify(null, null, flagValue); + break; + case "Administrator": + NewPerms = NewPerms.Modify(null, null, null, flagValue); + break; + case "ManageChannels": + NewPerms = NewPerms.Modify(null, null, null, null, flagValue); + break; + case "ManageGuild": + NewPerms = NewPerms.Modify(null, null, null, null, null, flagValue); + break; + case "AddReactions": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, flagValue); + break; + case "ViewAuditLog": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, flagValue); + break; + case "SendTTSMessages": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "AttachFiles": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ReadMessageHistory": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "MentionEveryone": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "UseExternalEmojis": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "Connect": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "Speak": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "MuteMembers": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "UseVAD": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "MoveMembers": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "EmbedLinks": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "PrioritySpeaker": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "Stream": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ChangeNickname": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ManageNicknames": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ManageRoles": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "DeafenMembers": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ManageMessages": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ViewChannel": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, flagValue); + break; + case "SendMessages": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ManageWebhooks": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + case "ManageEmojis": + NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); + break; + default: + break; + } + return NewPerms; + } + + protected KeyValuePair> RoleSettings(string givenserverid, string givenroleid) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return new KeyValuePair>(false, new Dictionary()); + } + if (ulong.TryParse(givenroleid, out ulong roleid) == false) + { + return new KeyValuePair>(false, new Dictionary()); + } + SocketGuild server = Discord.GetGuild(serverid); + SocketRole role = server.GetRole(roleid); + Dictionary settings = new Dictionary + { + { "Config|Color", String.Join(",", new byte[3] { role.Color.R, role.Color.G, role.Color.B }) }, + { "Config|Name", role.Name }, + { "Info|AssignedCount", role.Members.ToString() }, + { "Perm|AttachFiles", role.Permissions.AttachFiles.ToString() }, + { "Perm|ReadMessageHistory", role.Permissions.ReadMessageHistory.ToString() }, + { "Perm|MentionEveryone", role.Permissions.MentionEveryone.ToString() }, + { "Perm|UseExternalEmojis", role.Permissions.UseExternalEmojis.ToString() }, + { "Perm|Connect", role.Permissions.Connect.ToString() }, + { "Perm|Speak", role.Permissions.Speak.ToString() }, + { "Perm|MuteMembers", role.Permissions.MuteMembers.ToString() }, + { "Perm|UseVAD", role.Permissions.UseVAD.ToString() }, + { "Perm|MoveMembers", role.Permissions.MoveMembers.ToString() }, + { "Perm|EmbedLinks", role.Permissions.EmbedLinks.ToString() }, + { "Perm|PrioritySpeaker", role.Permissions.PrioritySpeaker.ToString() }, + { "Perm|Stream", role.Permissions.Stream.ToString() }, + { "Perm|ChangeNickname", role.Permissions.ChangeNickname.ToString() }, + { "Perm|ManageNicknames", role.Permissions.ManageNicknames.ToString() }, + { "Perm|ManageRoles", role.Permissions.ManageRoles.ToString() }, + { "Perm|DeafenMembers", role.Permissions.DeafenMembers.ToString() }, + { "Perm|ManageMessages", role.Permissions.ManageMessages.ToString() }, + { "Perm|ViewChannel", role.Permissions.ViewChannel.ToString() }, + { "Perm|SendMessages", role.Permissions.SendMessages.ToString() }, + { "Perm|CreateInstantInvite", role.Permissions.CreateInstantInvite.ToString() }, + { "Perm|BanMembers", role.Permissions.BanMembers.ToString() }, + { "Perm|SendTTSMessages", role.Permissions.SendTTSMessages.ToString() }, + { "Perm|Administrator", role.Permissions.Administrator.ToString() }, + { "Perm|ManageChannels", role.Permissions.ManageChannels.ToString() }, + { "Perm|KickMembers", role.Permissions.KickMembers.ToString() }, + { "Perm|AddReactions", role.Permissions.AddReactions.ToString() }, + { "Perm|ViewAuditLog", role.Permissions.ViewAuditLog.ToString() }, + { "Perm|ManageWebhooks", role.Permissions.ManageWebhooks.ToString() }, + { "Perm|ManageGuild", role.Permissions.ManageGuild.ToString() }, + { "Perm|ManageEmojis", role.Permissions.ManageEmojis.ToString() } + }; + return new KeyValuePair>(true, settings); + } + + protected async Task MuteMember(string givenserverid, string givenmemberid, string mode) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == true) + { + return false; + } + if (ulong.TryParse(givenmemberid, out ulong memberid) == true) + { + return false; + } + SocketGuild server = Discord.GetGuild(serverid); + SocketGuildUser user = server.GetUser(memberid); + bool.TryParse(mode, out bool status); + await user.ModifyAsync(pr => + { + pr.Mute = status; + }); + return true; + } + + protected async Task MessageChannel(string givenserverid, string givenchannelid, string givenmessage, string tts) + { + if (bool.TryParse(tts, out bool useTTS) == false) + { + return false; + } + return await bot.SendMessageToDiscord(givenserverid, givenchannelid, givenmessage, useTTS); + } + + + protected async Task>> ListMembers(string givenserverid) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return new KeyValuePair>(false, new Dictionary()); + } + SocketGuild server = Discord.GetGuild(serverid); + IEnumerable users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true); + Dictionary membersList = new Dictionary(); + + foreach (IGuildUser user in users) + { + if (user.Nickname != null) + { + membersList.Add(user.Id.ToString(), user.Nickname + "|" + user.Username); + } + else + { + membersList.Add(user.Id.ToString(), user.Username); + } + } + return new KeyValuePair>(true, membersList); + } + + + protected async Task MessageMember(string givenserverid, string givenmemberid, string givenmessage) + { + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return false; + } + if (ulong.TryParse(givenmemberid, out ulong memberid) == false) + { + return false; + } + try + { + SocketGuild server = Discord.GetGuild(serverid); + IEnumerable users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true); + bool sent = false; + foreach (IGuildUser user in users) + { + if (user.Id == memberid) + { + sent = true; + await user.SendMessageAsync(givenmessage); + break; + } + } + return sent; + } + catch + { + return false; + } + } + + protected async Task> ClearMessages(string givenserverid, string givenmemberid) + { + int messagesDeleted = 0; + DiscordSocketClient Discord = bot.getDiscordClient(); + if (ulong.TryParse(givenserverid, out ulong serverid) == false) + { + return new KeyValuePair(false, 0); + } + if (ulong.TryParse(givenmemberid, out ulong memberid) == false) + { + return new KeyValuePair(false, 0); + } + SocketGuild server = Discord.GetGuild(serverid); + SocketGuildUser user = server.GetUser(memberid); + TimeSpan somedays = new TimeSpan(13, 22, 59, 59, 0); + DateTimeOffset justundertwosweeks = DateTimeOffset.Now; + justundertwosweeks = justundertwosweeks.Subtract(somedays); + long unixtimelimit = justundertwosweeks.ToUnixTimeSeconds(); + foreach (SocketTextChannel channel in server.TextChannels) + { + List DeleteMessages = new List(); + IEnumerable messages = await channel.GetMessagesAsync(100).FlattenAsync(); + foreach (IMessage message in messages) + { + if (message.CreatedAt.ToUnixTimeSeconds() > unixtimelimit) + { + if (message.Author.Id == user.Id) + { + DeleteMessages.Add(message); + } + } + } + if (DeleteMessages.Count > 0) + { + messagesDeleted += DeleteMessages.Count; + await channel.DeleteMessagesAsync(DeleteMessages); + } + } + return new KeyValuePair(true, messagesDeleted); + } + + protected async Task BanMember(string givenserverid, string givenmemberid, string why) { @@ -101,5 +706,8 @@ namespace BetterSecondBot.HttpService await user.AddRoleAsync(role); // ? Irole seems to accept SocketRole ? return true; } + + + #endregion } } diff --git a/BetterSecondbot/HttpService/Estate.cs b/BetterSecondbot/HttpService/Estate.cs index 863fd4b..9445e7f 100644 --- a/BetterSecondbot/HttpService/Estate.cs +++ b/BetterSecondbot/HttpService/Estate.cs @@ -5,6 +5,9 @@ using EmbedIO.Routing; using System; using Newtonsoft.Json; using OpenMetaverse; +using System.Collections.Generic; +using EmbedIO.WebApi; +using BetterSecondBotShared.Static; namespace BetterSecondBot.HttpService { @@ -18,20 +21,137 @@ namespace BetterSecondBot.HttpService } + [About("Sends the message to the current sim")] + [ReturnHints("Not an estate manager here")] + [ReturnHints("restarting")] + [ReturnHints("canceled")] + [ArgHints("delay", "URLARG", "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", "URLARG", "true to start a restart, false to cancel")] + [Route(HttpVerbs.Get, "/SimRestart/{delay}/{mode}/{token}")] + public object SimRestart(string delay, string mode, string token) + { + if (tokens.Allow(token, "estate", "SimMessage", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim.IsEstateManager == false) + { + return Failure("Not an estate manager here"); + } + bool.TryParse(mode, out bool modeflag); + if (modeflag == false) + { + bot.GetClient.Estate.CancelRestart(); + return BasicReply("canceled"); + } + int delay_restart = 60; + int.TryParse(delay, out delay_restart); + if((delay_restart < 30) || (delay_restart > 240)) + { + delay_restart = 240; + } + bot.GetClient.Estate.RestartRegion(delay_restart); + return BasicReply("restarting"); + } + + [About("Sends the message to the current sim")] + [ReturnHints("Not an estate manager here")] + [ReturnHints("Message empty")] + [ReturnHints("ok")] + [ArgHints("message", "Text", "What the message is")] + [Route(HttpVerbs.Post, "/SimMessage/{token}")] + public object SimMessage([FormField] string message, string token) + { + if (tokens.Allow(token, "estate", "SimMessage", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (helpers.notempty(message) == false) + { + return Failure("Message empty"); + } + if (bot.GetClient.Network.CurrentSim.IsEstateManager == false) + { + return Failure("Not an estate manager here"); + } + bot.GetClient.Estate.SimulatorMessage(message); + return BasicReply("ok"); + } + + [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, "/GetSimTexture/{regionname}/{token}")] + public object GetSimTexture(string regionname, string token) + { + if (tokens.Allow(token, "estate", "GetSimTexture", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false) + { + return Failure("Unable to find region"); + } + return BasicReply(region.MapImageID.ToString()); + } + + [About("Reclaims ownership of the current parcel")] + [ReturnHints("Not an estate manager here")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/EstateParcelReclaim/{token}")] + public Object EstateParcelReclaim(string token) + { + if (tokens.Allow(token, "estate", "EstateParcelReclaim", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim.IsEstateManager == false) + { + return Failure("Not an estate manager here"); + } + int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); + bot.GetClient.Parcels.Reclaim(bot.GetClient.Network.CurrentSim, localid); + return BasicReply("ok"); + } + + [About("Reclaims ownership of the current parcel")] + [ReturnHints("Not an estate manager here")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/GetSimGlobalPos/{regionname}/{token}")] + public Object GetSimGlobalPos(string regionname, string token) + { + if (tokens.Allow(token, "estate", "GetSimGlobalPos", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Grid.GetGridRegion(regionname, GridLayerType.Objects, out GridRegion region) == false) + { + return Failure("Unable to find region"); + } + Dictionary reply = new Dictionary(); + reply.Add("region", regionname); + reply.Add("X", region.X.ToString()); + reply.Add("Y", region.Y.ToString()); + return reply; + } + [About("Requests the estate banlist")] [ReturnHints("")] [Route(HttpVerbs.Get, "/GetEstateBanList/{token}")] public Object GetEstateBanList(string token) { - if (tokens.Allow(token, "estate", "banlist", getClientIP()) == true) + if (tokens.Allow(token, "estate", "banlist", getClientIP()) == false) { - return BasicReply(JsonConvert.SerializeObject(bot._lastUpdatedSimBlacklist)); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + return BasicReply(JsonConvert.SerializeObject(bot._lastUpdatedSimBlacklist)); } [About("Attempts to add/remove the avatar to/from the Estate banlist")] - [ReturnHints("Request accepted")] + [ReturnHints("Unban request accepted")] + [ReturnHints("Ban request accepted")] [ReturnHints("Unable to find avatar UUID")] [ReturnHints("Unable to process global value please use true or false")] [ReturnHints("Not an estate manager on region {REGIONNAME}")] @@ -42,33 +162,31 @@ namespace BetterSecondBot.HttpService public Object UpdateEstateBanlist(string avatar, string mode, string global, string token) { - if (tokens.Allow(token, "estate", "banlist-add", getClientIP()) == true) + if (tokens.Allow(token, "estate", "banlist-add", getClientIP()) == false) { - if(bot.GetClient.Network.CurrentSim.IsEstateManager == false) - { - return BasicReply("Not an estate manager on region "+ bot.GetClient.Network.CurrentSim.Name); - } - UUID avataruuid = UUID.Zero; - if(UUID.TryParse(avatar,out avataruuid) == false) - { - return BasicReply("Unable to find avatar UUID"); - } - bool globalban = false; - if(bool.TryParse(global,out globalban) == false) - { - return BasicReply("Unable to process global value please use true or false"); - } - if(mode != "add") - { - bot.GetClient.Estate.UnbanUser(avataruuid, globalban); - } - else - { - bot.GetClient.Estate.BanUser(avataruuid, globalban); - } - return BasicReply("Request accepted"); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + if (bot.GetClient.Network.CurrentSim.IsEstateManager == false) + { + return Failure("Not an estate manager on region " + bot.GetClient.Network.CurrentSim.Name); + } + UUID avataruuid = UUID.Zero; + if (UUID.TryParse(avatar, out avataruuid) == false) + { + return Failure("Unable to find avatar UUID"); + } + bool globalban = false; + if (bool.TryParse(global, out globalban) == false) + { + return Failure("Unable to process global value please use true or false"); + } + if (mode != "add") + { + bot.GetClient.Estate.UnbanUser(avataruuid, globalban); + return BasicReply("Unban request accepted"); + } + bot.GetClient.Estate.BanUser(avataruuid, globalban); + return BasicReply("Ban request accepted"); } } } diff --git a/BetterSecondbot/HttpService/Friends.cs b/BetterSecondbot/HttpService/Friends.cs new file mode 100644 index 0000000..fdf2d7f --- /dev/null +++ b/BetterSecondbot/HttpService/Friends.cs @@ -0,0 +1,114 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Friends : WebApiControllerWithTokens + { + public HTTP_Friends(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Gets the friendslist
Formated as follows
friendreplyobject
  • name: String
  • id: String
  • online: bool
")] + [ReturnHints("array UUID = friendreplyobject")] + [Route(HttpVerbs.Get, "/Friendslist/{token}")] + public object Friendslist(string token) + { + if (tokens.Allow(token, "friends", "Friendslist", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + return BasicReply(bot.getJsonFriendlist()); + } + + [About("Updates the friend perms for avatar avatar to State \n if true grants (Online/Map/Modify) perms")] + [ArgHints("avatar", "URLARG", "A avatar uuid or Firstname Lastname")] + [ArgHints("state", "URLARG", "true: Grant perms, false: Remove perms")] + [ReturnHints("granted")] + [ReturnHints("removed")] + [ReturnHints("Not A friend")] + [ReturnHints("state invaild")] + [ReturnHints("avatar lookup")] + [Route(HttpVerbs.Get, "/FriendFullPerms/{avatar}/{state}/{token}")] + public object FriendFullPerms(string avatar, string state, string token) + { + if (tokens.Allow(token, "friends", "FriendFullPerms", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool status = false; + if (bool.TryParse(state, out status) == false) + { + return Failure("state invaild"); + } + if (bot.GetClient.Friends.FriendList.ContainsKey(avataruuid) == false) + { + return Failure("Not A friend"); + } + if (status == true) + { + bot.GetClient.Friends.GrantRights(avataruuid, FriendRights.CanSeeOnline | FriendRights.CanSeeOnMap | FriendRights.CanModifyObjects); + return BasicReply("granted"); + } + bot.GetClient.Friends.GrantRights(avataruuid, FriendRights.None); + return BasicReply("removed"); + } + + [About("Updates the friend perms for avatar avatar to State \n if true grants (Online/Map/Modify) perms")] + [ReturnHints("Request sent")] + [ReturnHints("Removed")] + [ReturnHints("Already a friend")] + [ReturnHints("Not in friendslist")] + [ReturnHints("state invaild")] + [ReturnHints("avatar lookup")] + [ArgHints("avatar", "URLARG", "A avatar uuid or Firstname Lastname")] + [ArgHints("state", "URLARG", "true: Send invite, false: Remove from friendslist")] + [Route(HttpVerbs.Get, "/FriendRequest/{avatar}/{state}/{token}")] + public object FriendRequest(string avatar, string state, string token) + { + if (tokens.Allow(token, "friends", "FriendRequest", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool status = false; + if (bool.TryParse(state, out status) == false) + { + return Failure("state invaild"); + } + if (bot.GetClient.Friends.FriendList.ContainsKey(avataruuid) == true) + { + if (status == false) + { + bot.GetClient.Friends.TerminateFriendship(avataruuid); + return BasicReply("Removed"); + } + } + if (status == false) + { + return Failure("Not in friendslist"); + } + bot.GetClient.Friends.OfferFriendship(avataruuid); + return BasicReply("Request sent"); + + } + } + + +} diff --git a/BetterSecondbot/HttpService/Funds.cs b/BetterSecondbot/HttpService/Funds.cs new file mode 100644 index 0000000..59f1f6b --- /dev/null +++ b/BetterSecondbot/HttpService/Funds.cs @@ -0,0 +1,112 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class Http_Funds : WebApiControllerWithTokens + { + public Http_Funds(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Requests the current balance and requests the balance to update.")] + [ReturnHints("Current fund level")] + [ReturnHints("Funds commands are disabled")] + [Route(HttpVerbs.Get, "/Balance/{token}")] + public object Balance(string token) + { + if (tokens.Allow(token, "funds", "Balance", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (bot.GetAllowFunds == false) + { + return Failure("Funds commands are disabled"); + } + bot.GetClient.Self.RequestBalance(); + return BasicReply(bot.GetClient.Self.Balance.ToString()); + } + + [About("Makes the bot pay a avatar")] + [ReturnHints("Accepted")] + [ReturnHints("avatar lookup")] + [ReturnHints("Invaild amount")] + [ReturnHints("Transfer funds to avatars disabled")] + [Route(HttpVerbs.Get, "/PayAvatar/{avatar}/{amount}/{token}")] + public object PayAvatar(string avatar, string amount, string token) + { + if (tokens.Allow(token, "funds", "PayAvatar", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + if (bot.GetAllowFunds == false) + { + return BasicReply("Transfer funds to avatars disabled"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return BasicReply("avatar lookup"); + } + if (int.TryParse(amount, out int amountvalue) == false) + { + return BasicReply("Invaild amount"); + } + if (amountvalue < 1) + { + return BasicReply("Invaild amount"); + } + bot.GetClient.Self.GiveAvatarMoney(avataruuid, amountvalue); + return BasicReply("Accepted"); + } + + [About("Makes the bot pay a object")] + [ReturnHints("ok")] + [ReturnHints("Primname is empty")] + [ReturnHints("Current fund level")] + [ReturnHints("Invaild object UUID")] + [ReturnHints("Invaild amount")] + [ReturnHints("Amount out of range")] + [ReturnHints("Funds commands are disabled")] + [ArgHints("object", "URLARG", "UUID of the object to pay")] + [ArgHints("primname", "URLARG", "The name of the prim on the object to pay")] + [ArgHints("amount", "URLARG", "the amount to pay (from 1 to current balance)")] + [Route(HttpVerbs.Get, "/PayObject/{object}/{primname}/{amount}/{token}")] + public object PayObject(string objectuuid,string primname,string amount,string token) + { + if (tokens.Allow(token, "funds", "PayObject", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (bot.GetAllowFunds == false) + { + return Failure("Funds commands are disabled"); + } + if (UUID.TryParse(objectuuid, out UUID objectUUID) == false) + { + return Failure("Invaild object UUID"); + } + if (int.TryParse(amount, out int amountvalue) == false) + { + return Failure("Invaild amount"); + } + if((amountvalue < 0) || (amountvalue > bot.GetClient.Self.Balance)) + { + return Failure("Amount out of range"); + } + if(helpers.notempty(primname) == false) + { + return Failure("Primname is empty"); + } + bot.GetClient.Self.GiveObjectMoney(objectUUID, amountvalue, primname); + return BasicReply("ok"); + } + } +} diff --git a/BetterSecondbot/HttpService/Group.cs b/BetterSecondbot/HttpService/Group.cs index e746737..8a6ddf6 100644 --- a/BetterSecondbot/HttpService/Group.cs +++ b/BetterSecondbot/HttpService/Group.cs @@ -22,58 +22,370 @@ namespace BetterSecondBot.HttpService [ReturnHints("Updating")] [ReturnHints("Unknown group")] [ReturnHints("Invaild group UUID")] - [ReturnHints("Unable to find avatar UUID")] + [ReturnHints("avatar lookup")] [ArgHints("group", "URLARG", "the UUID of the group")] [ArgHints("avatar", "URLARG", "the UUID of the avatar you wish to check with")] - [Route(HttpVerbs.Get, "/ismember/{group}/{avatar}/{token}")] - public object ismember(string group,string avatar,string token) + [Route(HttpVerbs.Get, "/IsGroupMember/{group}/{avatar}/{token}")] + public object IsGroupMember(string group, string avatar, string token) { - if (tokens.Allow(token, "groups", "ismember", getClientIP()) == true) + if (tokens.Allow(token, "groups", "IsGroupMember", getClientIP()) == true) { - if (UUID.TryParse(group, out UUID groupuuid) == true) - { - if (bot.MyGroups.ContainsKey(groupuuid) == true) - { - if (bot.NeedReloadGroupData(groupuuid) == false) - { - UUID avataruuid = UUID.Zero; - if(UUID.TryParse(avatar,out avataruuid) == false) - { - string lookup = bot.FindAvatarName2Key(avatar); - if (UUID.TryParse(lookup, out avataruuid) == false) - { - return BasicReply("Unable to find avatar UUID"); - } - } - bool status = bot.FastCheckInGroup(groupuuid, avataruuid); - return BasicReply(status.ToString()); - } - bot.GetClient.Groups.RequestGroupMembers(groupuuid); - return BasicReply("Updating"); - } - return BasicReply("Unknown group"); - } - return BasicReply("Invaild group UUID"); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (bot.NeedReloadGroupData(groupuuid) == true) + { + bot.GetClient.Groups.RequestGroupMembers(groupuuid); + return Failure("Updating"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool status = bot.FastCheckInGroup(groupuuid, avataruuid); + return BasicReply(status.ToString()); + } + + [About("Gets membership of a group")] + [ReturnHints("list of UUIDS of group members")] + [ReturnHints("Updating")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("avatar lookup")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [Route(HttpVerbs.Get, "/GetGroupMembers/{group}/{token}")] + public object GetGroupMembers(string group, string token) + { + if (tokens.Allow(token, "groups", "GetGroupMembers", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (bot.NeedReloadGroupData(groupuuid) == true) + { + bot.GetClient.Groups.RequestGroupMembers(groupuuid); + return Failure("Updating"); + } + return bot.GetGroupMembers(groupuuid); + } + + [About("Eject selected avatar from group")] + [ReturnHints("Requested")] + [ReturnHints("Updating")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("Not in group")] + [ReturnHints("avatar lookup")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [ArgHints("avatar", "URLARG", "the UUID of the avatar you wish to check with")] + [Route(HttpVerbs.Get, "/GroupEject/{group}/{avatar}/{token}")] + public object GroupEject(string group, string avatar, string token) + { + if (tokens.Allow(token, "groups", "GroupEject", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (bot.NeedReloadGroupData(groupuuid) == true) + { + bot.GetClient.Groups.RequestGroupMembers(groupuuid); + return Failure("Updating"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool status = bot.FastCheckInGroup(groupuuid, avataruuid); + if(status == false) + { + return BasicReply("Not in group"); + } + bot.GetClient.Groups.EjectUser(groupuuid, avataruuid); + return BasicReply("Requested"); + } + + [About("Adds the avatar to the Group with the role \n if they are not in the group then it invites them aswell")] + [ReturnHints("Roles updated")] + [ReturnHints("Invite sent")] + [ReturnHints("Updating")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("Invaild role UUID")] + [ReturnHints("Not in group")] + [ReturnHints("avatar lookup")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [ArgHints("avatar", "URLARG", "the UUID of the avatar you wish to check with")] + [Route(HttpVerbs.Get, "/GroupAddRole/{group}/{avatar}/{role}/{token}")] + public object GroupAddRole(string group, string avatar, string role, string token) + { + if (tokens.Allow(token, "groups", "GroupAddRole", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (UUID.TryParse(role, out UUID roleuuid) == false) + { + return Failure("Invaild role UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (bot.NeedReloadGroupData(groupuuid) == true) + { + bot.GetClient.Groups.RequestGroupMembers(groupuuid); + return Failure("Updating"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool status = bot.FastCheckInGroup(groupuuid, avataruuid); + if (status == false) + { + bot.GetClient.Groups.Invite(groupuuid, new List() { roleuuid }, avataruuid); + return BasicReply("Invite sent"); + } + bot.GetClient.Groups.AddToRole(groupuuid, roleuuid, avataruuid); + return BasicReply("Roles updated"); + } + + [About("Eject selected avatar from group")] + [ReturnHints("Invite sent")] + [ReturnHints("Updating")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("Already in group")] + [ReturnHints("avatar lookup")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [ArgHints("avatar", "URLARG", "the UUID of the avatar you wish to check with")] + [ArgHints("role", "URLARG", "the UUID of the role to invite them at the word \"everyone\"")] + [Route(HttpVerbs.Get, "/GroupInvite/{group}/{avatar}/{role}/{token}")] + public object GroupInvite(string group, string avatar, string role, string token) + { + if (tokens.Allow(token, "groups", "GroupInvite", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (bot.NeedReloadGroupData(groupuuid) == true) + { + bot.GetClient.Groups.RequestGroupMembers(groupuuid); + return Failure("Updating"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool status = bot.FastCheckInGroup(groupuuid, avataruuid); + if (status == true) + { + return Failure("Already in group"); + } + if(role == "everyone") + { + role = UUID.Zero.ToString(); + } + if(UUID.TryParse(role,out UUID roleuuid) == false) + { + return Failure("Unable to process role UUID"); + } + bot.GetClient.Groups.Invite(groupuuid, new List() { roleuuid }, avataruuid); + return BasicReply("Invite sent"); + } + + [About("Sends a group notice (No attachments please use GroupnoticeWithAttachment to attach items!)")] + [ReturnHints("Sending notice")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("Title empty")] + [ReturnHints("Message empty")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [ArgHints("title", "Text", "The title of the group notice")] + [ArgHints("message", "Text", "The body of the group notice")] + [Route(HttpVerbs.Post, "/Groupnotice/{group}/{token}")] + public object Groupnotice(string group, [FormField] string title, [FormField] string message, string token) + { + if (tokens.Allow(token, "groups", "Groupnotice", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (helpers.notempty(title) == false) + { + return Failure("Title empty"); + } + if (helpers.notempty(message) == false) + { + return Failure("Message empty"); + } + GroupNotice NewNotice = new GroupNotice(); + NewNotice.Subject = title; + NewNotice.Message = message; + NewNotice.OwnerID = bot.GetClient.Self.AgentID; + bot.GetClient.Groups.SendGroupNotice(groupuuid, NewNotice); + return BasicReply("Sending notice"); + } + + [About("Activates the selected title")] + [ReturnHints("Switching title")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("Invaild role UUID")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [ArgHints("role", "URLARG", "tje UUID of the role")] + [Route(HttpVerbs.Get, "/GroupActiveTitle/{group}/{token}")] + public object GroupActiveTitle(string group, string role, string token) + { + if (tokens.Allow(token, "groups", "GroupActiveTitle", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (UUID.TryParse(role, out UUID roleuuid) == false) + { + return Failure("Invaild role UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + bot.GetClient.Groups.ActivateTitle(groupuuid, roleuuid); + return BasicReply("Switching title"); + } + + [About("Sets the selected group to the active group")] + [ReturnHints("Switching active group")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [Route(HttpVerbs.Get, "/GroupActiveGroup/{group}/{token}")] + public object GroupActiveGroup(string group, string role, string token) + { + if (tokens.Allow(token, "groups", "GroupActiveTitle", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + bot.GetClient.Groups.ActivateGroup(groupuuid); + return BasicReply("Switching active group"); + } + + [About("Sends a group notice with an attachment")] + [ReturnHints("Sending notice with attachment")] + [ReturnHints("Unknown group")] + [ReturnHints("Invaild group UUID")] + [ReturnHints("Invaild inventory UUID")] + [ReturnHints("Title empty")] + [ReturnHints("Message empty")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [ArgHints("attachment", "URLARG", "the UUID of inventory you wish to attach")] + [ArgHints("title", "Text", "The title of the group notice")] + [ArgHints("message", "Text", "The body of the group notice")] + [Route(HttpVerbs.Post, "/Groupnotice/{group}/{attachment}/{token}")] + public object GroupnoticeWithAttachment(string group, [FormField] string title, [FormField] string message, string attachment, string token) + { + if (tokens.Allow(token, "groups", "GroupnoticeWithAttachment", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (UUID.TryParse(attachment, out UUID inventoryuuid) == false) + { + return Failure("Invaild inventory UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + if (helpers.notempty(title) == false) + { + return Failure("Title empty"); + } + if (helpers.notempty(message) == false) + { + return Failure("Message empty"); + } + GroupNotice NewNotice = new GroupNotice(); + NewNotice.Subject = title; + NewNotice.Message = message; + NewNotice.OwnerID = bot.GetClient.Self.AgentID; + NewNotice.AttachmentID = inventoryuuid; + bot.GetClient.Groups.SendGroupNotice(groupuuid, NewNotice); + return BasicReply("Sending notice with attachment"); } [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) + [Route(HttpVerbs.Get, "/GetGroupList/{token}")] + public object GetGroupList(string token) { - if (tokens.Allow(token, "groups", "listgroups", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GetGroupList", getClientIP()) == true) { - Dictionary grouppackage = new Dictionary(); - foreach(KeyValuePair entry in bot.MyGroups) - { - grouppackage.Add(entry.Value.ID.ToString(), entry.Value.Name); - } - return BasicReply(JsonConvert.SerializeObject(grouppackage)); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + Dictionary grouppackage = new Dictionary(); + foreach (KeyValuePair entry in bot.MyGroups) + { + grouppackage.Add(entry.Value.ID.ToString(), entry.Value.Name); + } + return BasicReply(JsonConvert.SerializeObject(grouppackage)); } [About("Requests the roles for the selected group
Replys with GroupRoleDetails object formated as follows
  • UpdateUnderway (Bool)
  • RoleDataAge (Int) [default -1]
  • Roles (KeyPair array of UUID=Name)

")] @@ -82,93 +394,132 @@ namespace BetterSecondBot.HttpService [ReturnHints("Invaild group UUID")] [ReturnHints("Updating")] [ArgHints("group", "URLARG", "the UUID of the group")] - [Route(HttpVerbs.Get, "/listgrouproles/{group}/{token}")] - public object listgrouproles(string group, string token) + [Route(HttpVerbs.Get, "/GetGroupRoles/{group}/{token}")] + public object GetGroupRoles(string group, string token) { - if (tokens.Allow(token, "groups", "listgrouproles", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GetGroupRoles", getClientIP()) == true) { - if (UUID.TryParse(group, out UUID groupuuid) == true) - { - if (bot.MyGroups.ContainsKey(groupuuid) == true) - { - GroupRoleDetails reply = new GroupRoleDetails(); - reply.UpdateUnderway = false; - reply.RoleDataAge = -1; - reply.Roles = new Dictionary(); - if (bot.MyGroupRolesStorage.ContainsKey(groupuuid) == false) - { - reply.UpdateUnderway = true; - } - else - { - long dif = helpers.UnixTimeNow() - bot.MyGroupRolesStorage[groupuuid].Key; - reply.RoleDataAge = dif; - if (dif >= 120) - { - reply.UpdateUnderway = true; - } - foreach(GroupRole gr in bot.MyGroupRolesStorage[groupuuid].Value) - { - reply.Roles.Add(gr.ID.ToString(), gr.Name); - } - } - if(reply.UpdateUnderway == true) - { - bot.GetClient.Groups.RequestGroupRoles(groupuuid); - if (reply.Roles.Count == 0) - { - return BasicReply("Updating"); - } - } - return BasicReply(JsonConvert.SerializeObject(reply)); - } - return BasicReply("Group is not currently known"); - } - return BasicReply("Invaild group UUID"); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group UUID"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Unknown group"); + } + GroupRoleDetails reply = new GroupRoleDetails(); + reply.UpdateUnderway = false; + reply.RoleDataAge = -1; + reply.Roles = new Dictionary(); + if (bot.MyGroupRolesStorage.ContainsKey(groupuuid) == false) + { + reply.UpdateUnderway = true; + } + else + { + long dif = helpers.UnixTimeNow() - bot.MyGroupRolesStorage[groupuuid].Key; + reply.RoleDataAge = dif; + if (dif >= 120) + { + reply.UpdateUnderway = true; + } + foreach (GroupRole gr in bot.MyGroupRolesStorage[groupuuid].Value) + { + reply.Roles.Add(gr.ID.ToString(), gr.Name); + } + } + if (reply.UpdateUnderway == true) + { + bot.GetClient.Groups.RequestGroupRoles(groupuuid); + if (reply.Roles.Count == 0) + { + return Failure("Updating"); + } + } + return BasicReply(JsonConvert.SerializeObject(reply)); } [About("fetchs a list of all groups with unread messages")] [ReturnHints("array UUID")] - [Route(HttpVerbs.Get, "/listgroupswithunread/{token}")] - public object listgroupswithunread(string token) + [Route(HttpVerbs.Get, "/GroupchatListAllUnreadGroups/{token}")] + public object GroupchatListAllUnreadGroups(string token) { - if (tokens.Allow(token, "groups", "listgroupswithunread", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatListAllUnreadGroups", getClientIP()) == true) { - return BasicReply(JsonConvert.SerializeObject(bot.UnreadGroupchatGroups())); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + return BasicReply(JsonConvert.SerializeObject(bot.UnreadGroupchatGroups())); } + [About("fetchs a list of all groups with unread messages")] + [ReturnHints("true")] + [ReturnHints("false")] + [ReturnHints("Unknown group")] + [ReturnHints("group value is invaild")] + [ArgHints("group", "URLARG", "the UUID of the group")] + [Route(HttpVerbs.Get, "/GroupchatGroupHasUnread/{group}/{token}")] + public object GroupchatGroupHasUnread(string group,string token) + { + if (tokens.Allow(token, "groups", "GroupchatListAllUnreadGroups", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + UUID groupUUID = UUID.Zero; + if(UUID.TryParse(group,out groupUUID) == false) + { + return Failure("group value is invaild"); + } + if(bot.MyGroups.ContainsKey(groupUUID) == false) + { + return Failure("Unknown group"); + } + return BasicReply(bot.GroupHasUnread(groupUUID).ToString()); + } + + [About("checks if there are any groups with unread messages")] [ReturnHints("True|False")] - [Route(HttpVerbs.Get, "/haveunreadgroupchat/{token}")] + [Route(HttpVerbs.Get, "/GroupchatAnyUnread/{token}")] public object haveunreadgroupchat(string token) { - if (tokens.Allow(token, "groups", "haveunreadgroupchat", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatAnyUnread", getClientIP()) == true) { return BasicReply(bot.HasUnreadGroupchats().ToString()); } - return BasicReply("Token not accepted"); + return Failure("Token not accepted"); + } + + [About("Clears all group chat buffers at once")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/GroupchatClearAll/{token}")] + public object GroupchatClearAll(string token) + { + if (tokens.Allow(token, "groups", "GroupchatClearAll", getClientIP()) == true) + { + bot.ClearAllGroupchat(); + return BasicReply("ok"); + } + return Failure("Token not accepted"); } [About("fetchs the groupchat history")] [ReturnHints("Group UUID invaild")] [ReturnHints("Group Chat")] [ArgHints("group", "URLARG", "the UUID of the group")] - [Route(HttpVerbs.Get, "/getgroupchat/{group}/{token}")] - public object getgroupchat(string group, string token) + [Route(HttpVerbs.Get, "/GroupchatHistory/{group}/{token}")] + public object GroupchatHistory(string group, string token) { - if (tokens.Allow(token, "groups", "getgroupchat", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatHistory", getClientIP()) == true) { if (UUID.TryParse(group, out UUID groupUUID) == true) { return BasicReply(JsonConvert.SerializeObject(bot.GetGroupchat(groupUUID))); } - return BasicReply("Group UUID invaild"); + return Failure("Group UUID invaild"); } - return BasicReply("Token not accepted"); + return Failure("Token not accepted"); } [About("sends a message to the groupchat")] @@ -176,19 +527,31 @@ namespace BetterSecondBot.HttpService [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) + [ReturnHints("Opening groupchat")] + [ReturnHints("Sending")] + [Route(HttpVerbs.Post, "/Groupchat/{group}/{token}")] + public object Groupchat(string group, [FormField] string message, string token) { - if (tokens.Allow(token, "groups", "sendgroupchat", getClientIP()) == true) + if (tokens.Allow(token, "groups", "Groupchat", getClientIP()) == true) { - if (UUID.TryParse(group, out UUID groupUUID) == true) - { - bool status = bot.GetCommandsInterface.Call("Groupchat", group + "~#~" + message, UUID.Zero, "~#~"); - return BasicReply("Processing"); - } - return BasicReply("Group UUID invaild"); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + UUID groupUUID = UUID.Zero; + if (UUID.TryParse(group, out groupUUID) == false) + { + return Failure("group value is invaild"); + } + if (bot.MyGroups.ContainsKey(groupUUID) == false) + { + return Failure("Unknown group"); + } + if (bot.GetActiveGroupchatSessions.Contains(groupUUID) == false) + { + bot.GetClient.Self.RequestJoinGroupChat(groupUUID); + return Failure("Opening groupchat"); + } + bot.GetClient.Self.InstantMessageGroup(groupUUID, message); + return BasicReply("Sending"); } } diff --git a/BetterSecondbot/HttpService/Home.cs b/BetterSecondbot/HttpService/Home.cs new file mode 100644 index 0000000..c0ee1ec --- /dev/null +++ b/BetterSecondbot/HttpService/Home.cs @@ -0,0 +1,33 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class Http_Home : WebApiControllerWithTokens + { + public Http_Home(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Makes the bot teleport to its home region")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/GoHome/{token}")] + public object GoHome(string group, string token) + { + if (tokens.Allow(token, "groups", "GetGroupMembers", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + bot.GotoNextHomeRegion(); + return BasicReply("ok"); + } + + } +} diff --git a/BetterSecondbot/HttpService/HttpAsService.cs b/BetterSecondbot/HttpService/HttpAsService.cs index de0762d..07c0948 100644 --- a/BetterSecondbot/HttpService/HttpAsService.cs +++ b/BetterSecondbot/HttpService/HttpAsService.cs @@ -436,8 +436,15 @@ namespace BetterSecondBot.HttpService protected Object BasicReply(string input) { - return new { reply = input }; + return new { reply = input, status=true }; } + + protected Object Failure(string input) + { + return new { reply = input, status = false }; + } + + public WebApiControllerWithTokens(SecondBot mainbot, TokenStorage setuptokens) { bot = mainbot; diff --git a/BetterSecondbot/HttpService/Info.cs b/BetterSecondbot/HttpService/Info.cs new file mode 100644 index 0000000..9f00532 --- /dev/null +++ b/BetterSecondbot/HttpService/Info.cs @@ -0,0 +1,116 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class Http_Info : WebApiControllerWithTokens + { + public Http_Info(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Fetchs the current bot")] + [ReturnHints("The build ID of the bot")] + [Route(HttpVerbs.Get, "/Version/{token}")] + public object Version(string token) + { + if (tokens.Allow(token, "info", "Version", getClientIP()) == true) + { + return BasicReply(bot.MyVersion); + } + return Failure("Token not accepted"); + } + + [About("Fetchs the name of the bot")] + [ReturnHints("Firstname Lastname")] + [Route(HttpVerbs.Get, "/Name/{token}")] + public object Name(string token) + { + if (tokens.Allow(token, "info", "Name", getClientIP()) == true) + { + return BasicReply(bot.GetClient.Self.FirstName + " " + bot.GetClient.Self.LastName); + } + return Failure("Token not accepted"); + } + + [About("Fetchs the current parcels name")] + [ReturnHints("Parcelname")] + [ReturnHints("Error parcel not found")] + [ReturnHints("Error not in a sim")] + [Route(HttpVerbs.Get, "/ParcelName/{token}")] + public object ParcelName(string token) + { + if (tokens.Allow(token, "info", "ParcelName", getClientIP()) == true) + { + if (bot.GetClient.Network.CurrentSim != null) + { + int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); + if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) + { + return BasicReply(bot.GetClient.Network.CurrentSim.Parcels[localid].Name); + } + return Failure("Error parcel not found"); + } + return Failure("Error not in a sim"); + } + return Failure("Token not accepted"); + } + + [About("Requests the current unixtime at the bot")] + [ReturnHints("Unixtime")] + [Route(HttpVerbs.Get, "/UnixTimeNow/{token}")] + public object UnixTimeNow(string token) + { + if (tokens.Allow(token, "info", "UnixTimeNow", getClientIP()) == true) + { + return BasicReply(helpers.UnixTimeNow().ToString()); + } + return Failure("Token not accepted"); + } + + [About("Fetchs the current region name")] + [ReturnHints("Regionname")] + [ReturnHints("Error not in a sim")] + [Route(HttpVerbs.Get, "/SimName/{token}")] + public object SimName(string token) + { + if (tokens.Allow(token, "info", "SimName", getClientIP()) == true) + { + if (bot.GetClient.Network.CurrentSim != null) + { + return BasicReply(bot.GetClient.Network.CurrentSim.Name); + } + return Failure("Error not in a sim"); + } + return Failure("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, "/GetPosition/{token}")] + public object GetPosition(string token) + { + if (tokens.Allow(token, "info", "GetPosition", getClientIP()) == true) + { + 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 Failure("Error not in a sim"); + } + return Failure("Token not accepted"); + } + } +} diff --git a/BetterSecondbot/HttpService/Self.cs b/BetterSecondbot/HttpService/Self.cs new file mode 100644 index 0000000..f08016f --- /dev/null +++ b/BetterSecondbot/HttpService/Self.cs @@ -0,0 +1,131 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class Http_Self : WebApiControllerWithTokens + { + public Http_Self(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Makes the bot turn to face avatar and point at them (if found)")] + [ReturnHints("ok")] + [ReturnHints("Cant find UUID in sim")] + [Route(HttpVerbs.Get, "/PointAt/{avatar}/{token}")] + public object PointAt(string avatar, string token) + { + if (tokens.Allow(token, "self", "PointAt", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if (bot.GetClient.Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false) + { + return Failure("Cant find UUID in sim"); + } + bot.ResetAnimations(); + bot.GetClient.Self.Stand(); + bot.GetClient.Self.Movement.TurnToward(bot.GetClient.Network.CurrentSim.AvatarPositions[avataruuid]); + bot.GetClient.Self.Movement.SendUpdate(); + bot.GetClient.Self.AnimationStart(Animations.POINT_YOU, true); + bot.GetClient.Self.PointAtEffect(bot.GetClient.Self.AgentID, avataruuid, new Vector3d(0, 0, 0), PointAtType.Select, UUID.Random()); + bot.GetClient.Self.BeamEffect(bot.GetClient.Self.AgentID, avataruuid, new Vector3d(0, 0, 2), new Color4(255, 255, 255, 1), (float)3.0, UUID.Random()); + return BasicReply("ok"); + } + + [About("Makes the bot sit on the ground or on a object if it can see it")] + [ReturnHints("ok")] + [ReturnHints("Invaild object UUID")] + [ArgHints("target", "URLARG", "ground or a object UUID")] + [Route(HttpVerbs.Get, "/Sit/{target}/{token}")] + public object Sit(string target, string token) + { + if (tokens.Allow(token, "self", "Sit", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if(target == "ground") + { + bot.GetClient.Self.SitOnGround(); + return BasicReply("ok"); + } + if(UUID.TryParse(target,out UUID objectuuid) == false) + { + return Failure("Invaild object UUID"); + } + bot.GetClient.Self.RequestSit(objectuuid, Vector3.Zero); + return BasicReply("ok"); + } + + [About("Makes the bot stand up if sitting (also resets animations)")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/Stand/{token}")] + public object Stand(string target, string token) + { + if (tokens.Allow(token, "self", "Stand", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + bot.GetClient.Self.Stand(); + bot.ResetAnimations(); + return BasicReply("ok"); + } + + [About("Makes the bot sit on the ground or on a object if it can see it")] + [ReturnHints("true|false")] + [ReturnHints("Invaild object UUID")] + [ReturnHints("Unable to see object")] + [ArgHints("target", "URLARG", "object UUID")] + [Route(HttpVerbs.Get, "/ClickObject/{object}/{token}")] + public object ClickObject(string target, string token) + { + if (tokens.Allow(token, "self", "ClickObject", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(target, out UUID objectuuid) == false) + { + return Failure("Invaild object UUID"); + } + Dictionary objectsentrys = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); + bool found_object = false; + foreach (KeyValuePair entry in objectsentrys) + { + if (entry.Value.ID == objectuuid) + { + bot.GetClient.Objects.ClickObject(bot.GetClient.Network.CurrentSim, entry.Key); + found_object = true; + break; + } + } + return BasicReply(found_object.ToString()); + } + + [About("Makes the bot sit on the ground or on a object if it can see it")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/Logoff/{token}")] + public object Logoff(string token) + { + if (tokens.Allow(token, "self", "Logoff", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.KillMe == false) + { + bot.GetClient.Self.Chat("Laters im out", 0, ChatType.Normal); + bot.KillMePlease(); + } + return BasicReply("ok"); + } + + + } +} diff --git a/Core/Commands/DiscordAPI/BulkClear_Messages.cs b/Core/Commands/DiscordAPI/BulkClear_Messages.cs deleted file mode 100644 index 49bea46..0000000 --- a/Core/Commands/DiscordAPI/BulkClear_Messages.cs +++ /dev/null @@ -1,75 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_BulkClear_Messages : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Member id" }; } } - public override string Helpfile { get { return "Clears messages on the server sent by the member in the last 13 days, 22hours 59mins"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - KeyValuePair reply = ClearMessages(args).Result; - Dictionary collection = new Dictionary(); - collection.Add("Deleted", reply.Value.ToString()); - return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "See status for state, see collection for total deleted", CommandName, collection); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task> ClearMessages(string[] args) - { - int messagesDeleted = 0; - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong memberid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketGuildUser user = server.GetUser(memberid); - TimeSpan somedays = new TimeSpan(13, 22, 59, 59, 0); - DateTimeOffset justundertwosweeks = DateTimeOffset.Now; - justundertwosweeks = justundertwosweeks.Subtract(somedays); - long unixtimelimit = justundertwosweeks.ToUnixTimeSeconds(); - foreach (SocketTextChannel channel in server.TextChannels) - { - List DeleteMessages = new List(); - IEnumerable messages = await channel.GetMessagesAsync(100).FlattenAsync(); - foreach (IMessage message in messages) - { - if (message.CreatedAt.ToUnixTimeSeconds() > unixtimelimit) - { - if (message.Author.Id == user.Id) - { - DeleteMessages.Add(message); - } - } - } - if(DeleteMessages.Count() > 0) - { - messagesDeleted += DeleteMessages.Count(); - await channel.DeleteMessagesAsync(DeleteMessages); - } - } - return new KeyValuePair(true, messagesDeleted); - } - } - return new KeyValuePair(false,0); - } - } -} diff --git a/Core/Commands/DiscordAPI/Dm_Member.cs b/Core/Commands/DiscordAPI/Dm_Member.cs deleted file mode 100644 index 7a2e311..0000000 --- a/Core/Commands/DiscordAPI/Dm_Member.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_Dm_Member : CoreCommand_4arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "Text" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Server id", "Member id", "Message" }; } } - public override string Helpfile { get { return "Sends a message directly to the user [They must be in the server]\n This command requires the SERVER MEMBERS INTENT found in discord app dev"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool reply = MessageMember(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task MessageMember(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong memberid) == true) - { - try - { - SocketGuild server = Discord.GetGuild(serverid); - IEnumerable users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true); - bool sent = false; - foreach(IGuildUser user in users) - { - if(user.Id == memberid) - { - sent = true; - await user.SendMessageAsync(args[3]); - break; - } - } - return sent; - } - catch - { - return false; - } - } - } - return false; - } - } -} diff --git a/Core/Commands/DiscordAPI/MembersList.cs b/Core/Commands/DiscordAPI/MembersList.cs deleted file mode 100644 index a771545..0000000 --- a/Core/Commands/DiscordAPI/MembersList.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_MembersList : CoreCommand_SmartReply_2arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id" }; } } - public override string Helpfile { get { return "Returns a list of members in a server \n collection is userid: username \n if the user has set a nickname: userid: nickname|username \n This command requires Discord full client mode enabled and connected\n !!!! This command also requires: Privileged Gateway Intents / SERVER MEMBERS INTENT set to true on the discord bot api area !!!"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - KeyValuePair> reply = ListMembers(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName, reply.Value); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task>> ListMembers(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - IEnumerable users = await server.GetUsersAsync().FlattenAsync().ConfigureAwait(true); - Dictionary membersList = new Dictionary(); - - foreach (IGuildUser user in users) - { - if (user.Nickname != null) - { - membersList.Add(user.Id.ToString(), user.Nickname+"|"+user.Username); - } - else - { - membersList.Add(user.Id.ToString(), user.Username); - } - } - return new KeyValuePair>(true, membersList); - } - return new KeyValuePair>(false, new Dictionary()); - } - } -} diff --git a/Core/Commands/DiscordAPI/MessageChannel.cs b/Core/Commands/DiscordAPI/MessageChannel.cs deleted file mode 100644 index dd8c1ae..0000000 --- a/Core/Commands/DiscordAPI/MessageChannel.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_MessageChannel : CoreCommand_4arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "Message", "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "channel id", "Message to send", "Use TTS defaults to False" }; } } - public override string Helpfile { get { return "Sends a message to the selected channel - Optional TTS usage"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool reply = MessageChannel(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task MessageChannel(string[] args) - { - bool useTTS = false; - if (args.Length == 5) - { - bool.TryParse(args[4], out useTTS); - } - return await bot.SendMessageToDiscord(args[1], args[2], args[3], useTTS); - } - } -} diff --git a/Core/Commands/DiscordAPI/MuteMember.cs b/Core/Commands/DiscordAPI/MuteMember.cs deleted file mode 100644 index 623e576..0000000 --- a/Core/Commands/DiscordAPI/MuteMember.cs +++ /dev/null @@ -1,57 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_MuteMember : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number", "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Member id", "{Optional} Mute status (defaults to true) set this to False to unmute" }; } } - public override string Helpfile { get { return "Updates the Mute status of the member"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool reply = MuteMember(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(reply, args[0], "see status for state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task MuteMember(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong memberid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketGuildUser user = server.GetUser(memberid); - bool status = true; - if (args.Length == 4) - { - bool.TryParse(args[3], out status); - } - await user.ModifyAsync(pr => - { - pr.Mute = status; - }); - return true; - } - } - return false; - } - } -} diff --git a/Core/Commands/DiscordAPI/RoleCreate.cs b/Core/Commands/DiscordAPI/RoleCreate.cs deleted file mode 100644 index 7f265cb..0000000 --- a/Core/Commands/DiscordAPI/RoleCreate.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_RoleCreate : CoreCommand_SmartReply_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart","Number","Text" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]","Discord server id","Role name" }; } } - public override string Helpfile { get { return "Creates a new role and returns its role ID via smart target\n This command requires Discord full client mode enabled and connected"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - KeyValuePair reply = CreateRole(args).Result; - Dictionary collection = new Dictionary(); - collection.Add("roleid", reply.Value.ToString()); - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], "ok", CommandName, collection); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task> CreateRole(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - RestRole role = await server.CreateRoleAsync(args[2], new GuildPermissions(), Color.DarkRed, false, null).ConfigureAwait(true); - return new KeyValuePair("ok", role.Id); - } - return new KeyValuePair("Unable to process server id", 0); - } - } -} diff --git a/Core/Commands/DiscordAPI/RoleList.cs b/Core/Commands/DiscordAPI/RoleList.cs deleted file mode 100644 index 3490ce2..0000000 --- a/Core/Commands/DiscordAPI/RoleList.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_RoleList: CoreCommand_SmartReply_2arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id" }; } } - public override string Helpfile { get { return "Returns a list of roles and their ids in collection \n This command requires Discord full client mode enabled and connected"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - KeyValuePair> reply = ListRoles(args); - return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName, reply.Value); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected KeyValuePair> ListRoles(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - Dictionary rolesList = new Dictionary(); - foreach (SocketRole role in server.Roles) - { - rolesList.Add(role.Id.ToString(), role.Name); - } - return new KeyValuePair>(true, rolesList); - } - return new KeyValuePair>(false,new Dictionary()); - } - } -} diff --git a/Core/Commands/DiscordAPI/RoleRemove.cs b/Core/Commands/DiscordAPI/RoleRemove.cs deleted file mode 100644 index ad4a3c1..0000000 --- a/Core/Commands/DiscordAPI/RoleRemove.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_RoleRemove: CoreCommand_SmartReply_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id" }; } } - public override string Helpfile { get { return "Remove a new role from a server \n This command requires Discord full client mode enabled and connected"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool status = RemoveRole(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(status, args[0], "see status for removal state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected async Task RemoveRole(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong roleid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketRole role = server.GetRole(roleid); - await role.DeleteAsync().ConfigureAwait(true); - return true; - } - } - return false; - } - } -} diff --git a/Core/Commands/DiscordAPI/Role_GetSettings.cs b/Core/Commands/DiscordAPI/Role_GetSettings.cs deleted file mode 100644 index 4f21e65..0000000 --- a/Core/Commands/DiscordAPI/Role_GetSettings.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_Role_GetSettings : CoreCommand_SmartReply_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id" }; } } - public override string Helpfile { get { return "returns a collection of settings for the given role \n This command requires Discord full client mode enabled and connected"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - KeyValuePair> reply = RoleSettings(args); - return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName,reply.Value); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected KeyValuePair> RoleSettings(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong roleid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketRole role = server.GetRole(roleid); - Dictionary settings = new Dictionary - { - { "Config|Color", String.Join(",", new byte[3] { role.Color.R, role.Color.G, role.Color.B }) }, - { "Config|Name", role.Name }, - { "Info|AssignedCount", role.Members.Count().ToString() }, - { "Perm|AttachFiles", role.Permissions.AttachFiles.ToString() }, - { "Perm|ReadMessageHistory", role.Permissions.ReadMessageHistory.ToString() }, - { "Perm|MentionEveryone", role.Permissions.MentionEveryone.ToString() }, - { "Perm|UseExternalEmojis", role.Permissions.UseExternalEmojis.ToString() }, - { "Perm|Connect", role.Permissions.Connect.ToString() }, - { "Perm|Speak", role.Permissions.Speak.ToString() }, - { "Perm|MuteMembers", role.Permissions.MuteMembers.ToString() }, - { "Perm|UseVAD", role.Permissions.UseVAD.ToString() }, - { "Perm|MoveMembers", role.Permissions.MoveMembers.ToString() }, - { "Perm|EmbedLinks", role.Permissions.EmbedLinks.ToString() }, - { "Perm|PrioritySpeaker", role.Permissions.PrioritySpeaker.ToString() }, - { "Perm|Stream", role.Permissions.Stream.ToString() }, - { "Perm|ChangeNickname", role.Permissions.ChangeNickname.ToString() }, - { "Perm|ManageNicknames", role.Permissions.ManageNicknames.ToString() }, - { "Perm|ManageRoles", role.Permissions.ManageRoles.ToString() }, - { "Perm|DeafenMembers", role.Permissions.DeafenMembers.ToString() }, - { "Perm|ManageMessages", role.Permissions.ManageMessages.ToString() }, - { "Perm|ViewChannel", role.Permissions.ViewChannel.ToString() }, - { "Perm|SendMessages", role.Permissions.SendMessages.ToString() }, - { "Perm|CreateInstantInvite", role.Permissions.CreateInstantInvite.ToString() }, - { "Perm|BanMembers", role.Permissions.BanMembers.ToString() }, - { "Perm|SendTTSMessages", role.Permissions.SendTTSMessages.ToString() }, - { "Perm|Administrator", role.Permissions.Administrator.ToString() }, - { "Perm|ManageChannels", role.Permissions.ManageChannels.ToString() }, - { "Perm|KickMembers", role.Permissions.KickMembers.ToString() }, - { "Perm|AddReactions", role.Permissions.AddReactions.ToString() }, - { "Perm|ViewAuditLog", role.Permissions.ViewAuditLog.ToString() }, - { "Perm|ManageWebhooks", role.Permissions.ManageWebhooks.ToString() }, - { "Perm|ManageGuild", role.Permissions.ManageGuild.ToString() }, - { "Perm|ManageEmojis", role.Permissions.ManageEmojis.ToString() } - }; - return new KeyValuePair>(true, settings); - } - } - return new KeyValuePair>(false, new Dictionary()); - } - } -} diff --git a/Core/Commands/DiscordAPI/Role_UpdatePerms.cs b/Core/Commands/DiscordAPI/Role_UpdatePerms.cs deleted file mode 100644 index 5e53575..0000000 --- a/Core/Commands/DiscordAPI/Role_UpdatePerms.cs +++ /dev/null @@ -1,165 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_Role_UpdatePerms : CoreCommand_4arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number", "Number","Text" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id", "Role id","CSV list of PermFlag=Bool" }; } } - public override string Helpfile { get { return "Updates perm flags for the selected role \n example CSV format: Speak=True,SendMessages=False \n for a full list of perms see output of DiscordRoleGetSettings \n This command requires Discord full client mode enabled and connected"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - bool status = UpdateRolePerms(args).Result; - return bot.GetCommandsInterface.SmartCommandReply(status, args[0], "see status for update state", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected GuildPermissions UpdateFlag(GuildPermissions NewPerms,string flag, bool flagValue) - { - switch (flag) - { - case "CreateInstantInvite": - NewPerms = NewPerms.Modify(flagValue); - break; - case "KickMembers": - NewPerms = NewPerms.Modify(null, flagValue); - break; - case "BanMembers": - NewPerms = NewPerms.Modify(null, null, flagValue); - break; - case "Administrator": - NewPerms = NewPerms.Modify(null, null, null, flagValue); - break; - case "ManageChannels": - NewPerms = NewPerms.Modify(null, null, null, null, flagValue); - break; - case "ManageGuild": - NewPerms = NewPerms.Modify(null, null, null, null, null, flagValue); - break; - case "AddReactions": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, flagValue); - break; - case "ViewAuditLog": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, flagValue); - break; - case "SendTTSMessages": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "AttachFiles": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ReadMessageHistory": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "MentionEveryone": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "UseExternalEmojis": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "Connect": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "Speak": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "MuteMembers": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "UseVAD": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "MoveMembers": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "EmbedLinks": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "PrioritySpeaker": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "Stream": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ChangeNickname": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ManageNicknames": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ManageRoles": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "DeafenMembers": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ManageMessages": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ViewChannel": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, flagValue); - break; - case "SendMessages": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ManageWebhooks": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - case "ManageEmojis": - NewPerms = NewPerms.Modify(null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, flagValue); - break; - default: - break; - } - return NewPerms; - } - - protected async Task UpdateRolePerms(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - if (ulong.TryParse(args[2], out ulong roleid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - SocketRole role = server.GetRole(roleid); - string[] bits = args[3].Split(','); - GuildPermissions NewPerms = role.Permissions; - foreach (String bit in bits) - { - string[] subbits = bit.Split('='); - if(subbits.Length == 2) - { - if(bool.TryParse(subbits[1],out bool flagValue) == true) - { - NewPerms = UpdateFlag(NewPerms, subbits[0], flagValue); - } - } - } - await role.ModifyAsync(Rp => - { - Rp.Permissions = NewPerms; - }).ConfigureAwait(true); - return true; - } - } - return false; - } - } -} diff --git a/Core/Commands/DiscordAPI/TextChannels_List.cs b/Core/Commands/DiscordAPI/TextChannels_List.cs deleted file mode 100644 index a18d72c..0000000 --- a/Core/Commands/DiscordAPI/TextChannels_List.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using Newtonsoft.Json; -using Discord.WebSocket; -using Discord; -using Discord.Rest; -using System.Threading.Tasks; - -namespace BetterSecondBot.Commands.DiscordAPI -{ - class Discord_TextChannels_List : CoreCommand_SmartReply_2arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]", "Discord server id" }; } } - public override string Helpfile { get { return "Returns a list of text channels in a server \n collection is channelid: name"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.discordReady() == false) - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], bot.getDiscordWhyFailed(), CommandName); - } - KeyValuePair> reply = ListTextChannels(args); - return bot.GetCommandsInterface.SmartCommandReply(reply.Key, args[0], "see status for state", CommandName, reply.Value); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "incorrect args", CommandName); - } - - protected KeyValuePair> ListTextChannels(string[] args) - { - DiscordSocketClient Discord = bot.getDiscordClient(); - if (ulong.TryParse(args[1], out ulong serverid) == true) - { - SocketGuild server = Discord.GetGuild(serverid); - Dictionary textChannels = new Dictionary(); - foreach(SocketTextChannel channel in server.TextChannels) - { - textChannels.Add(channel.Id.ToString(), channel.Name); - } - return new KeyValuePair>(true, textChannels); - } - return new KeyValuePair>(false, new Dictionary()); - } - } -} diff --git a/Core/Commands/Estate/EstateParcelReclaim.cs b/Core/Commands/Estate/EstateParcelReclaim.cs deleted file mode 100644 index 47a8e4e..0000000 --- a/Core/Commands/Estate/EstateParcelReclaim.cs +++ /dev/null @@ -1,25 +0,0 @@ -namespace BetterSecondBot.Commands.Estate -{ - public class EstateParcelReclaim : CoreCommand - { - public override string Helpfile { get { return "Reclaims ownership of the current parcel"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetClient.Network.CurrentSim.IsEstateManager == true) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - bot.GetClient.Parcels.Reclaim(bot.GetClient.Network.CurrentSim, localid); - return true; - } - else - { - return Failed("Not an estate manager here"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Estate/GetSimGlobalPos.cs b/Core/Commands/Estate/GetSimGlobalPos.cs deleted file mode 100644 index 60f007d..0000000 --- a/Core/Commands/Estate/GetSimGlobalPos.cs +++ /dev/null @@ -1,27 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Estate -{ - public class GetSimGlobalPos : CoreCommand_SmartReply_2arg - { - public override string Helpfile { get { return "Fetchs a region and returns its global X,Y"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetClient.Grid.GetGridRegion(args[1], GridLayerType.Objects, out GridRegion region)) - { - collection.Add("X", region.X.ToString()); - collection.Add("Y", region.Y.ToString()); - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], "ok", CommandName,collection); - } - else - { - return Failed("Unable to find region"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Estate/GetSimTexture.cs b/Core/Commands/Estate/GetSimTexture.cs deleted file mode 100644 index de732b1..0000000 --- a/Core/Commands/Estate/GetSimTexture.cs +++ /dev/null @@ -1,25 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Estate -{ - public class GetSimTexture : CoreCommand_SmartReply_2arg - { - public override string Helpfile { get { return "Fetchs a region and returns its tile texture UUID - Expect this to die at some point!"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetClient.Grid.GetGridRegion(args[1], GridLayerType.Objects, out GridRegion region)) - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], region.MapImageID.ToString(),CommandName); - } - else - { - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "Unable to find region", CommandName); - } - } - return false; - } - } -} diff --git a/Core/Commands/Estate/SimMessage.cs b/Core/Commands/Estate/SimMessage.cs deleted file mode 100644 index 2083466..0000000 --- a/Core/Commands/Estate/SimMessage.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace BetterSecondBot.Commands.Estate -{ - public class SimMessage : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Text" }; } } - public override string[] ArgHints { get { return new[] { "Message to send" }; } } - public override string Helpfile { get { return "Sends the message [ARG 1] to the current sim"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetClient.Network.CurrentSim.IsEstateManager == true) - { - bot.GetClient.Estate.SimulatorMessage(args[0]); - return true; - } - else - { - return Failed("Not an estate manager here"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Estate/SimRestart.cs b/Core/Commands/Estate/SimRestart.cs deleted file mode 100644 index 86471ad..0000000 --- a/Core/Commands/Estate/SimRestart.cs +++ /dev/null @@ -1,45 +0,0 @@ -namespace BetterSecondBot.Commands.Estate -{ - public class SimRestart : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "True|False","Number" }; } } - public override string[] ArgHints { get { return new[] { "Restart mode: True=Restart sim,False=Cancel restart","delay in secs to restart (Min 30 - max 240) defaults to 60 if not given" }; } } - public override string Helpfile { get { return "Sends the message [ARG 1] to the current sim"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetClient.Network.CurrentSim.IsEstateManager == true) - { - - if(bool.TryParse(args[0],out bool mode) == true) - { - if(mode == false) - { - bot.GetClient.Estate.CancelRestart(); - } - else - { - int delay_restart = 60; - if(args.Length == 2) - { - int.TryParse(args[1], out delay_restart); - } - bot.GetClient.Estate.RestartRegion(delay_restart); - } - } - else - { - return Failed("True or False request for arg 1"); - } - } - else - { - return Failed("Not an estate manager here"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Friends/FriendFullPerms.cs b/Core/Commands/Friends/FriendFullPerms.cs deleted file mode 100644 index 9c4c5a6..0000000 --- a/Core/Commands/Friends/FriendFullPerms.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System; -using OpenMetaverse; -namespace BetterSecondBot.Commands.Friends -{ - public class FriendFullPerms : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar","True|False" }; } } - public override string[] ArgHints { get { return new[] { "Avatar UUID or Firstname Lastname","What status should it be" }; } } - public override string Helpfile { get { return "Updates the friend perms for avatar [Arg 1] to [Arg 2] (Online/Map/Modify)"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID avatar) == true) - { - if(bool.TryParse(args[1],out bool status) == true) - { - if (bot.GetClient.Friends.FriendList.ContainsKey(avatar) == true) - { - if (status == true) - { - bot.GetClient.Friends.GrantRights(avatar, FriendRights.CanSeeOnline | FriendRights.CanSeeOnMap | FriendRights.CanModifyObjects); - InfoBlob = "Friendship rights granted"; - } - else - { - bot.GetClient.Friends.GrantRights(avatar, FriendRights.None); - InfoBlob = "Friendship rights removed"; - } - return true; - } - return Failed("Avatar not on friends list or friends list has not updated yet"); - } - return Failed("Unable to process arg 2"); - } - return Failed("Unable to process avatar on arg 1"); - } - return false; - } - } - -} diff --git a/Core/Commands/Friends/FriendRequest.cs b/Core/Commands/Friends/FriendRequest.cs deleted file mode 100644 index f26d34f..0000000 --- a/Core/Commands/Friends/FriendRequest.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using OpenMetaverse; -namespace BetterSecondBot.Commands.Friends -{ - public class FriendRequest : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar UUID or Firstname Lastname" }; } } - public override string Helpfile { get { return "sends a friend request to the target avatar"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID avatar) == true) - { - if (bot.GetClient.Friends.FriendList.ContainsKey(avatar) == false) - { - bot.GetClient.Friends.OfferFriendship(avatar); - } - return true; - } - return Failed("Unable to process avatar on arg 1"); - } - return false; - } - } - -} diff --git a/Core/Commands/Friends/Friendslist.cs b/Core/Commands/Friends/Friendslist.cs deleted file mode 100644 index cc05419..0000000 --- a/Core/Commands/Friends/Friendslist.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using OpenMetaverse; -namespace BetterSecondBot.Commands.Friends -{ - public class Friendslist : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Returns a copy of the friends list"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], bot.getJsonFriendlist(), CommandName); - } - return false; - } - } - -} diff --git a/Core/Commands/Group/GroupActiveGroup.cs b/Core/Commands/Group/GroupActiveGroup.cs deleted file mode 100644 index 5e9dd2d..0000000 --- a/Core/Commands/Group/GroupActiveGroup.cs +++ /dev/null @@ -1,38 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.Group -{ - class GroupActiveGroup : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Group"}; } } - public override string[] ArgHints { get { return new[] { "Group UUID or Name" }; } } - public override string Helpfile { get { return "Sets the selected group to the active group"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID group_uuid) != true) - { - foreach (KeyValuePair G in bot.MyGroups) - { - if (G.Value.Name == args[0]) - { - group_uuid = G.Key; - break; - } - } - } - if (group_uuid != UUID.Zero) - { - bot.GetClient.Groups.ActivateGroup(group_uuid); - return true; - } - return Failed("Unable to find group"); - } - return false; - } - } -} diff --git a/Core/Commands/Group/GroupActiveTitle.cs b/Core/Commands/Group/GroupActiveTitle.cs deleted file mode 100644 index 0b5fd6f..0000000 --- a/Core/Commands/Group/GroupActiveTitle.cs +++ /dev/null @@ -1,31 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.Group -{ - class GroupActiveTitle : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "UUID"}; } } - public override string[] ArgHints { get { return new[] { "UUID of the group","UUID of the role" }; } } - public override string Helpfile { get { return "Activates the selected title"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID group_uuid) == true) - { - if (UUID.TryParse(args[1], out UUID group_role) == true) - { - bot.GetClient.Groups.ActivateTitle(group_uuid, group_role); - return true; - } - return Failed("Unable to process group Role on arg 1"); - } - return Failed("Unable to process group UUID on arg 1"); - } - return false; - } - } -} diff --git a/Core/Commands/Group/GroupAddRole.cs b/Core/Commands/Group/GroupAddRole.cs deleted file mode 100644 index 092320c..0000000 --- a/Core/Commands/Group/GroupAddRole.cs +++ /dev/null @@ -1,108 +0,0 @@ -using System; -using OpenMetaverse; -using BetterSecondBotShared.logs; - -namespace BetterSecondBot.Commands.Group -{ - class GroupAddRole : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Avatar", "UUID" }; } } - public override string[] ArgHints { get { return new[] { "GROUP", "Avatar [UUID or Firstname Lastname]", "Role" }; } } - public override string Helpfile { get { return "Adds the avatar [ARG 2] to the Group [ARG 1] with the role [ARG 3] if they are not in the group then it invites them"; } } - - public override void Callback(string[] args, EventArgs e) - { - GroupMembersReplyEventArgs reply = (GroupMembersReplyEventArgs)e; - if (UUID.TryParse(args[0], out UUID target_group) == true) - { - if (reply.GroupID == target_group) - { - if (UUID.TryParse(args[1], out UUID target_avatar) == true) - { - if (UUID.TryParse(args[2], out UUID target_role) == true) - { - if(reply.Members.ContainsKey(target_avatar) == true) - { - bot.GetClient.Groups.AddToRole(target_group, target_role, target_avatar); - InfoBlob = "Role added to avatar: " + target_avatar.ToString() + ""; - base.Callback(args, e, true); - } - else - { - InfoBlob = "{GroupAddRole} Member not in group to get role, passing to invite"; - bot.GetCommandsInterface.Call("GroupInvite", String.Join("~#~", args), caller, "~#~"); - base.Callback(args, e, true); - } - - } - else - { - InfoBlob = "{ GroupAddRole} Unable to unpack role as part of the callback"; - base.Callback(args, e, false); - } - } - else - { - InfoBlob = "{GroupAddRole} Unable to unpack avatar as part of the callback"; - base.Callback(args, e, false); - } - } - else - { - InfoBlob = "Callback sent for the wrong group as part of GroupAddRole!"; - base.Callback(args, e, false); - } - } - else - { - InfoBlob = "{GroupAddRole} Unable to unpack group as part of the callback"; - base.Callback(args, e, false); - } - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target_group) == true) - { - if (UUID.TryParse(args[1], out UUID _) == true) - { - if (UUID.TryParse(args[2], out UUID _) == true) - { - if (bot.MyGroups.ContainsKey(target_group) == true) - { - if (bot.CreateAwaitEventReply("groupmembersreply", this, args) == true) - { - bot.GetClient.Groups.RequestGroupMembers(target_group); - InfoBlob = "Requesting group membership"; - return true; - } - else - { - return Failed("Unable to await reply"); - } - } - else - { - return Failed("I am not a member of that group"); - } - } - else - { - return Failed("Invaild role UUID"); - } - } - else - { - return Failed("Invaild avatar UUID"); - } - } - else - { - return Failed("Invaild group UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Group/GroupEject.cs b/Core/Commands/Group/GroupEject.cs deleted file mode 100644 index cf521ab..0000000 --- a/Core/Commands/Group/GroupEject.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using OpenMetaverse; -using BetterSecondBotShared.logs; - -namespace BetterSecondBot.Commands.Group -{ - public class GroupEject : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "GROUP", "Avatar [UUID or Firstname Lastname]"}; } } - public override string Helpfile { get { return "Eject selected avatar from group"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target_group) == true) - { - if (UUID.TryParse(args[1], out UUID target_avatar) == true) - { - if (bot.MyGroups.ContainsKey(target_group) == true) - { - bot.GetClient.Groups.EjectUser(target_group, target_avatar); - return true; - } - else - { - return Failed("I am not a member of that group"); - } - } - else - { - return Failed("Invaild avatar UUID"); - } - } - else - { - return Failed("Invaild group UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Group/GroupInvite.cs b/Core/Commands/Group/GroupInvite.cs deleted file mode 100644 index 020480a..0000000 --- a/Core/Commands/Group/GroupInvite.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System; -using System.Collections.Generic; -using OpenMetaverse; -using BetterSecondBotShared.logs; - -namespace BetterSecondBot.Commands.Group -{ - public class GroupInvite : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Avatar", "UUID" }; } } - public override string[] ArgHints { get { return new[] { "GROUP", "Avatar [UUID or Firstname Lastname]", "Role" }; } } - public override string Helpfile { get { return "Invites the avatar [ARG 2] to the Group [ARG 1] {optional with the Role [ARG 3]} otherwise to role Everyone"; } } - - protected void ForRealGroupInvite(string[] args,UUID group,UUID avatar) - { - UUID target_role = UUID.Zero; - if (args.Length == 3) - { - if(UUID.TryParse(args[2], out target_role) == false) - { - LogFormater.Warn("GroupInvite: Role uuid not vaild using everyone"); - } - } - bot.GetClient.Groups.Invite(group, new List() { target_role }, avatar); - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target_group) == true) - { - if (UUID.TryParse(args[1], out UUID target_avatar) == true) - { - if (bot.MyGroups.ContainsKey(target_group) == true) - { - if (bot.GetAllowGroupInvite(target_avatar, target_group) == true) - { - bot.GroupInviteLockoutArm(target_avatar,target_group); // enable 120 sec cooldown - ForRealGroupInvite(args, target_group, target_avatar); - return true; - } - else - { - return Failed("Group invite to this avatar is on 120sec cooldown"); - } - } - else - { - return Failed("I am not a member of that group"); - } - } - else - { - return Failed("Invaild avatar UUID"); - } - } - else - { - return Failed("Invaild group UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Group/GroupInviteNoLimiter.cs b/Core/Commands/Group/GroupInviteNoLimiter.cs deleted file mode 100644 index ec4eb55..0000000 --- a/Core/Commands/Group/GroupInviteNoLimiter.cs +++ /dev/null @@ -1,58 +0,0 @@ -using BetterSecondBotShared.logs; -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.Group -{ - class GroupInviteNoLimiter: CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Avatar", "UUID" }; } } - public override string[] ArgHints { get { return new[] { "GROUP", "Avatar [UUID or Firstname Lastname]", "Role" }; } } - public override string Helpfile { get { return "see GroupInvite, note: This command bypasses the limiter use at your own risk!"; } } - - protected void ForRealGroupInvite(string[] args, UUID group, UUID avatar) - { - UUID target_role = UUID.Zero; - if (args.Length == 3) - { - if (UUID.TryParse(args[2], out target_role) == false) - { - LogFormater.Warn("GroupInviteNoLimiter: Role uuid not vaild using everyone"); - } - } - bot.GetClient.Groups.Invite(group, new List() { target_role }, avatar); - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target_group) == true) - { - if (UUID.TryParse(args[1], out UUID target_avatar) == true) - { - if (bot.MyGroups.ContainsKey(target_group) == true) - { - ForRealGroupInvite(args, target_group, target_avatar); - return true; - } - else - { - return Failed("I am not a member of that group"); - } - } - else - { - return Failed("Invaild avatar UUID"); - } - } - else - { - return Failed("Invaild group UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Group/GroupNotice.cs b/Core/Commands/Group/GroupNotice.cs deleted file mode 100644 index 1341c7d..0000000 --- a/Core/Commands/Group/GroupNotice.cs +++ /dev/null @@ -1,53 +0,0 @@ -using BetterSecondBotShared.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - class Groupnotice : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "TEXT","TEXT","TEXT" }; } } - public override string[] ArgHints { get { return new[] { "Group", "Message/Title", "Message","Inventory UUID" }; } } - public override string Helpfile { get { return "Sends a group notice to [ARG 1] with the message [ARG 2]
if given 3 Args: Sends a group notice to [ARG 1] with the title [ARG 2] and the message [ARG 3]
if [ARG 4] is given then it also sends the notice with an attachment"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetgroup) == true) - { - if (bot.MyGroups.ContainsKey(targetgroup) == true) - { - string Noticetitle = "GroupNotice@"+ helpers.UnixTimeNow().ToString()+""; - string Noticemessage = args[1]; - if (args.Length >= 3) - { - Noticetitle = args[1]; - Noticemessage = args[2]; - } - GroupNotice NewNotice = new GroupNotice(); - NewNotice.Subject = Noticetitle; - NewNotice.Message = Noticemessage; - NewNotice.OwnerID = bot.GetClient.Self.AgentID; - if (args.Length == 4) - { - if (UUID.TryParse(args[3], out UUID result) == true) - { - NewNotice.AttachmentID = result; - } - } - bot.GetClient.Groups.SendGroupNotice(targetgroup, NewNotice); - return true; - } - else - { - return Failed("Unkown group"); - } - } - else - { - return Failed("Invaild UUID"); - } - } - return false; - } - } -} \ No newline at end of file diff --git a/Core/Commands/Group/IsGroupMember.cs b/Core/Commands/Group/IsGroupMember.cs deleted file mode 100644 index b98fd93..0000000 --- a/Core/Commands/Group/IsGroupMember.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Newtonsoft.Json; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - public class IsGroupMember : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Mixed", "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Group", "Smart reply [Channel|IM uuid|http url]", "Avatar [UUID or Firstname Lastname]" }; } } - public override string Helpfile { get { return "Returns if the selected user is in the group or not"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetgroup) == true) - { - if (UUID.TryParse(args[2], out UUID testavatar) == true) - { - if (bot.FastCheckInGroup(targetgroup, testavatar) == true) - { - Dictionary reply = new Dictionary - { - { "group", args[0] }, - { "avatar", args[2] }, - { "ingroup", "1" } - }; - return bot.GetCommandsInterface.SmartCommandReply(true, args[1], JsonConvert.SerializeObject(reply), CommandName); - } - else - { - if (bot.MyGroups.ContainsKey(targetgroup) == true) - { - if (bot.CreateAwaitEventReply("groupmembersreply", this, args) == true) - { - bot.GetClient.Groups.RequestGroupMembers(targetgroup); - InfoBlob = "Requesting group membership"; - return true; - } - else - { - return Failed("Unable to await reply"); - } - - } - else - { - return Failed("Unknown group"); - } - } - } - else - { - return Failed("Unable to find avatar"); - } - } - else - { - return Failed("Invaild UUID"); - } - } - return false; - } - - public override void Callback(string[] args, EventArgs e) - { - if (UUID.TryParse(args[2], out UUID testavatar) == true) - { - GroupMembersReplyEventArgs members_reply = (GroupMembersReplyEventArgs)e; - string return_status = "0"; - foreach (KeyValuePair data in members_reply.Members) - { - if (data.Value.ID == testavatar) - { - return_status = "1"; - break; - } - } - Dictionary reply = new Dictionary - { - { "group", args[0] }, - { "avatar", args[2] }, - { "ingroup", return_status } - }; - bot.GetCommandsInterface.SmartCommandReply(true, args[1], JsonConvert.SerializeObject(reply), CommandName); - } - base.Callback(args, e); - } - } -} diff --git a/Core/Commands/Group/getGroupList.cs b/Core/Commands/Group/getGroupList.cs deleted file mode 100644 index c285e2a..0000000 --- a/Core/Commands/Group/getGroupList.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - public class GetGroupList : CoreGroupCommand_SmartReply_auto - { - public override string Helpfile { get { return "Gets a list of groups Json encoded"; } } - protected override string RunFunction() - { - foreach (KeyValuePair groupdata in bot.MyGroups) - { - collection.Add(groupdata.Value.Name, groupdata.Key.ToString()); - } - return "grouplist=loaded"; - } - } -} diff --git a/Core/Commands/Group/getGroupMembers.cs b/Core/Commands/Group/getGroupMembers.cs deleted file mode 100644 index dce0041..0000000 --- a/Core/Commands/Group/getGroupMembers.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - public class GetGroupMembers : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Mixed" }; } } - public override string[] ArgHints { get { return new[] { "Group", "Smart reply [Channel|IM uuid|http url]" }; } } - public override string Helpfile { get { return "Gets membership of a group plus online status "; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetgroup) == true) - { - if (bot.MyGroups.ContainsKey(targetgroup) == true) - { - if (bot.CreateAwaitEventReply("groupmembersreply", this, args) == true) - { - bot.GetClient.Groups.RequestGroupMembers(targetgroup); - InfoBlob = "Requesting group membership"; - return true; - } - else - { - return Failed("Unable to await reply"); - } - - } - else - { - return Failed("Unknown group"); - } - } - else - { - return Failed("Invaild UUID"); - } - } - return false; - } - - public override void Callback(string[] args, EventArgs e) - { - GroupMembersReplyEventArgs members_reply = (GroupMembersReplyEventArgs)e; - Dictionary collection = new Dictionary(); - foreach (KeyValuePair data in members_reply.Members) - { - collection.Add(data.Key.ToString(), data.Value.OnlineStatus); - } - bot.GetCommandsInterface.SmartCommandReply(true, args[1], "group=" + args[0], CommandName, collection); - base.Callback(args, e); - } - } -} diff --git a/Core/Commands/Group/getGroupRoles.cs b/Core/Commands/Group/getGroupRoles.cs deleted file mode 100644 index 379dab0..0000000 --- a/Core/Commands/Group/getGroupRoles.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - public class GetGroupRoles : CoreGroupCommand_SmartReply_Group - { - public override string Helpfile { get { return "Gets a list of group roles Json encoded "; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[1], out UUID group) == true) - { - if (bot.CreateAwaitEventReply("grouproles", this, args) == true) - { - InfoBlob = "Requesting now"; - bot.GetClient.Groups.RequestGroupRoles(group); - return true; - } - else - { - return Failed("Unable to await reply"); - } - } - else - { - return Failed("Invaild group UUID"); - } - } - return false; - } - - public override void Callback(string[] args, EventArgs e) - { - GroupRolesDataReplyEventArgs rolesData = (GroupRolesDataReplyEventArgs)e; - foreach(KeyValuePair data in rolesData.Roles) - { - if (data.Key != UUID.Zero) - { - collection.Add(data.Value.Name, data.Value.ID.ToString()); - } - } - bot.GetCommandsInterface.SmartCommandReply(true,args[0], "group=" + args[1], CommandName,collection); - base.Callback(args, e); - } - } -} diff --git a/Core/Commands/Group/group.cs b/Core/Commands/Group/group.cs deleted file mode 100644 index 3ab64e6..0000000 --- a/Core/Commands/Group/group.cs +++ /dev/null @@ -1,58 +0,0 @@ -using OpenMetaverse; -using System.Collections.Generic; - -namespace BetterSecondBot.Commands.Group -{ - public abstract class CoreGroupCommand_SmartReply_auto : CoreCommand_SmartReply_1arg - { - protected virtual string RunFunction() - { - return ""; - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], RunFunction(), CommandName, collection); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "", CommandName); - } - } - - public abstract class CoreGroupCommand_SmartReply_Group : CoreCommand_2arg - { - protected Dictionary collection = new Dictionary(); - public override string[] ArgTypes { get { return new[] { "Mixed", "UUID" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply [Channel|IM uuid|http url]", "Group" }; } } - } - - public abstract class CoreGroupCommand_SmartReply_Group_auto : CoreGroupCommand_SmartReply_Group - { - protected virtual string RunFunction(UUID group) - { - return ""; - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[1], out UUID targetgroup) == true) - { - if (bot.MyGroups.ContainsKey(targetgroup) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], RunFunction(targetgroup), CommandName); - } - else - { - return Failed("Unknown group"); - } - } - else - { - return Failed("Invaild UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Group/groupchat.cs b/Core/Commands/Group/groupchat.cs deleted file mode 100644 index ce3c7bb..0000000 --- a/Core/Commands/Group/groupchat.cs +++ /dev/null @@ -1,62 +0,0 @@ -using OpenMetaverse; -using System; - -namespace BetterSecondBot.Commands.Group -{ - class Groupchat : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID","TEXT" }; } } - public override string[] ArgHints { get { return new[] { "Group","Message" }; } } - public override string Helpfile { get { return "Sends a message [ARG 2] to the group [ARG 1]"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetgroup) == true) - { - if (bot.MyGroups.ContainsKey(targetgroup) == true) - { - if (bot.GetActiveGroupchatSessions.Contains(targetgroup) == true) - { - Callback(args, null); - return true; - } - else - { - if (bot.CreateAwaitEventReply("groupchatjoin", this, args) == true) - { - bot.GetClient.Self.RequestJoinGroupChat(targetgroup); - return true; - } - else - { - return Failed("Unable to await reply"); - } - } - } - else - { - return Failed("Unkown group"); - } - } - else - { - return Failed("Invaild UUID"); - } - } - return false; - } - public override void Callback(string[] args, EventArgs e) - { - if (UUID.TryParse(args[0], out UUID targetgroup) == true) - { - bot.GetClient.Self.InstantMessageGroup(targetgroup, args[1]); - base.Callback(args, e); - } - else - { - base.Callback(args, e,false); - } - } - } -} \ No newline at end of file diff --git a/Core/Commands/Group/groupchatAnyUnread.cs b/Core/Commands/Group/groupchatAnyUnread.cs deleted file mode 100644 index 2e8451a..0000000 --- a/Core/Commands/Group/groupchatAnyUnread.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace BetterSecondBot.Commands.Group -{ - class GroupchatAnyUnread : CoreGroupCommand_SmartReply_auto - { - public override string Helpfile { get { return "Returns True|False via the smart reply target if there are any unread group ims"; } } - protected override string RunFunction() - { - return "groupchatunread="+bot.HasUnreadGroupchats().ToString(); - } - } -} \ No newline at end of file diff --git a/Core/Commands/Group/groupchatClearAll.cs b/Core/Commands/Group/groupchatClearAll.cs deleted file mode 100644 index d9c669d..0000000 --- a/Core/Commands/Group/groupchatClearAll.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BetterSecondBot.Commands.Group -{ - class GroupchatClearAll : CoreCommand - { - public override string Helpfile { get { return "Clears all group chat buffers at once"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bot.ClearAllGroupchat(); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Group/groupchatGroupHasUnread.cs b/Core/Commands/Group/groupchatGroupHasUnread.cs deleted file mode 100644 index b83c31b..0000000 --- a/Core/Commands/Group/groupchatGroupHasUnread.cs +++ /dev/null @@ -1,15 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - class GroupchatGroupHasUnread : CoreGroupCommand_SmartReply_Group_auto - { - public override string Helpfile { get { return "Returns True|False via the smart reply target if there are any unread group ims for the group [ARG 2]"; } } - - protected override string RunFunction(UUID targetgroup) - { - return ""+targetgroup.ToString()+"=" + bot.GroupHasUnread(targetgroup).ToString(); - } - - } -} diff --git a/Core/Commands/Group/groupchatHistory.cs b/Core/Commands/Group/groupchatHistory.cs deleted file mode 100644 index 22475f4..0000000 --- a/Core/Commands/Group/groupchatHistory.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System; -using System.Linq; -using Microsoft.VisualBasic.CompilerServices; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Group -{ - class GroupchatHistory : CoreGroupCommand_SmartReply_Group_auto - { - public override string Helpfile { get { return "Returns the chat history for the selected group [ARG 2] via smart reply [ARG 1]"; } } - protected override string RunFunction(UUID targetgroup) - { - int entry = 1; - foreach(string A in bot.GetGroupchat(targetgroup)) - { - collection.Add(entry.ToString(),A); - entry++; - } - return "group="+targetgroup.ToString()+""; - } - } -} diff --git a/Core/Commands/Group/groupchatListAllUnreadGroups.cs b/Core/Commands/Group/groupchatListAllUnreadGroups.cs deleted file mode 100644 index 15a8989..0000000 --- a/Core/Commands/Group/groupchatListAllUnreadGroups.cs +++ /dev/null @@ -1,21 +0,0 @@ -using OpenMetaverse; -using System.Text; - -namespace BetterSecondBot.Commands.Group -{ - public class GroupchatListAllUnreadGroups : CoreGroupCommand_SmartReply_auto - { - public override string Helpfile { get { return "Returns what groups have unread messages "; } } - - protected override string RunFunction() - { - int entry = 1; - foreach (UUID group in bot.UnreadGroupchatGroups()) - { - collection.Add(entry.ToString(),group.ToString()); - entry++; - } - return "count="+collection.Count.ToString(); - } - } -} diff --git a/Core/Commands/Home/GoHome.cs b/Core/Commands/Home/GoHome.cs deleted file mode 100644 index 30fa54a..0000000 --- a/Core/Commands/Home/GoHome.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BetterSecondBot.Commands.Home -{ - public class GoHome : CoreCommand - { - public override string Helpfile { get { return "Makes the bot teleport to its home region"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bot.GotoNextHomeRegion(); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Home/resetAtHome.cs b/Core/Commands/Home/resetAtHome.cs deleted file mode 100644 index 947db62..0000000 --- a/Core/Commands/Home/resetAtHome.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BetterSecondBot.Commands.Home -{ - public class ResetAtHome : CoreCommand - { - public override string Helpfile { get { return "Resets the at home lockouts"; } } - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - bot.ResetAtHome(); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Info/Balance.cs b/Core/Commands/Info/Balance.cs deleted file mode 100644 index 1b08433..0000000 --- a/Core/Commands/Info/Balance.cs +++ /dev/null @@ -1,21 +0,0 @@ -namespace BetterSecondBot.Commands.Info -{ - public class Balance : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Requests the current balance and sends that via the smart reply target and then requests the balance to update."; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bot.GetAllowFunds == true) - { - bool status = bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.GetClient.Self.Balance.ToString(), CommandName); - bot.GetClient.Self.RequestBalance(); - return status; - } - return bot.GetCommandsInterface.SmartCommandReply(false,args[0], "0", CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Info/GetPosition.cs b/Core/Commands/Info/GetPosition.cs deleted file mode 100644 index e617a63..0000000 --- a/Core/Commands/Info/GetPosition.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace BetterSecondBot.Commands.Info -{ - public class GetPosition : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Requests the Position and sends that via the smart reply target"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.GetClient.Self.RelativePosition.ToString(), CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Info/ParcelName.cs b/Core/Commands/Info/ParcelName.cs deleted file mode 100644 index a4eb654..0000000 --- a/Core/Commands/Info/ParcelName.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BetterSecondBot.Commands.Info -{ - public class ParcelName : ParcelCommand_CheckParcel_1arg_smart - { - public override string Helpfile { get { return "Fetchs the current parcels name and sends it to the smart reply target on [ARG 1]"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], targetparcel.Name, CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Info/SimName.cs b/Core/Commands/Info/SimName.cs deleted file mode 100644 index 3823bc0..0000000 --- a/Core/Commands/Info/SimName.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace BetterSecondBot.Commands.Info -{ - public class SimName : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Requests the current Sim Position and sends that via the smart reply target"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.GetClient.Network.CurrentSim.Name, CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Info/UnixTimeNow.cs b/Core/Commands/Info/UnixTimeNow.cs deleted file mode 100644 index 934eb6b..0000000 --- a/Core/Commands/Info/UnixTimeNow.cs +++ /dev/null @@ -1,17 +0,0 @@ -using BetterSecondBotShared.Static; - -namespace BetterSecondBot.Commands.Info -{ - public class UnixTimeNow : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Requests the current unixtime at the bot and sends that via the smart reply target"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], helpers.UnixTimeNow().ToString(), CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Self/CickObject.cs b/Core/Commands/Self/CickObject.cs deleted file mode 100644 index 286f6a4..0000000 --- a/Core/Commands/Self/CickObject.cs +++ /dev/null @@ -1,49 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; - - -namespace BetterSecondBot.Commands.Self -{ - public class ClickObject : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "UUID" }; } } - public override string[] ArgHints { get { return new[] { "Object UUID" }; } } - public override string Helpfile { get { return "Makes the bot attempt to click a object"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID ObjectUUID) == true) - { - Dictionary objectsentrys = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); - bool found_object = false; - foreach (KeyValuePair entry in objectsentrys) - { - if(entry.Value.ID == ObjectUUID) - { - bot.GetClient.Objects.ClickObject(bot.GetClient.Network.CurrentSim, entry.Key); - found_object = true; - break; - } - } - if(found_object == true) - { - return true; - } - else - { - return Failed("Unable to see object"); - } - } - else - { - return Failed("UUID not vaild"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Self/Help.cs b/Core/Commands/Self/Help.cs deleted file mode 100644 index 476bbb1..0000000 --- a/Core/Commands/Self/Help.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Self -{ - public class Help : CoreCommand - { - - public override string Helpfile { get { return "Basic list of commands"; } } - public override bool CallFunction(string[] args) - { - if (bot.getMaster_uuid != UUID.Zero) - { - - StringBuilder sb = new StringBuilder(); - sb.Append("Second Bot - Basic Command List\n\n"); - sb.Append(bot.GetCommandsInterface.GetCommandHelp("im")); - sb.Append("\n\n"); - sb.Append(bot.GetCommandsInterface.GetCommandHelp("say")); - sb.Append("\n\n"); - sb.Append(bot.GetCommandsInterface.GetCommandHelp("botsit")); - sb.Append("\n\n"); - sb.Append("\nType: 'morehelp' for a full list of commands\n"); - sb.Replace("
", "\n"); - bot.SendIM(bot.getMaster_uuid, sb.ToString()); - - return true; - } - else - { - return Failed("UUID is not vaild"); - } - } - } - public class MoreHelp : CoreCommand - { - - public override string Helpfile { get { return "Generates a notecard of all supported commands"; } } - public override bool CallFunction(string[] args) - { - if (bot.getMaster_uuid != UUID.Zero) - { - - - StringBuilder reply = new StringBuilder(); - reply.Append("Second Bot - Full Command List\n\n"); - foreach (string a in bot.GetCommandsInterface.GetCommandsList()) - { - reply.Append(a); - reply.Append("\n"); - reply.Append(bot.GetCommandsInterface.GetCommandHelp(a)); - reply.Append("\n\n"); - } - reply.Replace("
", "\n"); - reply.Replace("", ""); - reply.Replace("", "\n"); - reply.Replace("", "\n"); - reply.Replace("", ""); - reply.Replace("", ""); - reply.Replace("", ""); - reply.Replace("", ""); - reply.Replace("
", " "); - - bot.SendNotecard("SecondBot - All Commands", reply.ToString(), bot.getMaster_uuid); - - return true; - } - else - { - return Failed("UUID is not vaild"); - } - } - } -} diff --git a/Core/Commands/Self/PayObject.cs b/Core/Commands/Self/PayObject.cs deleted file mode 100644 index 8b49e4b..0000000 --- a/Core/Commands/Self/PayObject.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; - - -namespace BetterSecondBot.Commands.Self -{ - public class PayObject : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "UUID","Number","Text" }; } } - public override string[] ArgHints { get { return new[] { "Object UUID","Amount to pay","Object Name" }; } } - public override string Helpfile { get { return "Makes the bot pay a object"; } } - public override bool CallFunction(string[] args) - { - - if (base.CallFunction(args) == true) - { - if (bot.GetAllowFunds == true) - { - if (UUID.TryParse(args[0], out UUID objectuuid) == true) - { - if (int.TryParse(args[1], out int amount) == true) - { - if (amount > 0) - { - if (args[2].Length > 0) - { - bot.GetClient.Self.GiveObjectMoney(objectuuid, amount, args[2]); - return true; - } - return Failed("Invaild object name"); - } - } - return Failed("Invaild amount"); - } - return Failed("Invaild object UUID"); - } - return Failed("Transfer funds to objects disabled"); - } - return false; - } - } -} diff --git a/Core/Commands/Self/botVersion.cs b/Core/Commands/Self/botVersion.cs deleted file mode 100644 index d7993b0..0000000 --- a/Core/Commands/Self/botVersion.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace BetterSecondBot.Commands.Self -{ - class BotVersion : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Returns the bots build version"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], bot.MyVersion, CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Self/logout.cs b/Core/Commands/Self/logout.cs index 79973af..d80ec02 100644 --- a/Core/Commands/Self/logout.cs +++ b/Core/Commands/Self/logout.cs @@ -27,8 +27,7 @@ namespace BetterSecondBot.Commands.Self public override string Helpfile { get { return "Makes the bot kill itself you monster"; } } public override bool CallFunction(string[] args) { - bot.GetClient.Self.Chat("Laters im out", 0, ChatType.Normal); - bot.KillMePlease(); + return true; } } diff --git a/Core/Commands/Self/pointAt.cs b/Core/Commands/Self/pointAt.cs deleted file mode 100644 index 13b3444..0000000 --- a/Core/Commands/Self/pointAt.cs +++ /dev/null @@ -1,40 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Self -{ - public class PointAt : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]" }; } } - public override string Helpfile { get { return "Makes the bot turn to face [ARG 1] and point at them (if found)"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID testavatar) == true) - { - if (bot.GetClient.Network.CurrentSim.AvatarPositions.ContainsKey(testavatar) == true) - { - bot.ResetAnimations(); - bot.GetClient.Self.Stand(); - bot.GetClient.Self.Movement.TurnToward(bot.GetClient.Network.CurrentSim.AvatarPositions[testavatar]); - bot.GetClient.Self.Movement.SendUpdate(); - bot.GetClient.Self.AnimationStart(Animations.POINT_YOU, true); - bot.GetClient.Self.PointAtEffect(bot.GetClient.Self.AgentID, testavatar, new Vector3d(0, 0, 0), PointAtType.Select, UUID.Random()); - bot.GetClient.Self.BeamEffect(bot.GetClient.Self.AgentID, testavatar, new Vector3d(0, 0, 2), new Color4(255, 255, 255, 1), (float)3.0, UUID.Random()); - return true; - } - else - { - return Failed("Cant find UUID in sim"); - } - } - else - { - return Failed("UUID is not vaild"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Self/sit.cs b/Core/Commands/Self/sit.cs deleted file mode 100644 index 6239294..0000000 --- a/Core/Commands/Self/sit.cs +++ /dev/null @@ -1,37 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Self -{ - public class BotSit : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Mixed" }; } } - public override string[] ArgHints { get { return new[] { "Text \"ground\" or a object UUID" }; } } - public override string Helpfile { get { return "Makes the bot sit on the ground or on a object if it can see it
Example: BOTSIT|||" + UUID.Zero; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bot.ResetAnimations(); - bot.GetClient.Self.Stand(); - if (args[0] == "ground") - { - bot.GetClient.Self.SitOnGround(); - return true; - } - else - { - if (UUID.TryParse(args[0], out UUID arg_is_uuid) == true) - { - bot.GetClient.Self.RequestSit(arg_is_uuid, Vector3.Zero); - return true; - } - else - { - return Failed("UUID is not vaild"); - } - } - } - return false; - } - } -} diff --git a/Core/Commands/Self/stand.cs b/Core/Commands/Self/stand.cs deleted file mode 100644 index 8fe8a0d..0000000 --- a/Core/Commands/Self/stand.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace BetterSecondBot.Commands.Self -{ - public class Stand : CoreCommand - { - public override string Helpfile { get { return "Makes the bot stand up if sitting (also resets animations)"; } } - public override bool CallFunction(string[] args) - { - bot.GetClient.Self.Stand(); - bot.ResetAnimations(); - return true; - } - } -} \ No newline at end of file diff --git a/Core/bottypes/EventsBot.cs b/Core/bottypes/EventsBot.cs index 62668a4..1977b16 100644 --- a/Core/bottypes/EventsBot.cs +++ b/Core/bottypes/EventsBot.cs @@ -250,6 +250,15 @@ namespace BetterSecondBot.bottypes } + public List GetGroupMembers(UUID group) + { + if (group_members_storage.ContainsKey(group) == false) + { + return null; + } + return group_members_storage[group].Value; + } + public bool FastCheckInGroup(UUID group,UUID avatar) { if(NeedReloadGroupData(group) == false) From b70ef7c18655623046d44a9289fbff94a6a46fff Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Wed, 17 Feb 2021 13:25:27 +0000 Subject: [PATCH 3/5] Move http into core getting ready to replace the old commands system --- BetterSecondbot/BetterSecondbot.csproj | 1 - BetterSecondbot/HttpService/Parcel.cs | 50 -- BetterSecondbot/WikiMake/wikimake.cs | 10 +- Core/Commands/Movement/AutoPilot.cs | 56 -- Core/Commands/Movement/teleport.cs | 66 -- Core/Commands/Parcel/AbandonLand.cs | 17 - Core/Commands/Parcel/GetParcelBanlist.cs | 27 - Core/Commands/Parcel/GetParcelDesc.cs | 16 - Core/Commands/Parcel/GetParcelFlags.cs | 82 --- Core/Commands/Parcel/ParcelBan.cs | 91 --- Core/Commands/Parcel/ParcelBuy.cs | 33 - Core/Commands/Parcel/ParcelCleanAndSell.cs | 92 --- Core/Commands/Parcel/ParcelCommandHelper.cs | 99 --- Core/Commands/Parcel/ParcelDeedToGroup.cs | 22 - Core/Commands/Parcel/ParcelFreeze.cs | 35 - Core/Commands/Parcel/ParcelPrimCountAvatar.cs | 77 --- Core/Commands/Parcel/ParcelPrimCountTotal.cs | 51 -- Core/Commands/Parcel/ParcelReturnObjects.cs | 71 -- Core/Commands/Parcel/ParcelReturnTargeted.cs | 29 - Core/Commands/Parcel/ParcelSetMedia.cs | 170 ----- Core/Commands/Parcel/SetParcelDesc.cs | 20 - Core/Commands/Parcel/SetParcelFlag.cs | 89 --- Core/Commands/Parcel/SetParcelMusic.cs | 32 - Core/Commands/Parcel/SetParcelName.cs | 20 - Core/Commands/Parcel/SetParcelSale.cs | 56 -- Core/Commands/Parcel/eject.cs | 35 - Core/Commands/Prims/RezObject.cs | 47 -- .../Prims/TransferInventoryToObject.cs | 74 --- Core/Commands/Prims/UnRezObject.cs | 45 -- Core/Commands/Script/scriptHttp.cs | 85 --- Core/Commands/Script/scriptSend.cs | 45 -- Core/Commands/Self/GetLastCommands.cs | 24 - Core/Commands/Self/SetPermFlag.cs | 51 -- Core/Commands/Self/logout.cs | 34 - .../Commands/StreamAdmin/FetchNextNotecard.cs | 69 -- Core/Core.csproj | 1 + .../HttpService/Animation.cs | 4 +- .../HttpService/Avatars.cs | 0 {BetterSecondbot => Core}/HttpService/Chat.cs | 11 +- {BetterSecondbot => Core}/HttpService/Core.cs | 43 -- .../HttpService/Dialogs.cs | 0 .../HttpService/Discord.cs | 0 .../HttpService/Estate.cs | 4 +- .../HttpService/Friends.cs | 0 .../HttpService/Funds.cs | 0 .../HttpService/Group.cs | 4 +- {BetterSecondbot => Core}/HttpService/Home.cs | 4 +- .../HttpService/HttpAsService.cs | 29 +- {BetterSecondbot => Core}/HttpService/Im.cs | 0 {BetterSecondbot => Core}/HttpService/Info.cs | 4 +- .../HttpService/Inventory.cs | 83 ++- Core/HttpService/Movement.cs | 131 ++++ Core/HttpService/Parcel.cs | 620 ++++++++++++++++++ {BetterSecondbot => Core}/HttpService/Self.cs | 98 ++- Core/HttpService/StreamAdmin.cs | 90 +++ Shared/Staic/Helpers.cs | 11 + 56 files changed, 1070 insertions(+), 1888 deletions(-) delete mode 100644 BetterSecondbot/HttpService/Parcel.cs delete mode 100644 Core/Commands/Movement/AutoPilot.cs delete mode 100644 Core/Commands/Movement/teleport.cs delete mode 100644 Core/Commands/Parcel/AbandonLand.cs delete mode 100644 Core/Commands/Parcel/GetParcelBanlist.cs delete mode 100644 Core/Commands/Parcel/GetParcelDesc.cs delete mode 100644 Core/Commands/Parcel/GetParcelFlags.cs delete mode 100644 Core/Commands/Parcel/ParcelBan.cs delete mode 100644 Core/Commands/Parcel/ParcelBuy.cs delete mode 100644 Core/Commands/Parcel/ParcelCleanAndSell.cs delete mode 100644 Core/Commands/Parcel/ParcelCommandHelper.cs delete mode 100644 Core/Commands/Parcel/ParcelDeedToGroup.cs delete mode 100644 Core/Commands/Parcel/ParcelFreeze.cs delete mode 100644 Core/Commands/Parcel/ParcelPrimCountAvatar.cs delete mode 100644 Core/Commands/Parcel/ParcelPrimCountTotal.cs delete mode 100644 Core/Commands/Parcel/ParcelReturnObjects.cs delete mode 100644 Core/Commands/Parcel/ParcelReturnTargeted.cs delete mode 100644 Core/Commands/Parcel/ParcelSetMedia.cs delete mode 100644 Core/Commands/Parcel/SetParcelDesc.cs delete mode 100644 Core/Commands/Parcel/SetParcelFlag.cs delete mode 100644 Core/Commands/Parcel/SetParcelMusic.cs delete mode 100644 Core/Commands/Parcel/SetParcelName.cs delete mode 100644 Core/Commands/Parcel/SetParcelSale.cs delete mode 100644 Core/Commands/Parcel/eject.cs delete mode 100644 Core/Commands/Prims/RezObject.cs delete mode 100644 Core/Commands/Prims/TransferInventoryToObject.cs delete mode 100644 Core/Commands/Prims/UnRezObject.cs delete mode 100644 Core/Commands/Script/scriptHttp.cs delete mode 100644 Core/Commands/Script/scriptSend.cs delete mode 100644 Core/Commands/Self/GetLastCommands.cs delete mode 100644 Core/Commands/Self/SetPermFlag.cs delete mode 100644 Core/Commands/Self/logout.cs delete mode 100644 Core/Commands/StreamAdmin/FetchNextNotecard.cs rename {BetterSecondbot => Core}/HttpService/Animation.cs (91%) rename {BetterSecondbot => Core}/HttpService/Avatars.cs (100%) rename {BetterSecondbot => Core}/HttpService/Chat.cs (84%) rename {BetterSecondbot => Core}/HttpService/Core.cs (66%) rename {BetterSecondbot => Core}/HttpService/Dialogs.cs (100%) rename {BetterSecondbot => Core}/HttpService/Discord.cs (100%) rename {BetterSecondbot => Core}/HttpService/Estate.cs (95%) rename {BetterSecondbot => Core}/HttpService/Friends.cs (100%) rename {BetterSecondbot => Core}/HttpService/Funds.cs (100%) rename {BetterSecondbot => Core}/HttpService/Group.cs (96%) rename {BetterSecondbot => Core}/HttpService/Home.cs (84%) rename {BetterSecondbot => Core}/HttpService/HttpAsService.cs (89%) rename {BetterSecondbot => Core}/HttpService/Im.cs (100%) rename {BetterSecondbot => Core}/HttpService/Info.cs (94%) rename {BetterSecondbot => Core}/HttpService/Inventory.cs (62%) create mode 100644 Core/HttpService/Movement.cs create mode 100644 Core/HttpService/Parcel.cs rename {BetterSecondbot => Core}/HttpService/Self.cs (55%) create mode 100644 Core/HttpService/StreamAdmin.cs diff --git a/BetterSecondbot/BetterSecondbot.csproj b/BetterSecondbot/BetterSecondbot.csproj index ccc4cd3..b4c29db 100644 --- a/BetterSecondbot/BetterSecondbot.csproj +++ b/BetterSecondbot/BetterSecondbot.csproj @@ -25,7 +25,6 @@ - all diff --git a/BetterSecondbot/HttpService/Parcel.cs b/BetterSecondbot/HttpService/Parcel.cs deleted file mode 100644 index 0145e01..0000000 --- a/BetterSecondbot/HttpService/Parcel.cs +++ /dev/null @@ -1,50 +0,0 @@ -using BetterSecondBot.bottypes; -using BetterSecondBot.Static; -using EmbedIO; -using EmbedIO.Routing; -using EmbedIO.WebApi; -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; -using Newtonsoft.Json; -using static OpenMetaverse.ParcelManager; - -namespace BetterSecondBot.HttpService -{ - class HttpApiParcel : WebApiControllerWithTokens - { - public HttpApiParcel(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } - - [About("Fetchs the parcel ban list of the parcel the bot is currently on
If the name returned is lookup the bot is currently requesting the avatar name")] - [ReturnHints("array of UUID=Name")] - [ReturnHints("Error not in a sim")] - [ReturnHints("Parcel data not ready")] - [Route(HttpVerbs.Get, "/banlist/{token}")] - public object parcelbanlist(string token) - { - if (tokens.Allow(token, "parcel", "banlist", getClientIP()) == true) - { - if (bot.GetClient.Network.CurrentSim != null) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - Parcel targetparcel = null; - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - targetparcel = bot.GetClient.Network.CurrentSim.Parcels[localid]; - Dictionary reply = new Dictionary(); - foreach (ParcelAccessEntry e in targetparcel.AccessBlackList) - { - string name = bot.FindAvatarKey2Name(e.AgentID); - reply.Add(e.AgentID.ToString(), name); - } - return BasicReply(JsonConvert.SerializeObject(reply)); - } - return BasicReply("Parcel data not ready"); - } - return BasicReply("Error not in a sim"); - } - return BasicReply("Token not accepted"); - } - } -} diff --git a/BetterSecondbot/WikiMake/wikimake.cs b/BetterSecondbot/WikiMake/wikimake.cs index fcb9b60..832274c 100644 --- a/BetterSecondbot/WikiMake/wikimake.cs +++ b/BetterSecondbot/WikiMake/wikimake.cs @@ -554,12 +554,12 @@ namespace BetterSecondBot.WikiMake public HTTPendpoint() { createEndpoint("core", typeof(HttpApiCore)); - createEndpoint("inventory", typeof(HttpApiInventory)); + createEndpoint("inventory", typeof(HTTP_Inventory)); createEndpoint("im", typeof(HttpApiIM)); - createEndpoint("groups", typeof(HttpApiGroup)); - createEndpoint("chat", typeof(HttpApiLocalchat)); - createEndpoint("parcel", typeof(HttpApiParcel)); - createEndpoint("estate", typeof(HttpAPIEstate)); + createEndpoint("groups", typeof(HTTP_Group)); + createEndpoint("chat", typeof(HTTP_Chat)); + createEndpoint("parcel", typeof(HTTP_Parcel)); + createEndpoint("estate", typeof(HTTP_Estate)); } public string getCommandMethod(string endpoint, string command) diff --git a/Core/Commands/Movement/AutoPilot.cs b/Core/Commands/Movement/AutoPilot.cs deleted file mode 100644 index ca2a761..0000000 --- a/Core/Commands/Movement/AutoPilot.cs +++ /dev/null @@ -1,56 +0,0 @@ -using BetterSecondBotShared.Static; -using OpenMetaverse; -using System.Threading; - -namespace BetterSecondBot.Commands.Movement -{ - public class AutoPilot : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Vector" }; } } - public override string[] ArgHints { get { return new[] { "<0,0,0>" }; } } - public override string Helpfile { get { return "Make the bot auto pilot to
Example AutoPilot|||<124,55,22>"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (Vector3.TryParse(args[0], out Vector3 pos) == true) - { - if (helpers.inrange(pos.X, 0, 255) == true) - { - if (helpers.inrange(pos.Y, 0, 255) == true) - { - if (helpers.inrange(pos.Z, 0, 5000) == true) - { - bot.GetClient.Self.AutoPilotCancel(); - bot.GetClient.Self.Movement.TurnToward(pos, true); - Thread.Sleep(500); - uint Globalx, Globaly; - Utils.LongToUInts(bot.GetClient.Network.CurrentSim.Handle, out Globalx, out Globaly); - bot.GetClient.Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z); - return true; - } - else - { - return Failed("Z cord is out of range"); - } - } - else - { - return Failed("Y cord is out of range"); - } - } - else - { - return Failed("X cord is out of range"); - } - } - else - { - return Failed("Unable to process vector"); - } - } - return false; - } - } - -} diff --git a/Core/Commands/Movement/teleport.cs b/Core/Commands/Movement/teleport.cs deleted file mode 100644 index 7875e22..0000000 --- a/Core/Commands/Movement/teleport.cs +++ /dev/null @@ -1,66 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Movement -{ - public class Teleport : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Mixed" }; } } - public override string[] ArgHints { get { return new[] { "SLurl
Region
X/Y/Z
Region/X/Y/Z" }; } } - public override string Helpfile { get { return "Teleports the avatar
" + - "SLurl: http://maps.secondlife.com/secondlife/Bombalai/216/51/33
" + - "Region: Bombalai [Defaults to 128,128,0]
" + - "X/Y/Z: Stays in the sim just changes location
" + - "Region/X/Y/Z: Teleports to the given region and trys to goto X/Y/Z if no teleport hub (or has access)"; - } } - - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - bot.GetClient.Self.AutoPilotCancel(); - if (args[0].Contains("http://maps.secondlife.com/secondlife/") == true) - { - bot.TeleportWithSLurl(args[0]); - return true; - } - else - { - float posX = 128; - float posY = 128; - float posZ = 0; - string regionName = bot.GetClient.Network.CurrentSim.Name; - bool ok = true; - int offset = 0; - string[] tp_args = args[0].Split('/'); - if ((tp_args.Length == 4) || (tp_args.Length == 1)) - { - regionName = tp_args[0]; - offset = 1; - } - if (tp_args.Length >= 3) - { - float.TryParse(tp_args[offset + 0], out posX); - float.TryParse(tp_args[offset + 1], out posY); - float.TryParse(tp_args[offset + 2], out posZ); - } - else if (tp_args.Length == 2) - { - ok = false; - } - if (ok == true) - { - bot.SetTeleported(); - bool status = bot.GetClient.Self.Teleport(regionName, new Vector3(posX, posY, posZ)); - bot.ResetAnimations(); - return status; - } - else - { - return Failed("Required args [Region or x/y/z or region/x/y/z not sent]"); - } - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/AbandonLand.cs b/Core/Commands/Parcel/AbandonLand.cs deleted file mode 100644 index 6934361..0000000 --- a/Core/Commands/Parcel/AbandonLand.cs +++ /dev/null @@ -1,17 +0,0 @@ -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class AbandonLand : ParcelCommand_RequirePerms - { - public override string Helpfile { get { return "Abandons the parcel the bot is currently on, returning it to Linden's or Estate owner"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bot.GetClient.Parcels.ReleaseParcel(bot.GetClient.Network.CurrentSim, targetparcel.LocalID); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/GetParcelBanlist.cs b/Core/Commands/Parcel/GetParcelBanlist.cs deleted file mode 100644 index 660a83e..0000000 --- a/Core/Commands/Parcel/GetParcelBanlist.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using static OpenMetaverse.ParcelManager; - -namespace BetterSecondBot.Commands.Parcel -{ - class GetParcelBanlist : ParcelCommand_CheckParcel_1arg_smart - { - public override string Helpfile { get { return "Fetchs the current parcels banlist and sends it to the smart reply target on [ARG 1]"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - Dictionary reply = new Dictionary(); - foreach(ParcelAccessEntry e in targetparcel.AccessBlackList) - { - string name = bot.FindAvatarKey2Name(e.AgentID); - reply.Add(e.AgentID.ToString(), name); - } - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], targetparcel.Name, CommandName, reply); - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/GetParcelDesc.cs b/Core/Commands/Parcel/GetParcelDesc.cs deleted file mode 100644 index ece327b..0000000 --- a/Core/Commands/Parcel/GetParcelDesc.cs +++ /dev/null @@ -1,16 +0,0 @@ -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class GetParcelDesc : ParcelCommand_CheckParcel_1arg_smart - { - public override string Helpfile { get { return "Fetchs the current parcels desc and sends it to the smart reply target on [ARG 1]"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], targetparcel.Desc, CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/GetParcelFlags.cs b/Core/Commands/Parcel/GetParcelFlags.cs deleted file mode 100644 index 9405808..0000000 --- a/Core/Commands/Parcel/GetParcelFlags.cs +++ /dev/null @@ -1,82 +0,0 @@ -using System.Collections.Generic; -using System.Text; -using BetterSecondBotShared.logs; -using BetterSecondBotShared.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class GetParcelFlags : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "String" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply [Channel|Avatar|http url]", "[Repeatable] flag name" }; } } - public override string Helpfile { get { return "Returns the value of the parcel flags (At the parcel on the bot is currently on)
" + - "requested on [ARG 2+] via [ARG 1] smart reply target
" + - "If you request multiple Flags they are split with CSV
You can also get all the flags skipping [ARG 2]

" + - "" + helpers.create_dirty_table(parcel_static.get_flag_names()) + "

Example: getparcelflag|||0~#~ForSale
Example: getparcelflag|||12"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - Dictionary flags = parcel_static.get_flags_list(); - List get_flags = new List(); - List otherargs = new List(args); - string target = otherargs[0]; - otherargs.RemoveAt(0); - if (otherargs.Count == 0) - { - otherargs.Add("ALL"); - } - if (otherargs[0] == "ALL") - { - foreach (string A in flags.Keys) - { - get_flags.Add(A); - } - } - else - { - foreach (string a in otherargs) - { - if (flags.ContainsKey(a) == true) - { - get_flags.Add(a); - } - else - { - LogFormater.Warn("Flag: " + a + " is unknown"); - } - } - } - - if (get_flags.Count > 0) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid]; - Dictionary collection = new Dictionary(); - foreach (string cfg in get_flags) - { - if (flags.ContainsKey(cfg) == true) - { - collection.Add(cfg, p.Flags.HasFlag(flags[cfg]).ToString()); - } - } - return bot.GetCommandsInterface.SmartCommandReply(true,target, p.Name, CommandName, collection); - } - else - { - return Failed("Unable to find parcel in memory, please wait and try again"); - } - } - else - { - return Failed("No accepted flags"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelBan.cs b/Core/Commands/Parcel/ParcelBan.cs deleted file mode 100644 index 40e036f..0000000 --- a/Core/Commands/Parcel/ParcelBan.cs +++ /dev/null @@ -1,91 +0,0 @@ -using OpenMetaverse; -using static OpenMetaverse.ParcelManager; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class ParcelBan : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Type" }; } } - public override string Helpfile { get { return "Bans an avatar [ARG 1] from a parcel
by setting Type to False you can unban"; } } - - protected bool ban_target(OpenMetaverse.Parcel p, UUID target) - { - bool alreadyBanned = false; - foreach (ParcelAccessEntry E in p.AccessBlackList) - { - if (E.AgentID == target) - { - alreadyBanned = true; - break; - } - } - if (alreadyBanned == true) - { - return Failed("Target is in the blacklist"); - } - ParcelAccessEntry entry = new ParcelAccessEntry(); - entry.AgentID = target; - entry.Flags = AccessList.Ban; - entry.Time = new System.DateTime(3030, 03, 03); - p.AccessBlackList.Add(entry); - p.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - - protected bool unban_target(OpenMetaverse.Parcel p, UUID target) - { - bool alreadyBanned = false; - ParcelAccessEntry removeme = new ParcelAccessEntry(); - foreach (ParcelAccessEntry E in p.AccessBlackList) - { - if (E.AgentID == target) - { - alreadyBanned = true; - removeme = E; - break; - } - } - if (alreadyBanned == false) - { - return Failed("Target is NOT in the blacklist"); - } - p.AccessBlackList.Remove(removeme); - p.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - - - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == false) - { - return false; - } - if (UUID.TryParse(args[0], out UUID target) == false) - { - return Failed("Arg 0 requires UUID"); - } - bool banuser = true; - if (args.Length == 2) - { - if (args[1] == "False") - { - banuser = false; - } - } - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == false) - { - return Failed("Unable to get parcel details"); - } - OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid]; - if (banuser == true) - { - return ban_target(p, target); - } - return unban_target(p, target); - } - } -} diff --git a/Core/Commands/Parcel/ParcelBuy.cs b/Core/Commands/Parcel/ParcelBuy.cs deleted file mode 100644 index 666df1d..0000000 --- a/Core/Commands/Parcel/ParcelBuy.cs +++ /dev/null @@ -1,33 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class ParcelBuy : ParcelCommand_CheckParcel - { - public override string[] ArgTypes { get { return new[] { "Number" }; } } - public override string[] ArgHints { get { return new[] { "expected price to pay" }; } } - public override string Helpfile { get { return "Attempts to buy the parcel the bot is standing on, note: if no price expected price is set it will pay the listed price"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int expected_price = -1; - if (args.Length == 1) - { - int.TryParse(args[0], out expected_price); - } - if ((targetparcel.SalePrice == expected_price) || (expected_price == -1)) - { - bot.GetClient.Parcels.Buy(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, false, UUID.Zero, false, targetparcel.Area, targetparcel.SalePrice); - return true; - } - else - { - return Failed("Expected price is not -1 or matchs: " + expected_price.ToString() + ""); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelCleanAndSell.cs b/Core/Commands/Parcel/ParcelCleanAndSell.cs deleted file mode 100644 index a116ec4..0000000 --- a/Core/Commands/Parcel/ParcelCleanAndSell.cs +++ /dev/null @@ -1,92 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Threading; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class ParcelCleanAndSell : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "Number" }; } } - public override string[] ArgHints { get { return new[] { "L$ amount to mark the parcel for sale as" }; } } - - public override string Helpfile { get { return "Sets the current parcel for sale for L$[ARG 1] (Also marks the parcel for sale)"; } } - - public override void Callback(string[] args, EventArgs e) - { - if (base.CallFunction(args) == true) - { - ParcelObjectOwnersReplyEventArgs ObjectOwners = (ParcelObjectOwnersReplyEventArgs)e; - List owner_uuids = new List(); - foreach (ParcelManager.ParcelPrimOwners owner in ObjectOwners.PrimOwners) - { - owner_uuids.Add(owner.OwnerID); - } - if (owner_uuids.Count > 0) - { - bot.GetClient.Parcels.ReturnObjects(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.List, owner_uuids); - } - int.TryParse(args[0], out int price); - bot.GetClient.Parcels.ReleaseParcel(bot.GetClient.Network.CurrentSim, targetparcel.LocalID); - targetparcel.SalePrice = price; - targetparcel.AuthBuyerID = UUID.Zero; - targetparcel.OwnerID = UUID.Zero; - parcel_static.ParcelSetFlag(ParcelFlags.ForSale, targetparcel, true); - parcel_static.ParcelSetFlag(ParcelFlags.ForSaleObjects, targetparcel, false); - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - base.Callback(args, e, true); - } - else - { - base.Callback(args, e, false); - } - } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (int.TryParse(args[0], out int price) == true) - { - if (price >= 1) - { - if (price <= 99999) - { - bot.GetClient.Parcels.ReleaseParcel(bot.GetClient.Network.CurrentSim, targetparcel.LocalID); - targetparcel.AuthBuyerID = bot.GetClient.Self.AgentID; - targetparcel.SalePrice = 0; - parcel_static.ParcelSetFlag(ParcelFlags.ForSale, targetparcel, true); - parcel_static.ParcelSetFlag(ParcelFlags.ForSaleObjects, targetparcel, false); - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - Thread.Sleep(200); - bot.GetClient.Parcels.Buy(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, false, UUID.Zero, false, targetparcel.Area, 0); - Thread.Sleep(1000); - if (bot.CreateAwaitEventReply("parcelobjectowners", this, args) == true) - { - bot.GetClient.Parcels.RequestObjectOwners(bot.GetClient.Network.CurrentSim, targetparcel.LocalID); - return true; - } - else - { - return Failed("Unable to send request for parcel object owners"); - } - } - else - { - return Failed("Price must be 99999 or less"); - } - } - else - { - return Failed("Price must be 1 or more"); - } - } - else - { - return Failed("Unable to process price"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelCommandHelper.cs b/Core/Commands/Parcel/ParcelCommandHelper.cs deleted file mode 100644 index 5d68f47..0000000 --- a/Core/Commands/Parcel/ParcelCommandHelper.cs +++ /dev/null @@ -1,99 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands -{ - public abstract class ParcelCommand_RequirePerms_1arg_Group : ParcelCommand_RequirePerms_1arg - { - protected UUID groupuuid = UUID.Zero; - public override string[] ArgTypes { get { return new[] { "UUID" }; } } - public override string[] ArgHints { get { return new[] { "Group UUID" }; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out groupuuid) == true) - { - return true; - } - else - { - return Failed("Unable to process group uuid"); - } - } - else - { - return false; - } - } - } - - public abstract class ParcelCommand_RequirePerms_1arg : ParcelCommand_RequirePerms - { - public override int Min_Required_args { get { return 1; } } - } - - public abstract class ParcelCommand_CheckParcel_1arg : ParcelCommand_CheckParcel - { - public override int Min_Required_args { get { return 1; } } - } - - public abstract class ParcelCommand_RequirePerms : ParcelCommand_CheckParcel - { - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (targetparcel != null) - { - if (parcel_static.has_parcel_perm(targetparcel, bot) == true) - { - return true; - } - else - { - return Failed("Incorrect perms to control parcel"); - } - } - else - { - return Failed("No parcel targeted."); - } - } - else - { - return false; - } - } - } - public abstract class ParcelCommand_CheckParcel_1arg_smart : ParcelCommand_CheckParcel_1arg - { - public override string[] ArgTypes { get { return new[] { "Smart" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply [Channel|Avatar|http url]" }; } } - } - - public abstract class ParcelCommand_CheckParcel : CoreCommand - { - protected OpenMetaverse.Parcel targetparcel; - public OpenMetaverse.Parcel GetTargetParcel { get { return targetparcel; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - targetparcel = bot.GetClient.Network.CurrentSim.Parcels[localid]; - return true; - } - else - { - return Failed("Unable to find parcel in memory, please wait and try again"); - } - } - else - { - return false; - } - } - } -} diff --git a/Core/Commands/Parcel/ParcelDeedToGroup.cs b/Core/Commands/Parcel/ParcelDeedToGroup.cs deleted file mode 100644 index b9894bc..0000000 --- a/Core/Commands/Parcel/ParcelDeedToGroup.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Threading; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class ParcelDeedToGroup : ParcelCommand_RequirePerms_1arg_Group - { - public override string Helpfile { get { return "transfers the current parcel ownership to a group"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - targetparcel.GroupID = groupuuid; - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - Thread.Sleep(1000); - bot.GetClient.Parcels.DeedToGroup(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, groupuuid); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelFreeze.cs b/Core/Commands/Parcel/ParcelFreeze.cs deleted file mode 100644 index 13ad8e1..0000000 --- a/Core/Commands/Parcel/ParcelFreeze.cs +++ /dev/null @@ -1,35 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class ParcelFreeze : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Status (defaults to True)" }; } } - public override string Helpfile { get { return "Freezes an avatar [ARG 1]
Set to False to unfreeze"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target) == true) - { - bool freezethem = true; - if (args.Length == 2) - { - if (args[1] == "False") - { - freezethem = false; - } - } - bot.GetClient.Parcels.FreezeUser(target, freezethem); - return true; - } - else - { - return Failed("Arg 0 requires UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelPrimCountAvatar.cs b/Core/Commands/Parcel/ParcelPrimCountAvatar.cs deleted file mode 100644 index 7ee79ce..0000000 --- a/Core/Commands/Parcel/ParcelPrimCountAvatar.cs +++ /dev/null @@ -1,77 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class ParcelPrimCountAvatar : CoreCommand_SmartReply_2arg - { - public override string[] ArgTypes { get { return new[] { "Smart","Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP url","the avatar (UUID or Firstname Lastname) we want the count of back" }; } } - public override string Helpfile { get { return "Returns the number of prims owned by the selected avatar on the current parcel as follows: DATA=SIMNAME,PARCELID,AVATAR UUID,COUNT"; } } - - public override void Callback(string[] args, EventArgs e) - { - ParcelObjectOwnersReplyEventArgs ObjectOwners = (ParcelObjectOwnersReplyEventArgs)e; - List owner_uuids = new List(); - List owner_counts = new List(); - foreach (ParcelManager.ParcelPrimOwners owner in ObjectOwners.PrimOwners) - { - owner_uuids.Add(owner.OwnerID); - owner_counts.Add(owner.Count); - } - if (owner_uuids.Count > 0) - { - if (UUID.TryParse(args[1], out UUID avatar) == true) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - collection.Add("sim", bot.GetClient.Network.CurrentSim.Name); - if (owner_uuids.Contains(avatar) == true) - { - int owner_count = owner_counts[owner_uuids.IndexOf(avatar)]; - collection.Add("count", owner_count.ToString()); - } - else - { - collection.Add("count", "0"); - } - base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(true,args[0], "avatar="+ avatar.ToString(), CommandName,collection)); - } - else - { - base.Callback(args, e, false); - } - } - else - { - base.Callback(args, e, false); - } - } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[1], out _) == true) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.CreateAwaitEventReply("parcelobjectowners", this, args) == true) - { - bot.GetClient.Parcels.RequestObjectOwners(bot.GetClient.Network.CurrentSim, localid); - return true; - } - else - { - return Failed("Unable to await reply"); - } - } - else - { - return Failed("Arg 2 is not a vaild avatar"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelPrimCountTotal.cs b/Core/Commands/Parcel/ParcelPrimCountTotal.cs deleted file mode 100644 index d41c5f8..0000000 --- a/Core/Commands/Parcel/ParcelPrimCountTotal.cs +++ /dev/null @@ -1,51 +0,0 @@ -using OpenMetaverse; -using System; -using System.Text; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class ParcelPrimCountTotal : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Returns the total number of prims on the current parcel as follows: DATA=SIMNAME,PARCELID,COUNT"; } } - - public override void Callback(string[] args, EventArgs e) - { - ParcelObjectOwnersReplyEventArgs ObjectOwners = (ParcelObjectOwnersReplyEventArgs)e; - int total_count = 0; - foreach (ParcelManager.ParcelPrimOwners owner in ObjectOwners.PrimOwners) - { - total_count += owner.Count; - } - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - collection.Add("sim", bot.GetClient.Network.CurrentSim.Name); - collection.Add("parcelid", localid.ToString()); - collection.Add("count", total_count.ToString()); - base.Callback(args, e, bot.GetCommandsInterface.SmartCommandReply(true,args[0], "ok", CommandName,collection)); - } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - if (bot.CreateAwaitEventReply("parcelobjectowners", this, args) == true) - { - bot.GetClient.Parcels.RequestObjectOwners(bot.GetClient.Network.CurrentSim, localid); - return true; - } - else - { - return Failed("Unable to await reply"); - } - } - else - { - return Failed("Unable to find parcel in memory, please wait and try again"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelReturnObjects.cs b/Core/Commands/Parcel/ParcelReturnObjects.cs deleted file mode 100644 index 9eff62b..0000000 --- a/Core/Commands/Parcel/ParcelReturnObjects.cs +++ /dev/null @@ -1,71 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class ParcelReturnObjects : CoreCommand - { - public override string Helpfile { get { return "Returns all object from the current parcel to their owners"; } } - - public override void Callback(string[] args, EventArgs e) - { - ParcelObjectOwnersReplyEventArgs ObjectOwners = (ParcelObjectOwnersReplyEventArgs)e; - List owner_uuids = new List(); - foreach(ParcelManager.ParcelPrimOwners owner in ObjectOwners.PrimOwners) - { - owner_uuids.Add(owner.OwnerID); - } - if (owner_uuids.Count > 0) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid]; - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - if (parcel_static.has_parcel_perm(p, bot) == true) - { - bot.GetClient.Parcels.ReturnObjects(bot.GetClient.Network.CurrentSim, localid, ObjectReturnType.List, owner_uuids); - base.Callback(args, e, true); - } - else - { - base.Callback(args, e, false); - } - } - else - { - base.Callback(args, e, false); - } - } - else - { - base.Callback(args, e, false); - } - } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - if (bot.CreateAwaitEventReply("parcelobjectowners", this, args) == true) - { - bot.GetClient.Parcels.RequestObjectOwners(bot.GetClient.Network.CurrentSim, localid); - return true; - } - else - { - return Failed("Unable to await reply"); - } - } - else - { - return Failed("Unable to find parcel in memory, please wait and try again"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelReturnTargeted.cs b/Core/Commands/Parcel/ParcelReturnTargeted.cs deleted file mode 100644 index 0dcbe2d..0000000 --- a/Core/Commands/Parcel/ParcelReturnTargeted.cs +++ /dev/null @@ -1,29 +0,0 @@ -using OpenMetaverse; -using System.Collections.Generic; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class ParcelReturnTargeted : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]" }; } } - public override string Helpfile { get { return "Returns all objects from the current parcel for the selected avatar"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID avatarUUID) == true) - { - bot.GetClient.Parcels.ReturnObjects(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.None, new List() { avatarUUID }); - return true; - } - else - { - return Failed("Invaild avatar UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/ParcelSetMedia.cs b/Core/Commands/Parcel/ParcelSetMedia.cs deleted file mode 100644 index 46e9d55..0000000 --- a/Core/Commands/Parcel/ParcelSetMedia.cs +++ /dev/null @@ -1,170 +0,0 @@ -using BetterSecondBotShared.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class ParcelSetMedia : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "Flag [Repeatable]" }; } } - public override string[] ArgHints { get { return new[] { "See flags table" }; } } - public override string Helpfile { get { return "Supports updating one or multiple media options for the current parcel
Example: ParcelSetMedia|||MediaURL=http://google.com~#~MediaDesc=Google.com website
Flags: " + helpers.create_dirty_table(parcel_static.get_flag_names()) + "
"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bool all_flags_ok = true; - string why_failed = ""; - int loop = 1; - foreach (string A in args) - { - bool format_failed = false; - string[] bits = A.Split('='); - if (bits.Length == 2) - { - switch (bits[0]) - { - case "MediaType": - { - if (bits[1] == "IMG-PNG") - { - targetparcel.Media.MediaType = "image/png"; - } - else if (bits[1] == "IMG-JPG") - { - targetparcel.Media.MediaType = "image/jpeg"; - } - else if (bits[1] == "VID-MP4") - { - targetparcel.Media.MediaType = "video/mp4"; - } - else if (bits[1] == "VID-AVI") - { - targetparcel.Media.MediaType = "video/x-msvideo"; - } - else if (bits[1].StartsWith("Custom-") == true) - { - string mime = bits[1]; - mime = mime.Replace("Custom-", ""); - targetparcel.Media.MediaType = mime; - } - else - { - format_failed = true; - } - break; - } - case "MediaWidth": - case "MediaHeight": - { - if (int.TryParse(bits[1], out int size) == true) - { - if ((size >= 256) || (size <= 1024)) - { - if (bits[0] == "MediaHeight") - { - targetparcel.Media.MediaHeight = size; - } - else if (bits[0] == "MediaWidth") - { - targetparcel.Media.MediaWidth = size; - } - else - { - format_failed = true; // not sure how this happened - } - } - else - { - format_failed = true; - } - } - else - { - format_failed = true; - } - break; - } - case "MediaID": - { - if (UUID.TryParse(bits[1], out UUID texture) == true) - { - targetparcel.Media.MediaID = texture; - } - else - { - format_failed = true; - } - break; - } - case "MediaURL": - { - targetparcel.Media.MediaURL = bits[1]; - break; - } - case "MediaDesc": - { - targetparcel.Media.MediaDesc = bits[1]; - break; - } - case "MediaAutoScale": - { - if (bool.TryParse(bits[1], out bool output) == true) - { - targetparcel.Media.MediaAutoScale = output; - } - else - { - format_failed = true; - } - break; - } - case "MediaLoop": - { - if (bool.TryParse(bits[1], out bool output) == true) - { - targetparcel.Media.MediaLoop = output; - } - else - { - format_failed = true; - } - break; - } - default: - { - why_failed = "Arg:" + loop.ToString() + " is not a supported media option!"; - all_flags_ok = false; - break; - } - } - } - else - { - format_failed = true; - } - if (format_failed == true) - { - why_failed = "Arg:" + loop.ToString() + " Not formated correctly"; - all_flags_ok = false; - } - if (all_flags_ok == false) - { - break; - } - loop++; - } - if (all_flags_ok == true) - { - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - else - { - return Failed(why_failed); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/SetParcelDesc.cs b/Core/Commands/Parcel/SetParcelDesc.cs deleted file mode 100644 index 3788caa..0000000 --- a/Core/Commands/Parcel/SetParcelDesc.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class SetParcelDesc : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "String" }; } } - public override string[] ArgHints { get { return new[] { "The new desc" }; } } - public override string Helpfile { get { return "Updates the current parcels desc"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - targetparcel.Desc = args[0]; - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/SetParcelFlag.cs b/Core/Commands/Parcel/SetParcelFlag.cs deleted file mode 100644 index f772987..0000000 --- a/Core/Commands/Parcel/SetParcelFlag.cs +++ /dev/null @@ -1,89 +0,0 @@ -using System; -using System.Collections.Generic; -using BetterSecondBotShared.logs; -using BetterSecondBotShared.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class SetParcelFlag : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "Text=True|False" }; } } - public override string[] ArgHints { get { return new[] { "[Repeatable] flag args" }; } } - - public override string Helpfile { get { return "Sets the parcel flags of the parcel the bot is currently standing on
" + - "Example:AllowFly=False~#~AllowDamage=True
" + helpers.create_dirty_table(parcel_static.get_flag_names()) +"
"; } } - - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - List acceptablewords = new List(); - Dictionary flags = parcel_static.get_flags_list(); - acceptablewords.AddRange(new[] { "True", "False" }); - - Dictionary setflags = new Dictionary(); - foreach (string a in args) - { - string[] parts = a.Split('=',StringSplitOptions.RemoveEmptyEntries); - if (parts.Length == 2) - { - if (flags.ContainsKey(parts[0]) == true) - { - if (acceptablewords.Contains(parts[1])) - { - setflags.Add(parts[0], Convert.ToBoolean(parts[1])); - } - else - { - LogFormater.Crit("Unable to set flag " + parts[0] + " to : " + parts[1] + ""); - } - } - else - { - LogFormater.Warn("Flag: " + parts[0] + " is unknown"); - } - } - else - { - LogFormater.Warn("Flag: " + a + " missing = True|False"); - } - } - if (setflags.Count > 0) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - OpenMetaverse.Parcel p = bot.GetClient.Network.CurrentSim.Parcels[localid]; - if (parcel_static.has_parcel_perm(p, bot) == true) - { - foreach (KeyValuePair cfg in setflags) - { - if (flags.ContainsKey(cfg.Key) == true) - { - parcel_static.ParcelSetFlag(flags[cfg.Key], p, cfg.Value); - } - } - p.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - else - { - return Failed("Incorrect perms to control parcel"); - } - } - else - { - return Failed("Unable to find parcel in memory, please wait and try again"); - } - } - else - { - return Failed("No accepted flags"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/SetParcelMusic.cs b/Core/Commands/Parcel/SetParcelMusic.cs deleted file mode 100644 index 849d55a..0000000 --- a/Core/Commands/Parcel/SetParcelMusic.cs +++ /dev/null @@ -1,32 +0,0 @@ -namespace BetterSecondBot.Commands.CMD_Parcel -{ - class SetParcelMusic : ParcelCommand_RequirePerms - { - public override string[] ArgTypes { get { return new[] { "String" }; } } - public override string[] ArgHints { get { return new[] { "A vaild url" }; } } - public override string Helpfile { get { return "Updates the current parcels music url"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (args.Length == 0) - { - return parcel_static.set_parcel_music(bot,targetparcel,""); - } - else - { - if (args[0].StartsWith("http") == true) - { - return parcel_static.set_parcel_music(bot, targetparcel, args[0]); - } - else - { - return Failed("Invaild url"); - } - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/SetParcelName.cs b/Core/Commands/Parcel/SetParcelName.cs deleted file mode 100644 index 614c045..0000000 --- a/Core/Commands/Parcel/SetParcelName.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class SetParcelName : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "String" }; } } - public override string[] ArgHints { get { return new[] { "The new name" }; } } - public override string Helpfile { get { return "Updates the current parcels name"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - targetparcel.Name = args[0]; - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/SetParcelSale.cs b/Core/Commands/Parcel/SetParcelSale.cs deleted file mode 100644 index dfd0402..0000000 --- a/Core/Commands/Parcel/SetParcelSale.cs +++ /dev/null @@ -1,56 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class SetParcelSale : ParcelCommand_RequirePerms_1arg - { - public override string[] ArgTypes { get { return new[] { "Number","Avatar" }; } } - public override string[] ArgHints { get { return new[] { "L$ amount to mark the parcel for sale as (Range: 1 to 99999 unless [ARG 2] is set)", "Avatar who can buy the land (If set allows you to set the sell price to zero)" }; } } - - public override string Helpfile { get { return "Sets the current parcel for sale for L$[ARG 1] (Also marks the parcel for sale)"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (int.TryParse(args[0], out int price) == true) - { - UUID target_buyer = UUID.Zero; - int low_limit = 1; - if (args.Length == 2) - { - if (UUID.TryParse(args[1], out target_buyer) == true) - { - low_limit = 0; - } - } - if (price >= low_limit) - { - if (price <= 99999) - { - targetparcel.SalePrice = price; - targetparcel.AuthBuyerID = target_buyer; - parcel_static.ParcelSetFlag(ParcelFlags.ForSale, targetparcel, true); - parcel_static.ParcelSetFlag(ParcelFlags.ForSaleObjects, targetparcel, false); - targetparcel.Update(bot.GetClient.Network.CurrentSim, false); - return true; - } - else - { - return Failed("Price must be 99999 or less"); - } - } - else - { - return Failed("Price must be " + low_limit.ToString() + " or more"); - } - } - else - { - return Failed("Unable to process price"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Parcel/eject.cs b/Core/Commands/Parcel/eject.cs deleted file mode 100644 index 86ca5b9..0000000 --- a/Core/Commands/Parcel/eject.cs +++ /dev/null @@ -1,35 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.CMD_Parcel -{ - public class ParcelEject : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Also Ban" }; } } - public override string Helpfile { get { return "Ejects an avatar [ARG 1] from a parcel
You can also ban them at the same time if you wish"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID target) == true) - { - bool banuser = false; - if (args.Length == 2) - { - if (args[1] == "True") - { - banuser = true; - } - } - bot.GetClient.Parcels.EjectUser(target, banuser); - return true; - } - else - { - return Failed("Arg 0 requires UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Prims/RezObject.cs b/Core/Commands/Prims/RezObject.cs deleted file mode 100644 index b42fec7..0000000 --- a/Core/Commands/Prims/RezObject.cs +++ /dev/null @@ -1,47 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.Prims -{ - class RezObject : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "Vector" }; } } - public override string[] ArgHints { get { return new[] { "The object to rez", "The location to rez at: Example \"<123,32,18>\"" }; } } - public override string Helpfile { get { return "Rez a object [ARG 1] from inventory at [ARG 2] (Or current pos if not given)"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetitem) == true) - { - InventoryItem itm = bot.GetClient.Inventory.FetchItem(targetitem, bot.GetClient.Self.AgentID, (5 * 1000)); - if (itm != null) - { - Vector3 pos = bot.GetClient.Self.RelativePosition; - if (args.Length == 2) - { - if(Vector3.TryParse(args[1], out pos) == false) - { - return Failed("Unable to process pos"); - } - } - bot.GetClient.Inventory.RequestRezFromInventory(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimRotation, pos, itm); - return true; - } - else - { - return Failed("Unable to find item"); - } - } - else - { - return Failed("Invaild item UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Prims/TransferInventoryToObject.cs b/Core/Commands/Prims/TransferInventoryToObject.cs deleted file mode 100644 index 74c3594..0000000 --- a/Core/Commands/Prims/TransferInventoryToObject.cs +++ /dev/null @@ -1,74 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.Prims -{ - class TransferInventoryToObject : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "UUID", "UUID","True" }; } } - public override string[] ArgHints { get { return new[] { "Object we are sending to", "The item we are sending","Running script (Optional)" }; } } - public override string Helpfile { get { return "Transfers a item [ARG 2] to a objects inventory [ARG 1] (And if set with the script running state [ARG 3])"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[1], out UUID targetitem) == true) - { - if (UUID.TryParse(args[0], out UUID targetobject) == true) - { - InventoryItem itm = bot.GetClient.Inventory.FetchItem(targetitem, bot.GetClient.Self.AgentID, (5 * 1000)); - if (itm != null) - { - Dictionary objects_copy = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); - bool found = false; - foreach (KeyValuePair Obj in objects_copy) - { - if (Obj.Value.ID == targetobject) - { - bool script_state = false; - if (args.Length == 3) - { - if (itm.AssetType != AssetType.LSLText) - { - script_state = false; - InfoBlob = "Please omit the 3rd arg if not sending a script!"; - } - else - { - if (bool.TryParse(args[2], out script_state) == false) - { - return Failed("Unable to process arg 3"); - } - } - } - if (script_state == false) - { - bot.GetClient.Inventory.UpdateTaskInventory(Obj.Key, itm); - } - else - { - bot.GetClient.Inventory.CopyScriptToTask(Obj.Key, itm, true); - } - found = true; - break; - } - } - if (found == false) - { - return true; - } - return Failed("Unable to see object (Please wait and try again)"); - } - return Failed("Unable to find item"); - } - return Failed("Invaild object UUID"); - } - return Failed("Invaild item UUID"); - } - return false; - } - } -} diff --git a/Core/Commands/Prims/UnRezObject.cs b/Core/Commands/Prims/UnRezObject.cs deleted file mode 100644 index f6b0edd..0000000 --- a/Core/Commands/Prims/UnRezObject.cs +++ /dev/null @@ -1,45 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Text; - -namespace BetterSecondBot.Commands.Prims -{ - class UnRezObject : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "UUID" }; } } - public override string[] ArgHints { get { return new[] { "The object to unrez"}; } } - public override string Helpfile { get { return "Returns a rezzed object"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetobject) == true) - { - bool found = false; - Dictionary objects_copy = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); - foreach (KeyValuePair Obj in objects_copy) - { - if (Obj.Value.ID == targetobject) - { - bot.GetClient.Inventory.RequestDeRezToInventory(Obj.Key); - found = true; - break; - } - } - if(found == true) - { - return true; - } - return Failed("Unable to see object"); - } - else - { - return Failed("Invaild object UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Script/scriptHttp.cs b/Core/Commands/Script/scriptHttp.cs deleted file mode 100644 index 98ce28d..0000000 --- a/Core/Commands/Script/scriptHttp.cs +++ /dev/null @@ -1,85 +0,0 @@ -using System; -using System.Linq; -using OpenMetaverse; -using RestSharp; - -namespace BetterSecondBot.Commands.Script -{ - public class ScriptHttp : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "TEXT", "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "File endpoint", "Avatar Name/UUID to recive script" }; } } - public override string Helpfile { get { return "[StreamAdmin]\nThis command is part of the streamadmin commands set\n No end user support will be given."; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - string attempt_endpoint = args[0]; - - Uri uriResult; - bool urlValid = Uri.TryCreate(attempt_endpoint, UriKind.Absolute, out uriResult) - && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); - if(urlValid == false) - { - return Failed("Url >" + attempt_endpoint + "< is not a valid URL"); - } - if (attempt_endpoint.Contains("https://github.com/")) - { - attempt_endpoint = attempt_endpoint.Replace("https://github.com/", "https://raw.githubusercontent.com/"); - } - - var client = new RestClient(attempt_endpoint); - var request = new RestRequest("", Method.GET); - request.AddHeader("content-type", "application/x-www-form-urlencoded"); - IRestResponse endpoint_checks = client.Get(request); - if (endpoint_checks.StatusCode == System.Net.HttpStatusCode.OK) - { - try - { - if (endpoint_checks.IsSuccessful == true) - { - if (endpoint_checks.Content.Length > 3) - { - if (UUID.TryParse(args[1], out UUID Avatar)) - { - return bot.SendScript(attempt_endpoint.Split('/').LastOrDefault().Replace("%20", " "), endpoint_checks.Content, Avatar); - } - else - { - Failed("Avatar UUID not valid"); - } - } - else - { - Failed("script title is to short"); - } - } - return Failed(endpoint_checks.ErrorMessage); - } - catch (Exception e) - { - return Failed("Error: " + e.Message + ""); - } - } - else - { - return Failed("HTTP error DataObject broken Status:" + endpoint_checks.StatusCode.ToString() + " @ " + attempt_endpoint + ""); - } - } - return false; - } - } - - public class scriptendpoint : endpoint - { - public string AvatarUUID { get; set; } - public string scriptTitle { get; set; } - public string scriptContent { get; set; } - } - - public class endpoint - { - public bool status { get; set; } - public string message { get; set; } - } -} diff --git a/Core/Commands/Script/scriptSend.cs b/Core/Commands/Script/scriptSend.cs deleted file mode 100644 index 39bc488..0000000 --- a/Core/Commands/Script/scriptSend.cs +++ /dev/null @@ -1,45 +0,0 @@ -using BetterSecondBotShared.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Script -{ - class ScriptSend : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar","Text","Text" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Collection","Script name" }; } } - public override string Helpfile { get { return "Creats and send a Script to [ARG 1]
" + - " using the collection [ARG 2] as the content
" + - " Optional: You can name the Script using [ARG 3]"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - // target UUID,Script storage id,["Script title" or defaults to: New Script for ] - if (UUID.TryParse(args[0], out UUID target) == true) - { - string content = bot.GetScriptContent(args[1]); - if (content != null) - { - bot.ClearScriptStorage(args[1]); - string Script_name = "New Script for " + args[0] + " " + helpers.UnixTimeNow().ToString() + ""; - if (args.Length == 3) - { - Script_name = args[2] + " " + helpers.UnixTimeNow().ToString() + ""; - } - return bot.SendScript(Script_name, content, target); - } - else - { - return Failed("No content in Script storage " + args[1]); - } - } - else - { - return Failed("Arg 0 not a UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Self/GetLastCommands.cs b/Core/Commands/Self/GetLastCommands.cs deleted file mode 100644 index f19b51c..0000000 --- a/Core/Commands/Self/GetLastCommands.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System; - -namespace BetterSecondBot.Commands.Self -{ - public class GetLastCommands : CoreCommand_SmartReply_1arg - { - public override string Helpfile { get { return "Gets the last 5 commands issued to the bot and returns them via the smart target"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int entry = 1; - foreach(string a in bot.GetLastCommands(5)) - { - collection.Add(entry.ToString(), a); - entry++; - } - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], "last=5", CommandName,collection); - } - return false; - } - } -} diff --git a/Core/Commands/Self/SetPermFlag.cs b/Core/Commands/Self/SetPermFlag.cs deleted file mode 100644 index c0e4649..0000000 --- a/Core/Commands/Self/SetPermFlag.cs +++ /dev/null @@ -1,51 +0,0 @@ -using OpenMetaverse; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; - -namespace BetterSecondBot.Commands.Self -{ - public class SetPermFlag : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "Text","Text (True|Flase)", "Text (True|Flase)" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Flag: friend, group, animation, teleport or command", "State to set the flag to","Make the permission sticky" }; } } - public override string Helpfile { get { return "Makes the bot set/clear a permission flag for a selected action, sticky permissions are kept untill they are removed or the bot restarts"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID targetUUID) == true) - { - string[] AcceptedFlags = new string[] { "friend", "group", "animation", "teleport", "command" }; - if(AcceptedFlags.Contains(args[1]) == true) - { - if(bool.TryParse(args[2],out bool stateflag) == true) - { - bool sticky = false; - if(args.Length == 4) - { - bool.TryParse(args[3], out sticky); - } - if(stateflag == true) - { - bot.Add_action_from(args[1], targetUUID, sticky); - InfoBlob = "Added perm: "+args[1]+" Sticky: " + sticky.ToString(); - } - else - { - bot.Remove_action_from(args[1], targetUUID, sticky); - InfoBlob = "Removed perm: " + args[1] + " Sticky: " + sticky.ToString(); - } - return true; - } - return Failed("Failed to process state flag value"); - } - return Failed("Not an accepted flag"); - } - return Failed("Unable to process UUID"); - } - return false; - } - } -} diff --git a/Core/Commands/Self/logout.cs b/Core/Commands/Self/logout.cs deleted file mode 100644 index d80ec02..0000000 --- a/Core/Commands/Self/logout.cs +++ /dev/null @@ -1,34 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Self -{ - public class Bye : Logout - { - public override string Helpfile { get { return "Makes the bot kill itself you monster, without saying anything"; } } - public override bool CallFunction(string[] args) - { - bot.KillMePlease(); - return true; - } - } - public class Logout : CoreCommand - { - public override string Helpfile { get { return "Makes the bot kill itself you monster"; } } - public override bool CallFunction(string[] args) - { - bot.GetClient.Self.Chat("I dont want to go :( ", 0, ChatType.Normal); - bot.KillMePlease(); - return true; - } - } - - public class Logoff : CoreCommand - { - public override string Helpfile { get { return "Makes the bot kill itself you monster"; } } - public override bool CallFunction(string[] args) - { - - return true; - } - } -} diff --git a/Core/Commands/StreamAdmin/FetchNextNotecard.cs b/Core/Commands/StreamAdmin/FetchNextNotecard.cs deleted file mode 100644 index c480af4..0000000 --- a/Core/Commands/StreamAdmin/FetchNextNotecard.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System; -using OpenMetaverse; -using BetterSecondBotShared.Static; -using RestSharp; -using Newtonsoft.Json; - -namespace BetterSecondBot.Commands.StreamAdmin -{ - public class FetchNextNotecard : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "TEXT","TEXT" }; } } - public override string[] ArgHints { get { return new[] { "Server endpoint","Server endpoint code" }; } } - public override string Helpfile { get { return "[StreamAdmin]\nThis command is part of the streamadmin commands set\n No end user support will be given."; } } - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - string attempt_endpoint = "" + args[0] + "endpoint.php"; - string token = helpers.GetSHA1(helpers.UnixTimeNow().ToString()+"notecardnext" + args[1]); - var client = new RestClient("" + args[0] + "endpoint.php"); - var request = new RestRequest("notecard/next", Method.POST); - request.AddParameter("token", token); - request.AddHeader("content-type", "application/x-www-form-urlencoded"); - IRestResponse endpoint_checks = client.Post(request); - if (endpoint_checks.StatusCode == System.Net.HttpStatusCode.OK) - { - try - { - notecardendpoint server_reply = JsonConvert.DeserializeObject(endpoint_checks.Content); - if (server_reply.status == true) - { - if (server_reply.NotecardTitle.Length > 3) - { - return bot.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, (UUID)server_reply.AvatarUUID); - } - else - { - return Failed("Notecard title is to short - "+ endpoint_checks.Content); - } - } - return Failed(server_reply.message); - } - catch (Exception e) - { - return Failed("Error: "+e.Message+""); - } - } - else - { - return Failed("HTTP error DataObject broken Status:"+ endpoint_checks.StatusCode.ToString()+" @ "+ attempt_endpoint+"\n Message given (if any): "+endpoint_checks.Content); - } - } - return Failed("incorrect number of args"); - } - } - - public class notecardendpoint : endpoint - { - public string AvatarUUID { get; set; } - public string NotecardTitle { get; set; } - public string NotecardContent { get; set; } - } - - public class endpoint - { - public bool status { get; set; } - public string message { get; set; } - } -} diff --git a/Core/Core.csproj b/Core/Core.csproj index 4a60d50..dc285be 100644 --- a/Core/Core.csproj +++ b/Core/Core.csproj @@ -8,6 +8,7 @@ + diff --git a/BetterSecondbot/HttpService/Animation.cs b/Core/HttpService/Animation.cs similarity index 91% rename from BetterSecondbot/HttpService/Animation.cs rename to Core/HttpService/Animation.cs index c503689..b5dcec8 100644 --- a/BetterSecondbot/HttpService/Animation.cs +++ b/Core/HttpService/Animation.cs @@ -12,9 +12,9 @@ using System.Reflection; namespace BetterSecondBot.HttpService { - public class HttpApiAnimation : WebApiControllerWithTokens + public class HTTP_Animation : WebApiControllerWithTokens { - public HttpApiAnimation(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Animation(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("Toggles if animation requests from this avatar (used for remote poseballs) are accepted")] [ReturnHints("Granted perm animation")] diff --git a/BetterSecondbot/HttpService/Avatars.cs b/Core/HttpService/Avatars.cs similarity index 100% rename from BetterSecondbot/HttpService/Avatars.cs rename to Core/HttpService/Avatars.cs diff --git a/BetterSecondbot/HttpService/Chat.cs b/Core/HttpService/Chat.cs similarity index 84% rename from BetterSecondbot/HttpService/Chat.cs rename to Core/HttpService/Chat.cs index 1ddf9bc..db58aab 100644 --- a/BetterSecondbot/HttpService/Chat.cs +++ b/Core/HttpService/Chat.cs @@ -12,9 +12,9 @@ using BetterSecondBotShared.Static; namespace BetterSecondBot.HttpService { - public class HttpApiLocalchat : WebApiControllerWithTokens + public class HTTP_Chat : WebApiControllerWithTokens { - public HttpApiLocalchat(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Chat(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("fetchs the last 20 localchat messages")] [ReturnHints("array string")] @@ -29,7 +29,8 @@ namespace BetterSecondBot.HttpService } [About("sends a message to localchat")] - [ArgHints("message", "URLARG", "the message to send")] + [ArgHints("channel", "URLARG", "the channel to output on (>=0)")] + [ArgHints("message", "Text", "the message to send")] [ReturnHints("array string")] [ReturnHints("Message empty")] [ReturnHints("Invaild channel")] @@ -48,6 +49,10 @@ namespace BetterSecondBot.HttpService { return BasicReply("Invaild channel"); } + if(channelnum < 0) + { + return BasicReply("Invaild channel"); + } bot.GetClient.Self.Chat(message, channelnum, ChatType.Normal); return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory())); diff --git a/BetterSecondbot/HttpService/Core.cs b/Core/HttpService/Core.cs similarity index 66% rename from BetterSecondbot/HttpService/Core.cs rename to Core/HttpService/Core.cs index 4b08816..ac83d88 100644 --- a/BetterSecondbot/HttpService/Core.cs +++ b/Core/HttpService/Core.cs @@ -53,52 +53,9 @@ namespace BetterSecondBot.HttpService - [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) - { - if (tokens.Allow(token, "core", "walkto", getClientIP()) == true) - { - bool status = bot.GetCommandsInterface.Call("AutoPilot", "<"+x+","+y+","+z+">"); - if (status == true) - { - return BasicReply("Accepted"); - } - return Failure("Error Unable to AutoPilot to location"); - } - return Failure("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) - { - if (tokens.Allow(token, "core", "teleport", getClientIP()) == true) - { - bool status = bot.GetCommandsInterface.Call("Teleport", ""+region+"/" + x + "/" + y + "/" + z + ""); - if (status == true) - { - return BasicReply("Accepted"); - } - return Failure("Error Unable to Teleport to location"); - } - return Failure("Token not accepted"); - } - - [About("Used to check HTTP connections")] [ReturnHints("world")] [NeedsToken(false)] diff --git a/BetterSecondbot/HttpService/Dialogs.cs b/Core/HttpService/Dialogs.cs similarity index 100% rename from BetterSecondbot/HttpService/Dialogs.cs rename to Core/HttpService/Dialogs.cs diff --git a/BetterSecondbot/HttpService/Discord.cs b/Core/HttpService/Discord.cs similarity index 100% rename from BetterSecondbot/HttpService/Discord.cs rename to Core/HttpService/Discord.cs diff --git a/BetterSecondbot/HttpService/Estate.cs b/Core/HttpService/Estate.cs similarity index 95% rename from BetterSecondbot/HttpService/Estate.cs rename to Core/HttpService/Estate.cs index 9445e7f..9b84b46 100644 --- a/BetterSecondbot/HttpService/Estate.cs +++ b/Core/HttpService/Estate.cs @@ -14,9 +14,9 @@ namespace BetterSecondBot.HttpService - public class HttpAPIEstate : WebApiControllerWithTokens + public class HTTP_Estate : WebApiControllerWithTokens { - public HttpAPIEstate(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) + public HTTP_Estate(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } diff --git a/BetterSecondbot/HttpService/Friends.cs b/Core/HttpService/Friends.cs similarity index 100% rename from BetterSecondbot/HttpService/Friends.cs rename to Core/HttpService/Friends.cs diff --git a/BetterSecondbot/HttpService/Funds.cs b/Core/HttpService/Funds.cs similarity index 100% rename from BetterSecondbot/HttpService/Funds.cs rename to Core/HttpService/Funds.cs diff --git a/BetterSecondbot/HttpService/Group.cs b/Core/HttpService/Group.cs similarity index 96% rename from BetterSecondbot/HttpService/Group.cs rename to Core/HttpService/Group.cs index 8a6ddf6..f44b764 100644 --- a/BetterSecondbot/HttpService/Group.cs +++ b/Core/HttpService/Group.cs @@ -12,9 +12,9 @@ using BetterSecondBotShared.Static; namespace BetterSecondBot.HttpService { - public class HttpApiGroup : WebApiControllerWithTokens + public class HTTP_Group : WebApiControllerWithTokens { - public HttpApiGroup(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Group(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("Checks if the given UUID is in the given group
Note: if group membership data is more than 60 secs old this will return Updating
Please wait and retry later")] diff --git a/BetterSecondbot/HttpService/Home.cs b/Core/HttpService/Home.cs similarity index 84% rename from BetterSecondbot/HttpService/Home.cs rename to Core/HttpService/Home.cs index c0ee1ec..c8104a2 100644 --- a/BetterSecondbot/HttpService/Home.cs +++ b/Core/HttpService/Home.cs @@ -12,9 +12,9 @@ using BetterSecondBotShared.Static; namespace BetterSecondBot.HttpService { - public class Http_Home : WebApiControllerWithTokens + public class HTTP_Home : WebApiControllerWithTokens { - public Http_Home(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Home(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("Makes the bot teleport to its home region")] [ReturnHints("ok")] diff --git a/BetterSecondbot/HttpService/HttpAsService.cs b/Core/HttpService/HttpAsService.cs similarity index 89% rename from BetterSecondbot/HttpService/HttpAsService.cs rename to Core/HttpService/HttpAsService.cs index 07c0948..f300c37 100644 --- a/BetterSecondbot/HttpService/HttpAsService.cs +++ b/Core/HttpService/HttpAsService.cs @@ -178,13 +178,13 @@ namespace BetterSecondBot.HttpService // .WithRegexRules("HTTP exception 404") //) .WithWebApi("/inventory", m => m - .WithController(() => new HttpApiInventory(Bot, Tokens)) + .WithController(() => new HTTP_Inventory(Bot, Tokens)) ) .WithWebApi("/chat", m => m - .WithController(() => new HttpApiLocalchat(Bot, Tokens)) + .WithController(() => new HTTP_Chat(Bot, Tokens)) ) .WithWebApi("/groups", m => m - .WithController(() => new HttpApiGroup(Bot, Tokens)) + .WithController(() => new HTTP_Group(Bot, Tokens)) ) .WithWebApi("/ims", m => m .WithController(() => new HttpApiIM(Bot, Tokens)) @@ -193,10 +193,10 @@ namespace BetterSecondBot.HttpService .WithController(() => new HttpApiCore(Config, Bot, Tokens)) ) .WithWebApi("/parcel", m => m - .WithController(() => new HttpApiParcel(Bot,Tokens)) + .WithController(() => new HTTP_Parcel(Bot,Tokens)) ) .WithWebApi("/estate", m => m - .WithController(() => new HttpAPIEstate(Bot, Tokens)) + .WithController(() => new HTTP_Estate(Bot, Tokens)) ) .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" }))); return server; @@ -397,6 +397,7 @@ namespace BetterSecondBot.HttpService protected SecondBot bot; public bool needsToken { get; set; } protected UUID avataruuid = UUID.Zero; + protected Parcel targetparcel = null; protected string CallMethod(string name,string[] args) { @@ -423,6 +424,24 @@ namespace BetterSecondBot.HttpService string reply = (string)found.Invoke(this, settings.Cast().ToArray()); return "Passed:"+ reply; } + protected KeyValuePair SetupCurrentParcel(string token,string usenamespace,string command) + { + if (tokens.Allow(token, usenamespace, command, getClientIP()) == false) + { + return new KeyValuePair(false, "Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim == null) + { + return new KeyValuePair(false, "Error not in a sim"); + } + int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); + if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == false) + { + return new KeyValuePair(false, "Parcel data not ready"); + } + Parcel targetparcel = bot.GetClient.Network.CurrentSim.Parcels[localid]; + return new KeyValuePair(true, ""); + } protected void ProcessAvatar(string avatar) { string[] bits = avatar.Split(' '); diff --git a/BetterSecondbot/HttpService/Im.cs b/Core/HttpService/Im.cs similarity index 100% rename from BetterSecondbot/HttpService/Im.cs rename to Core/HttpService/Im.cs diff --git a/BetterSecondbot/HttpService/Info.cs b/Core/HttpService/Info.cs similarity index 94% rename from BetterSecondbot/HttpService/Info.cs rename to Core/HttpService/Info.cs index 9f00532..8d56528 100644 --- a/BetterSecondbot/HttpService/Info.cs +++ b/Core/HttpService/Info.cs @@ -12,9 +12,9 @@ using BetterSecondBotShared.Static; namespace BetterSecondBot.HttpService { - public class Http_Info : WebApiControllerWithTokens + public class HTTP_Info : WebApiControllerWithTokens { - public Http_Info(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Info(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("Fetchs the current bot")] [ReturnHints("The build ID of the bot")] diff --git a/BetterSecondbot/HttpService/Inventory.cs b/Core/HttpService/Inventory.cs similarity index 62% rename from BetterSecondbot/HttpService/Inventory.cs rename to Core/HttpService/Inventory.cs index b87c908..1a6ae67 100644 --- a/BetterSecondbot/HttpService/Inventory.cs +++ b/Core/HttpService/Inventory.cs @@ -10,17 +10,17 @@ using OpenMetaverse; namespace BetterSecondBot.HttpService { - public class HttpApiInventory : WebApiControllerWithTokens + public class HTTP_Inventory : WebApiControllerWithTokens { - public HttpApiInventory(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Inventory(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) + [Route(HttpVerbs.Get, "/RezObject/{item}/{token}")] + public object RezObject(string item, string token) { - if (tokens.Allow(token, "inventory", "rezobject", getClientIP()) == true) + if (tokens.Allow(token, "inventory", "RezObject", getClientIP()) == true) { bool status = bot.GetCommandsInterface.Call("RezObject", item); return BasicReply(status.ToString()); @@ -28,14 +28,15 @@ 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) + [Route(HttpVerbs.Post, "/Rename/{item}/{token}")] + public object Rename(string item, string token, [FormField] string newname) { - if (tokens.Allow(token, "inventory", "rename", getClientIP()) == true) + if (tokens.Allow(token, "inventory", "Rename", getClientIP()) == true) { bool status = bot.GetCommandsInterface.Call("RenameInventory", "12~#~" + item + "~#~" + newname); return BasicReply(status.ToString()); @@ -85,6 +86,72 @@ namespace BetterSecondBot.HttpService return BasicReply("Token not accepted"); } + [About("Transfers a item [ARG 2] to a objects inventory [ARG 1] (And if set with the script running state [ARG 3])")] + [ReturnHints("Transfering running script")] + [ReturnHints("Transfering inventory")] + [ReturnHints("Invaild item uuid")] + [ReturnHints("Invaild object uuid")] + [ReturnHints("Unable to find inventory")] + [ReturnHints("Unable to find object")] + [ReturnHints("Invaild running")] + [ArgHints("item", "URLARG", "UUID of item")] + [ArgHints("object", "URLARG", "the uuid of the object")] + [ArgHints("running", "URLARG", "true if you wish the transfered script to be running otherwise false")] + + [Route(HttpVerbs.Get, "/TransferInventoryToObject/{item}/{objectuuid}/{running}/{token}")] + public object TransferInventoryToObject(string item, string objectuuid, string running, string token) + { + if (tokens.Allow(token, "inventory", "TransferInventoryToObject", getClientIP()) == true) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(item, out UUID itemuuid) == false) + { + return Failure("Invaild item uuid"); + } + if (UUID.TryParse(objectuuid, out UUID objectUUID) == false) + { + return Failure("Invaild object uuid"); + } + if (bool.TryParse(running, out bool runscript) == false) + { + return Failure("Invaild running"); + } + + InventoryItem itm = bot.GetClient.Inventory.FetchItem(itemuuid, bot.GetClient.Self.AgentID, (3 * 1000)); + if (itm == null) + { + return Failure("Unable to find inventory"); + } + Dictionary objects_copy = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); + KeyValuePair RealObject = new KeyValuePair(0,null); + foreach (KeyValuePair Obj in objects_copy) + { + if (Obj.Value.ID == objectUUID) + { + RealObject = Obj; + break; + } + } + if (RealObject.Value == null) + { + return Failure("Unable to find object"); + } + bool scriptState = runscript; + if (itm.AssetType != AssetType.LSLText) + { + scriptState = false; + } + if (itm.AssetType == AssetType.LSLText) + { + bot.GetClient.Inventory.CopyScriptToTask(RealObject.Key, itm, scriptState); + return BasicReply("Transfering script [state: "+scriptState.ToString()+"]"); + } + bot.GetClient.Inventory.UpdateTaskInventory(RealObject.Key, itm); + return BasicReply("Transfering inventory"); + } + + [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")] diff --git a/Core/HttpService/Movement.cs b/Core/HttpService/Movement.cs new file mode 100644 index 0000000..096979d --- /dev/null +++ b/Core/HttpService/Movement.cs @@ -0,0 +1,131 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; +using System.Threading; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Movement : WebApiControllerWithTokens + { + public HTTP_Movement(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("uses the AutoPilot to move to a location")] + [ReturnHints("Error Unable to AutoPilot to location")] + [ReturnHints("Accepted")] + [ReturnHints("Convert to vector has failed")] + [ReturnHints("? value out of range 0-?")] + [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, "/AutoPilot/{x}/{y}/{z}/{token}")] + public object AutoPilot(string x, string y, string z, string token) + { + if (tokens.Allow(token, "movement", "AutoPilot", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (Vector3.TryParse("<" + x + "," + y + "," + z + ">", out Vector3 pos) == false) + { + return Failure("Convert to vector has failed"); + } + if (helpers.inrange(pos.X, 0, 255) == false) + { + return Failure("x value out of range 0-255"); + } + if (helpers.inrange(pos.Y, 0, 255) == false) + { + return Failure("y value out of range 0-255"); + } + if (helpers.inrange(pos.Z, 0, 5000) == false) + { + return Failure("z value out of range 0-5000"); + } + bot.GetClient.Self.AutoPilotCancel(); + bot.GetClient.Self.Movement.TurnToward(pos, true); + Thread.Sleep(500); + uint Globalx, Globaly; + Utils.LongToUInts(bot.GetClient.Network.CurrentSim.Handle, out Globalx, out Globaly); + bot.GetClient.Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z); + return true; + } + + [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) + { + if (tokens.Allow(token, "core", "Teleport", getClientIP()) == true) + { + bool status = TeleportRequest(new string[] { region, x, y, z }); + if (status == true) + { + return BasicReply("Accepted"); + } + return Failure("Error Unable to Teleport to location"); + } + return Failure("Token not accepted"); + } + + + + protected bool TeleportRequest(string[] args) + { + bot.GetClient.Self.AutoPilotCancel(); + if (args[0].Contains("http://maps.secondlife.com/secondlife/") == true) + { + bot.TeleportWithSLurl(args[0]); + return true; + } + else + { + float posX = 128; + float posY = 128; + float posZ = 0; + string regionName = bot.GetClient.Network.CurrentSim.Name; + bool ok = true; + int offset = 0; + string[] tp_args = args[0].Split('/'); + if ((tp_args.Length == 4) || (tp_args.Length == 1)) + { + regionName = tp_args[0]; + offset = 1; + } + if (tp_args.Length >= 3) + { + float.TryParse(tp_args[offset + 0], out posX); + float.TryParse(tp_args[offset + 1], out posY); + float.TryParse(tp_args[offset + 2], out posZ); + } + else if (tp_args.Length == 2) + { + ok = false; + } + if (ok == true) + { + bot.SetTeleported(); + bool status = bot.GetClient.Self.Teleport(regionName, new Vector3(posX, posY, posZ)); + bot.ResetAnimations(); + return status; + } + else + { + return false; + } + } + } + } +} diff --git a/Core/HttpService/Parcel.cs b/Core/HttpService/Parcel.cs new file mode 100644 index 0000000..67e68f8 --- /dev/null +++ b/Core/HttpService/Parcel.cs @@ -0,0 +1,620 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using static OpenMetaverse.ParcelManager; +using BetterSecondBotShared.Static; +using BetterSecondBotShared.logs; +using System.Threading; + +namespace BetterSecondBot.HttpService +{ + public partial class HTTP_Parcel : WebApiControllerWithTokens + { + public HTTP_Parcel(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Sets the current parcel for sale Also marks the parcel for sale")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Invaild amount")] + [ArgHints("amount", "URLARG", "The amount to sell the parcel for from 1 to 9999999")] + [ArgHints("avatar", "URLARG", "Avatar uuid or Firstname Lastname or \"none\" who we are locking the sale to")] + [Route(HttpVerbs.Get, "/SetParcelSale/{amount}/{avatar}/{token}")] + public object SetParcelSale(string amount,string avatar,string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "SetParcelSale"); + if(tests.Key == false) + { + return Failure(tests.Value); + } + if (int.TryParse(amount,out int amountvalue) == false) + { + return Failure("Invaild amount"); + } + if((amountvalue < 1) || (amountvalue > 9999999)) + { + return Failure("Invaild amount"); + } + ProcessAvatar(avatar); + targetparcel.SalePrice = amountvalue; + targetparcel.AuthBuyerID = avataruuid; + parcel_static.ParcelSetFlag(ParcelFlags.ForSale, targetparcel, true); + parcel_static.ParcelSetFlag(ParcelFlags.ForSaleObjects, targetparcel, false); + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return Failure("ok"); + } + + [About("Updates the current parcels name")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Parcel name is empty")] + [ArgHints("name", "URLARG", "The new name of the parcel")] + [Route(HttpVerbs.Get, "/SetParcelName/{name}/{token}")] + public object SetParcelName(string name, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "SetParcelName"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + if (helpers.notempty(name) == false) + { + return Failure("Parcel name is empty"); + } + targetparcel.Name = name; + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return Failure("ok"); + } + + [About("Updates the current parcels description")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ArgHints("desc", "Text", "The new desc of the parcel")] + [Route(HttpVerbs.Post, "/SetParcelDesc/{token}")] + public object SetParcelDesc([FormField] string desc, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "SetParcelDesc"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + targetparcel.Desc = desc; + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return Failure("ok"); + } + + [About("Fetchs the current parcels desc")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [Route(HttpVerbs.Get, "/GetParcelDesc/{token}")] + public object GetParcelDesc(string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "GetParcelDesc"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + return Failure(targetparcel.Desc); + } + + [About("gets the flags for the parcel")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [Route(HttpVerbs.Get, "/GetParcelFlags/{token}")] + public object GetParcelFlags(string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "GetParcelFlags"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + Dictionary flags = parcel_static.get_flags_list(); + Dictionary collection = new Dictionary(); + foreach (ParcelFlags cfg in flags.Values) + { + collection.Add(cfg.ToString(), targetparcel.Flags.HasFlag(cfg).ToString()); + } + return collection; + } + + [About("Ejects an avatar")] + [ReturnHints("ok")] + [ReturnHints("Invaild avatar")] + [ArgHints("avatar", "URLARG", "uuid of the avatar or Firstname Lastname")] + [Route(HttpVerbs.Get, "/ParcelEject/{avatar}/{token}")] + public object ParcelEject(string avatar,string token) + { + if (tokens.Allow(token, "parcel", "ParcelEject", getClientIP()) == false) + { + return BasicReply("Token not accepted"); + } + ProcessAvatar(avatar); + if(avataruuid == UUID.Zero) + { + return Failure("Invaild avatar"); + } + bot.GetClient.Parcels.EjectUser(avataruuid, false); + return BasicReply("ok"); + } + + [About("Abandons the parcel the bot is currently on, returning it to Linden's or Estate owner")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/AbandonLand/{token}")] + public object AbandonLand(string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "AbandonLand"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + bot.GetClient.Parcels.ReleaseParcel(bot.GetClient.Network.CurrentSim, targetparcel.LocalID); + return BasicReply("ok"); + } + + + [About("Bans an avatar from a parcel")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Invaild avatar")] + [ReturnHints("Avatar is in the blacklist")] + [ArgHints("avatar", "URLARG", "uuid of the avatar or Firstname Lastname")] + [Route(HttpVerbs.Get, "/ParcelBan/{avatar}/{token}")] + public object ParcelBan(string avatar, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "ParcelBan"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar"); + } + bool alreadyBanned = false; + foreach (ParcelAccessEntry E in targetparcel.AccessBlackList) + { + if (E.AgentID == avataruuid) + { + alreadyBanned = true; + break; + } + } + if (alreadyBanned == true) + { + return BasicReply("Avatar is in the blacklist"); + } + ParcelAccessEntry entry = new ParcelAccessEntry(); + entry.AgentID = avataruuid; + entry.Flags = AccessList.Ban; + entry.Time = new System.DateTime(3030, 03, 03); + targetparcel.AccessBlackList.Add(entry); + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return BasicReply("ok"); + } + + [About("Unbans an avatar from a parcel")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Invaild avatar")] + [ReturnHints("Avatar is already unbanned")] + [ArgHints("avatar", "URLARG", "uuid of the avatar or Firstname Lastname")] + [Route(HttpVerbs.Get, "/ParcelUnBan/{avatar}/{token}")] + public object ParcelUnBan(string avatar, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "ParcelUnBan"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar"); + } + bool alreadyBanned = false; + ParcelAccessEntry removeentry = new ParcelAccessEntry(); + foreach (ParcelAccessEntry E in targetparcel.AccessBlackList) + { + if (E.AgentID == avataruuid) + { + alreadyBanned = true; + removeentry = E; + break; + } + } + if (alreadyBanned == false) + { + return BasicReply("Avatar is already unbanned"); + } + targetparcel.AccessBlackList.Remove(removeentry); + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return BasicReply("ok"); + } + + + [About("Updates the current parcels name")] + [ReturnHints("true|false")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ArgHints("musicurl", "URLARG", "The new name of the parcel")] + [Route(HttpVerbs.Get, "/SetParcelMusic/{musicurl}/{token}")] + public object SetParcelMusic(string musicurl, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "SetParcelMusic"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + bool status = parcel_static.set_parcel_music(bot, targetparcel, musicurl); + return Failure(status.ToString()); + } + + [About("Updates the current parcels name")] + [ReturnHints("true|false")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Incorrect perms to control parcel")] + [ReturnHints("No accepted flags")] + [ReturnHints("Unable to set flag ...")] + [ReturnHints("Flag: ? is unknown")] + [ReturnHints("Flag: ? missing \"=\"")] + [ArgHints("escapedflagdata", "Text", "repeatable flag data split by ::: formated Flag=True|False")] + [Route(HttpVerbs.Post, "/SetParcelFlag/{escapedflagdata}/{token}")] + public object SetParcelFlag([FormField] string escapedflagdata, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "SetParcelFlag"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + List acceptablewords = new List(); + Dictionary flags = parcel_static.get_flags_list(); + acceptablewords.AddRange(new[] { "True", "False" }); + + Dictionary setflags = new Dictionary(); + string[] args = escapedflagdata.Split(":::"); + foreach (string a in args) + { + string[] parts = a.Split('=', StringSplitOptions.RemoveEmptyEntries); + if (parts.Length != 2) + { + LogFormater.Warn("Flag: " + a + " missing \"=\""); + continue; + } + if (flags.ContainsKey(parts[0]) == false) + { + LogFormater.Warn("Flag: " + parts[0] + " is unknown"); + continue; + } + if (acceptablewords.Contains(parts[1]) == false) + { + LogFormater.Crit("Unable to set flag " + parts[0] + " to : " + parts[1] + ""); + } + setflags.Add(parts[0], Convert.ToBoolean(parts[1])); + } + if (setflags.Count == 0) + { + return Failure("No accepted flags"); + } + if (parcel_static.has_parcel_perm(targetparcel, bot) == false) + { + return Failure("Incorrect perms to control parcel"); + } + foreach (KeyValuePair cfg in setflags) + { + if (flags.ContainsKey(cfg.Key) == true) + { + parcel_static.ParcelSetFlag(flags[cfg.Key], targetparcel, cfg.Value); + } + } + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return BasicReply("Applying perms"); + } + + [About("Returns all objects from the current parcel for the selected avatar")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Invaild avatar UUID")] + [ArgHints("avatar", "URLARG", "avatar uuid or Firstname Lastname")] + [Route(HttpVerbs.Get, "/ParcelReturnTargeted/{avatar}/{token}")] + public object ParcelReturnTargeted(string avatar, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "ParcelReturnTargeted"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar UUID"); + } + bot.GetClient.Parcels.ReturnObjects(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, ObjectReturnType.None, new List() { avataruuid }); + return BasicReply("ok"); + } + + + [About("transfers the current parcel ownership to the assigned group")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Invaild group uuid")] + [ReturnHints("Not in group")] + [Route(HttpVerbs.Get, "/ParcelDeedToGroup/{group}/{token}")] + public object ParcelDeedToGroup(string group, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "ParcelReturnTargeted"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + if (UUID.TryParse(group, out UUID groupuuid) == false) + { + return Failure("Invaild group uuid"); + } + if (bot.MyGroups.ContainsKey(groupuuid) == false) + { + return Failure("Not in group"); + } + targetparcel.GroupID = groupuuid; + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + Thread.Sleep(500); + bot.GetClient.Parcels.DeedToGroup(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, groupuuid); + return BasicReply("ok"); + } + + [About("Attempts to buy the parcel the bot is standing on, the amount must match the sale price for the land!")] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ReturnHints("Parcel not for sale")] + [ReturnHints("Parcel not for sale")] + [ReturnHints("Parcel sale locked to other avatars")] + [ReturnHints("Parcel sale price and amount do not match")] + [ReturnHints("Invaild amount")] + [ArgHints("amount", "URLARG", "amount to pay for the parcel (min 1)")] + [Route(HttpVerbs.Get, "/ParcelBuy/{amount}/{token}")] + public object ParcelBuy(string amount, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "ParcelBuy"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + if (int.TryParse(amount, out int amountvalue) == false) + { + return Failure("Invaild amount"); + } + if (amountvalue < 1) + { + return Failure("Invaild amount"); + }; + if (targetparcel.Flags.HasFlag(ParcelFlags.ForSale) == false) + { + return Failure("Parcel not for sale"); + } + if ((targetparcel.AuthBuyerID != UUID.Zero) && (targetparcel.AuthBuyerID != bot.GetClient.Self.AgentID)) + { + return Failure("Parcel sale locked to other avatars"); + } + if (targetparcel.SalePrice != amountvalue) + { + return Failure("Parcel sale price and amount do not match"); + } + bot.GetClient.Parcels.Buy(bot.GetClient.Network.CurrentSim, targetparcel.LocalID, false, UUID.Zero, false, targetparcel.Area, amountvalue); + return BasicReply("ok"); + } + + [About("Freezes an avatar")] + [ReturnHints("ok")] + [ReturnHints("Invaild avatar UUID")] + [ReturnHints("Invaild state")] + [ArgHints("avatar", "URLARG", "avatar uuid or Firstname Lastname")] + [ArgHints("state", "URLARG", "setting state to false will unfreeze or true to freeze")] + [Route(HttpVerbs.Get, "/ParcelFreeze/{avatar}/{state}/{token}")] + public object ParcelFreeze(string avatar, string state, string token) + { + if (tokens.Allow(token, "parcel", "ParcelFreeze", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if(bool.TryParse(state, out bool freezestate) == false) + { + return Failure("Invaild state"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar UUID"); + } + bot.GetClient.Parcels.FreezeUser(avataruuid, freezestate); + return BasicReply("ok"); + } + + + [About("Fetchs the parcel ban list of the parcel the bot is currently on
If the name returned is lookup the bot is currently requesting the avatar name")] + [ReturnHints("array of UUID=Name")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [Route(HttpVerbs.Get, "/GetParcelBanlist/{token}")] + public object GetParcelBanlist(string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "GetParcelBanlist"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + Dictionary reply = new Dictionary(); + foreach (ParcelAccessEntry e in targetparcel.AccessBlackList) + { + string name = bot.FindAvatarKey2Name(e.AgentID); + reply.Add(e.AgentID.ToString(), name); + } + return BasicReply(JsonConvert.SerializeObject(reply)); + } + + [About("Returns a rezzed object")] + [ReturnHints("ok")] + [ReturnHints("Invaild object uuid")] + [ReturnHints("Unable to find object")] + [ArgHints("objectuuid", "URLARG", "object UUID to unrez")] + [Route(HttpVerbs.Get, "/UnRezObject/{objectuuid}/{token}")] + public object UnRezObject(string objectuuid,string token) + { + if (tokens.Allow(token, "parcel", "UnRezObject", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(objectuuid, out UUID targetobject) == false) + { + return Failure("Invaild object uuid"); + } + bool found = false; + Dictionary objects_copy = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); + foreach (KeyValuePair Obj in objects_copy) + { + if (Obj.Value.ID == targetobject) + { + bot.GetClient.Inventory.RequestDeRezToInventory(Obj.Key); + found = true; + break; + } + } + if(found == false) + { + return Failure("Unable to find object"); + } + return BasicReply("ok"); + } + + [About("Updates the current parcels media settings \n" + + "MediaAutoScale=Bool (True|False)\n" + + "MediaLoop=Bool (True|False)\n" + + "MediaID=UUID (Texture)\n" + + "MediaURL=String\n" + + "MediaDesc=String\n" + + "MediaHeight=Int (256 to 1024)\n" + + "MediaWidth=Int (256 to 1024)\n" + + "MediaType=String [\"IMG-PNG\",\"IMG-JPG\",\"VID-MP4\",\"VID-AVI\" or \"Custom-MIME_TYPE_CODE\"]" + )] + [ReturnHints("ok")] + [ReturnHints("Error not in a sim")] + [ReturnHints("Parcel data not ready")] + [ArgHints("escapedflagdata", "Text", "repeatable flag data split by ::: formated Flag=True|False")] + [Route(HttpVerbs.Get, "/ParcelSetMedia/{token}")] + public object ParcelSetMedia([FormField] string escapedflagdata, string token) + { + KeyValuePair tests = SetupCurrentParcel(token, "parcel", "ParcelSetMedia"); + if (tests.Key == false) + { + return Failure(tests.Value); + } + string[] args = escapedflagdata.Split(":::"); + foreach (string A in args) + { + string[] bits = A.Split('='); + if (bits.Length == 2) + { + if (bits[0] == "MediaType") + { + UpdateParcel_MediaType(targetparcel, bits[1]); + } + else if ((bits[0] == "MediaWidth") || (bits[0] == "MediaHeight")) + { + if (int.TryParse(bits[1], out int size) == true) + { + if ((size >= 256) || (size <= 1024)) + { + if (bits[0] == "MediaHeight") + { + targetparcel.Media.MediaHeight = size; + } + else if (bits[0] == "MediaWidth") + { + targetparcel.Media.MediaWidth = size; + } + } + } + } + else if (bits[0] == "MediaID") + { + if (UUID.TryParse(bits[1], out UUID texture) == true) + { + targetparcel.Media.MediaID = texture; + } + } + else if (bits[0] == "MediaURL") + { + targetparcel.Media.MediaURL = bits[1]; + } + else if (bits[0] == "MediaDesc") + { + targetparcel.Media.MediaDesc = bits[1]; + } + else if (bits[0] == "MediaAutoScale") + { + if (bool.TryParse(bits[1], out bool output) == true) + { + targetparcel.Media.MediaAutoScale = output; + } + } + else if (bits[0] == "MediaLoop") + { + if (bool.TryParse(bits[1], out bool output) == true) + { + targetparcel.Media.MediaLoop = output; + } + } + } + } + targetparcel.Update(bot.GetClient.Network.CurrentSim, false); + return BasicReply("ok"); + } + + protected bool UpdateParcel_MediaType(Parcel targetparcel, string value) + { + if (value == "IMG-PNG") + { + targetparcel.Media.MediaType = "image/png"; + } + else if (value == "IMG-JPG") + { + targetparcel.Media.MediaType = "image/jpeg"; + } + else if (value == "VID-MP4") + { + targetparcel.Media.MediaType = "video/mp4"; + } + else if (value == "VID-AVI") + { + targetparcel.Media.MediaType = "video/x-msvideo"; + } + else if (value.StartsWith("Custom-") == true) + { + string mime = value; + mime = mime.Replace("Custom-", ""); + targetparcel.Media.MediaType = mime; + } + else + { + return false; + } + return true; + } + } +} diff --git a/BetterSecondbot/HttpService/Self.cs b/Core/HttpService/Self.cs similarity index 55% rename from BetterSecondbot/HttpService/Self.cs rename to Core/HttpService/Self.cs index f08016f..b55cb6e 100644 --- a/BetterSecondbot/HttpService/Self.cs +++ b/Core/HttpService/Self.cs @@ -9,12 +9,13 @@ using System.Text; using OpenMetaverse; using Newtonsoft.Json; using BetterSecondBotShared.Static; +using System.Linq; namespace BetterSecondBot.HttpService { - public class Http_Self : WebApiControllerWithTokens + public class HTTP_Self : WebApiControllerWithTokens { - public Http_Self(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_Self(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("Makes the bot turn to face avatar and point at them (if found)")] [ReturnHints("ok")] @@ -109,7 +110,7 @@ namespace BetterSecondBot.HttpService return BasicReply(found_object.ToString()); } - [About("Makes the bot sit on the ground or on a object if it can see it")] + [About("Makes the bot kill itself you monster")] [ReturnHints("ok")] [Route(HttpVerbs.Get, "/Logoff/{token}")] public object Logoff(string token) @@ -126,6 +127,97 @@ namespace BetterSecondBot.HttpService return BasicReply("ok"); } + [About("Makes the bot kill itself you monster")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/Logout/{token}")] + public object Logout(string token) + { + if (tokens.Allow(token, "self", "Logout", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.KillMe == false) + { + bot.GetClient.Self.Chat("Laters im out", 0, ChatType.Normal); + bot.KillMePlease(); + } + return BasicReply("ok"); + } + + [About("Makes the bot kill itself you monster - without making a sound")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/Bye/{token}")] + public object Bye(string token) + { + if (tokens.Allow(token, "self", "Bye", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.KillMe == false) + { + bot.KillMePlease(); + } + return BasicReply("ok"); + } + + [About("Gets the last 5 commands issued to the bot")] + [ReturnHints("list of commands")] + [Route(HttpVerbs.Get, "/GetLastCommands/{token}")] + public object GetLastCommands(string token) + { + if (tokens.Allow(token, "self", "GetLastCommands", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + return bot.GetLastCommands(5); + } + + [About("Gets the last 5 commands issued to the bot")] + [ReturnHints("avatar lookup")] + [ReturnHints("Invaild state")] + [ReturnHints("Invaild sticky")] + [ReturnHints("Invaild flag")] + [ArgHints("avatar", "URLARG", "avatar uuid or Firstname Lastname")] + [ArgHints("flag", "URLARG", "friend, group, animation, teleport or command")] + [ArgHints("state", "URLARG", "State to set the flag to true or false")] + [ArgHints("sticky", "URLARG", "if true the permissing will not expire after the first use otherwise false")] + [Route(HttpVerbs.Get, "/SetPermFlag/{avatar}/{flag}/{state}/{sticky}/{token}")] + public object SetPermFlag(string avatar, string flag, string state, string sticky, string token) + { + if (tokens.Allow(token, "self", "SetPermFlag", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("avatar lookup"); + } + bool stateflag = false; + bool stickyflag = false; + if(bool.TryParse(state,out stateflag) == false) + { + return Failure("Invaild state"); + } + if (bool.TryParse(sticky, out stickyflag) == false) + { + return Failure("Invaild sticky"); + } + string[] AcceptedFlags = new string[] { "friend", "group", "animation", "teleport", "command" }; + if (AcceptedFlags.Contains(flag) == true) + { + return Failure("Invaild flag"); + } + if (stateflag == true) + { + bot.Add_action_from(flag, avataruuid, stickyflag); + return BasicReply("Added perm: " + flag + " Sticky: " + stickyflag.ToString()); + } + bot.Remove_action_from(flag, avataruuid, stickyflag); + return BasicReply("Removed perm: " + flag + " Sticky: " + stickyflag.ToString()); + } + + } } diff --git a/Core/HttpService/StreamAdmin.cs b/Core/HttpService/StreamAdmin.cs new file mode 100644 index 0000000..cb1ab9f --- /dev/null +++ b/Core/HttpService/StreamAdmin.cs @@ -0,0 +1,90 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; +using BetterSecondBotShared.Static; +using RestSharp; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_StreamAdmin : WebApiControllerWithTokens + { + public HTTP_StreamAdmin(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("an improved version of near me with extra details
NearMeDetails is a object formated as follows
  • id
  • name
  • x
  • y
  • z
  • range
")] + [ReturnHints("True|False")] + [ReturnHints("Bad reply: ...")] + [ReturnHints("Endpoint is empty")] + [ReturnHints("Endpointcode is empty")] + [ReturnHints("HTTP status code: ...")] + [ReturnHints("Error: ...")] + [ReturnHints("Notecard title is to short")] + [ArgHints("endpoint","Text","The end point")] + [ArgHints("endpointcode", "Text", "The end point code")] + [Route(HttpVerbs.Post, "/FetchNextNotecard/{token}")] + public object FetchNextNotecard([FormField] string endpoint, [FormField] string endpointcode, string token) + { + if (tokens.Allow(token, "avatars", "FetchNextNotecard", getClientIP()) == false) + { + return Failure("Token not accepted"); + } + if(helpers.notempty(endpoint) == false) + { + return Failure("Endpoint is empty"); + } + if (helpers.notempty(endpointcode) == false) + { + return Failure("Endpointcode is empty"); + } + + string attempt_endpoint = endpoint + "endpoint.php"; + token = helpers.GetSHA1(helpers.UnixTimeNow().ToString() + "notecardnext" + endpointcode); + var client = new RestClient(attempt_endpoint); + var request = new RestRequest("notecard/next", Method.POST); + request.AddParameter("token", token); + request.AddHeader("content-type", "application/x-www-form-urlencoded"); + IRestResponse endpoint_checks = client.Post(request); + if (endpoint_checks.StatusCode != System.Net.HttpStatusCode.OK) + { + return Failure("HTTP status code: " + endpoint_checks.StatusCode.ToString()); + } + try + { + notecardendpoint server_reply = JsonConvert.DeserializeObject(endpoint_checks.Content); + if (server_reply.status == false) + { + return Failure("Bad reply: " + server_reply.message); + } + if (server_reply.NotecardTitle.Length < 3) + { + return Failure("Notecard title is to short"); + } + return BasicReply(bot.SendNotecard(server_reply.NotecardTitle, server_reply.NotecardContent, (UUID)server_reply.AvatarUUID).ToString()); + } + catch (Exception e) + { + return Failure("Error: " + e.Message + ""); + } + } + + public class notecardendpoint : endpoint + { + public string AvatarUUID { get; set; } + public string NotecardTitle { get; set; } + public string NotecardContent { get; set; } + } + + public class endpoint + { + public bool status { get; set; } + public string message { get; set; } + } + } +} diff --git a/Shared/Staic/Helpers.cs b/Shared/Staic/Helpers.cs index 45e9f82..b5682b0 100644 --- a/Shared/Staic/Helpers.cs +++ b/Shared/Staic/Helpers.cs @@ -184,6 +184,17 @@ namespace BetterSecondBotShared.Static } return false; } + } + + public static string create_dirty_table(Dictionary entrys) + { + List items = new List(); + foreach(KeyValuePair e in entrys) + { + items.Add(e.Key); + items.Add(e.Value); + } + return create_dirty_table(items.ToArray(), 2); } public static string create_dirty_table(string[] items) { From fd1ca6626f71aac89f9bb898f8a552ef8a12bb6a Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 18 Feb 2021 09:42:48 +0000 Subject: [PATCH 4/5] Joined the HTTP commands and Core commands into one system There is no limit to my evil!!!! --- BetterSecondbot/BetterAtHome/BetterAtHome.cs | 35 +- .../BetterRelayService/BetterRelay.cs | 3 +- BetterSecondbot/DiscordSupervisor/Inbound.cs | 105 +---- BetterSecondbot/WikiMake/wiki_header.txt | 6 +- BetterSecondbot/WikiMake/wikimake.cs | 56 ++- Core/{HttpService => Commands}/Animation.cs | 6 +- Core/{HttpService => Commands}/Avatars.cs | 4 +- Core/{HttpService => Commands}/Chat.cs | 10 +- Core/{HttpService => Commands}/Core.cs | 77 +-- Core/{HttpService => Commands}/Dialogs.cs | 6 +- Core/{HttpService => Commands}/Discord.cs | 26 +- Core/{HttpService => Commands}/Estate.cs | 14 +- Core/{HttpService => Commands}/Friends.cs | 6 +- Core/{HttpService => Commands}/Funds.cs | 6 +- Core/{HttpService => Commands}/Group.cs | 54 +-- Core/Commands/Helpers/delay.cs | 29 -- Core/{HttpService => Commands}/Home.cs | 2 +- Core/{HttpService => Commands}/Im.cs | 12 +- Core/Commands/Info.cs | 117 +++++ Core/Commands/Inventory.cs | 441 ++++++++++++++++++ Core/Commands/Inventory/DeleteInventory.cs | 47 -- .../Inventory/InventoryPurgeNotecards.cs | 55 --- Core/Commands/Inventory/RenameInventory.cs | 41 -- Core/Commands/Inventory/attach.cs | 80 ---- Core/Commands/Inventory/getRealUUID.cs | 35 -- Core/Commands/Inventory/inventoryContents.cs | 52 --- Core/Commands/Inventory/inventoryFolders.cs | 36 -- Core/Commands/Inventory/outfit.cs | 74 --- Core/Commands/Inventory/sendFolder.cs | 43 -- Core/Commands/Inventory/sendItem.cs | 47 -- Core/Commands/Movement.cs | 304 ++++++++++++ Core/Commands/Movement/AutoPilotStop.cs | 13 - Core/Commands/Movement/Fly.cs | 35 -- Core/Commands/Movement/RequestTeleport.cs | 26 -- Core/Commands/Movement/RotateToFace.cs | 28 -- Core/Commands/Movement/RotateToFaceVector.cs | 37 -- Core/Commands/Movement/SendTeleportLure.cs | 25 - Core/Commands/Movement/rotateTo.cs | 48 -- Core/Commands/Notecard.cs | 97 ++++ Core/Commands/Notecard/notecardAdd.cs | 19 - Core/Commands/Notecard/notecardClear.cs | 19 - Core/Commands/Notecard/notecardSend.cs | 45 -- Core/{HttpService => Commands}/Parcel.cs | 6 +- Core/{HttpService => Commands}/Self.cs | 18 +- Core/{HttpService => Commands}/StreamAdmin.cs | 2 +- Core/Commands/commandlib.cs | 398 ---------------- Core/HttpService/HttpAsService.cs | 102 ++-- Core/HttpService/Info.cs | 116 ----- Core/HttpService/Inventory.cs | 218 --------- Core/HttpService/Movement.cs | 131 ------ Core/Static/http_commands_helper.cs | 33 ++ Core/bottypes/AVstorageBot.cs | 1 + Core/bottypes/AnimationsBot.cs | 4 +- Core/bottypes/AwaitReplyEventBot.cs | 104 +---- Core/bottypes/CommandsBot.cs | 403 +++++++++------- Core/bottypes/DialogsBot.cs | 8 +- Core/bottypes/EventsBot.cs | 57 +-- Core/bottypes/MessageSwitcherBot.cs | 58 --- Core/bottypes/SecondBot.cs | 7 +- Shared/BotTypes/BasicBot.cs | 116 ++--- 60 files changed, 1521 insertions(+), 2482 deletions(-) rename Core/{HttpService => Commands}/Animation.cs (92%) rename Core/{HttpService => Commands}/Avatars.cs (93%) rename Core/{HttpService => Commands}/Chat.cs (86%) rename Core/{HttpService => Commands}/Core.cs (54%) rename Core/{HttpService => Commands}/Dialogs.cs (91%) rename Core/{HttpService => Commands}/Discord.cs (96%) rename Core/{HttpService => Commands}/Estate.cs (91%) rename Core/{HttpService => Commands}/Friends.cs (94%) rename Core/{HttpService => Commands}/Funds.cs (91%) rename Core/{HttpService => Commands}/Group.cs (91%) delete mode 100644 Core/Commands/Helpers/delay.cs rename Core/{HttpService => Commands}/Home.cs (93%) rename Core/{HttpService => Commands}/Im.cs (81%) create mode 100644 Core/Commands/Info.cs create mode 100644 Core/Commands/Inventory.cs delete mode 100644 Core/Commands/Inventory/DeleteInventory.cs delete mode 100644 Core/Commands/Inventory/InventoryPurgeNotecards.cs delete mode 100644 Core/Commands/Inventory/RenameInventory.cs delete mode 100644 Core/Commands/Inventory/attach.cs delete mode 100644 Core/Commands/Inventory/getRealUUID.cs delete mode 100644 Core/Commands/Inventory/inventoryContents.cs delete mode 100644 Core/Commands/Inventory/inventoryFolders.cs delete mode 100644 Core/Commands/Inventory/outfit.cs delete mode 100644 Core/Commands/Inventory/sendFolder.cs delete mode 100644 Core/Commands/Inventory/sendItem.cs create mode 100644 Core/Commands/Movement.cs delete mode 100644 Core/Commands/Movement/AutoPilotStop.cs delete mode 100644 Core/Commands/Movement/Fly.cs delete mode 100644 Core/Commands/Movement/RequestTeleport.cs delete mode 100644 Core/Commands/Movement/RotateToFace.cs delete mode 100644 Core/Commands/Movement/RotateToFaceVector.cs delete mode 100644 Core/Commands/Movement/SendTeleportLure.cs delete mode 100644 Core/Commands/Movement/rotateTo.cs create mode 100644 Core/Commands/Notecard.cs delete mode 100644 Core/Commands/Notecard/notecardAdd.cs delete mode 100644 Core/Commands/Notecard/notecardClear.cs delete mode 100644 Core/Commands/Notecard/notecardSend.cs rename Core/{HttpService => Commands}/Parcel.cs (96%) rename Core/{HttpService => Commands}/Self.cs (89%) rename Core/{HttpService => Commands}/StreamAdmin.cs (96%) delete mode 100644 Core/Commands/commandlib.cs delete mode 100644 Core/HttpService/Info.cs delete mode 100644 Core/HttpService/Inventory.cs delete mode 100644 Core/HttpService/Movement.cs create mode 100644 Core/Static/http_commands_helper.cs diff --git a/BetterSecondbot/BetterAtHome/BetterAtHome.cs b/BetterSecondbot/BetterAtHome/BetterAtHome.cs index cbf5371..e7d569c 100644 --- a/BetterSecondbot/BetterAtHome/BetterAtHome.cs +++ b/BetterSecondbot/BetterAtHome/BetterAtHome.cs @@ -4,6 +4,7 @@ using BetterSecondBotShared.Static; using BetterSecondBot.bottypes; using OpenMetaverse; using System.Collections.Generic; +using BetterSecondBotShared.logs; namespace BetterSecondbot.BetterAtHome { @@ -20,6 +21,7 @@ namespace BetterSecondbot.BetterAtHome protected int homeregionIndexer = 0; protected long LastTeleportEvent = 0; protected List homeRegions = new List(); + protected string LastLoginStatus = "None"; public BetterAtHome(Cli setcontroler, JsonConfig configfile) { @@ -62,20 +64,23 @@ namespace BetterSecondbot.BetterAtHome protected void LoginProcess(object o, LoginProgressEventArgs e) { - resetSwitchs(); - if(e.Status == LoginStatus.Failed) + LastLoginStatus = e.Status.ToString(); + if (e.Status == LoginStatus.Failed) { + resetSwitchs(); LoginFailed = true; } else if(e.Status == LoginStatus.ConnectingToLogin) { + resetSwitchs(); LoggingIn = true; SetBetterAtHomeAction("Waiting for login to finish"); } else if(e.Status == LoginStatus.Success) { - LoggedIn = true; + resetSwitchs(); controler.Bot.AfterBotLoginHandler(); + LoggedIn = true; } } @@ -115,6 +120,10 @@ namespace BetterSecondbot.BetterAtHome { return false; } + if(hasBasicBot() == false) + { + return false; + } if(LoggingIn == true) { return false; @@ -154,6 +163,7 @@ namespace BetterSecondbot.BetterAtHome } protected string simname = ""; + protected int void_counter = 0; protected void ChangedSim(object o, SimChangedEventArgs e) { simname = ""; @@ -180,13 +190,13 @@ namespace BetterSecondbot.BetterAtHome return; } long dif = helpers.UnixTimeNow() - LastLoginEvent; - if (dif < 60) + if (dif < 15) { SetBetterAtHomeAction("[DC] Waiting for login lockout"); return; } dif = helpers.UnixTimeNow() - LastTeleportEvent; - if (dif < 60) + if (dif < 15) { SetBetterAtHomeAction("[DC] Waiting for Teleport lockout"); return; @@ -209,6 +219,19 @@ namespace BetterSecondbot.BetterAtHome protected void LoggedInAction() { + if((simname == "") || (controler.Bot.GetClient.Self.SimPosition.Z == 0)) + { + ChangedSim(null, null); + void_counter++; + SetBetterAtHomeAction("Void counter: "+ void_counter.ToString()); + if (void_counter == 10) + { + resetSwitchs(); + SetBetterAtHomeAction("Void detected - Resetting switchs"); + } + return; + } + void_counter = 0; SetBetterAtHomeAction("Logged In Actions"); if (controler.Bot.KillMe == true) { @@ -227,7 +250,7 @@ namespace BetterSecondbot.BetterAtHome SetBetterAtHomeAction("Waiting for Teleport lockout"); return; } - if(homeRegions.Count == 0) + if (homeRegions.Count == 0) { SetBetterAtHomeAction("No home regions"); return; diff --git a/BetterSecondbot/BetterRelayService/BetterRelay.cs b/BetterSecondbot/BetterRelayService/BetterRelay.cs index c3cb66e..230e24c 100644 --- a/BetterSecondbot/BetterRelayService/BetterRelay.cs +++ b/BetterSecondbot/BetterRelayService/BetterRelay.cs @@ -248,7 +248,8 @@ namespace BetterSecondBot.BetterRelayService { if (cfg.targetvalue != filtervalue) { - bool status = controler.Bot.GetCommandsInterface.Call("groupchat", cfg.targetvalue + "~#~" + sendmessage, UUID.Zero, "~#~"); + bool status = false; + //bool status = controler.Bot.GetCommandsInterface.Call("groupchat", cfg.targetvalue + "~#~" + sendmessage, UUID.Zero, "~#~"); if(status == false) { LogFormater.Info("sending via groupchat to group: " + cfg.targetvalue + " [Failed]"); diff --git a/BetterSecondbot/DiscordSupervisor/Inbound.cs b/BetterSecondbot/DiscordSupervisor/Inbound.cs index d3bd5cd..6c821c8 100644 --- a/BetterSecondbot/DiscordSupervisor/Inbound.cs +++ b/BetterSecondbot/DiscordSupervisor/Inbound.cs @@ -92,61 +92,11 @@ namespace BetterSecondBot.DiscordSupervisor { if (message.Content == "!commands") { - int counter = 0; - string addon = ""; - foreach (string a in controler.Bot.GetCommandsInterface.GetCommandsList()) - { - output.Append(addon); - addon = " , "; - output.Append(a); - counter++; - if (counter == 5) - { - output.Append("\n"); - addon = ""; - counter = 0; - } - } - await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot"); + await SendMessageToChannelAsync("interface", "broken", "bot", UUID.Zero, "bot"); } else if (message.Content.StartsWith("!help") == true) { - string[] bits = message.Content.Split(' '); - if (bits.Length == 2) - { - string command = bits[1].ToLowerInvariant(); - - if (controler.Bot.GetCommandsInterface.GetCommandsList().Contains(command) == true) - { - output.Append("\n=========================\nCommand:"); - output.Append(command); - output.Append("\n"); - output.Append("Workspace: "); - output.Append(controler.Bot.GetCommandsInterface.GetCommandWorkspace(command)); - output.Append("\n"); - output.Append("Min args: "); - output.Append(controler.Bot.GetCommandsInterface.GetCommandArgs(command).ToString()); - output.Append("\n"); - output.Append("Arg types: "); - output.Append(String.Join(",", controler.Bot.GetCommandsInterface.GetCommandArgTypes(command))); - output.Append("\n"); - output.Append("\n"); - output.Append("About: "); - output.Append(controler.Bot.GetCommandsInterface.GetCommandHelp(command)); - await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot"); - } - else - { - output.Append("Unable to find command: "); - output.Append(command); - output.Append(" please use !commands for a full list"); - await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot"); - } - } - else - { - await SendMessageToChannelAsync("interface", "Please format help request as follows: !help commandname", "bot", UUID.Zero, "bot"); - } + await SendMessageToChannelAsync("interface", "broken", "bot", UUID.Zero, "bot"); } else { @@ -157,46 +107,7 @@ namespace BetterSecondBot.DiscordSupervisor } else { - string[] bits = message.Content.Split("|||"); - string command = bits[0].ToLowerInvariant(); - bool known_command = controler.Bot.GetCommandsInterface.GetCommandsList().Contains(command); - if (known_command == false) - { - known_command = controler.Bot.getCustomCommands.ContainsKey(command); - } - if (known_command == true) - { - bool process_status = false; - if (bits.Length == 1) - { - bits = new string[] { bits[0], "" }; - } - if (controler.Bot.getCustomCommands.ContainsKey(command) == false) - { - process_status = controler.Bot.GetCommandsInterface.Call(command, bits[1], UUID.Zero); - } - else - { - process_status = true; - Thread t = new Thread(() => controler.Bot.custom_commands_loop(command, bits[1], UUID.Zero)); - t.Start(); - } - if (process_status == true) - { - await MarkMessage(message, "✅").ConfigureAwait(false); - } - else - { - await MarkMessage(message, "❌").ConfigureAwait(false); - } - } - else - { - output.Append("Unable to find command: "); - output.Append(command); - output.Append(" please use !commands for a full list"); - await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot"); - } + await MarkMessage(message, "❌").ConfigureAwait(false); } } } @@ -269,14 +180,16 @@ namespace BetterSecondBot.DiscordSupervisor } Noticetitle = Noticetitle.Replace("!notice ", ""); Noticetitle = Noticetitle.Trim(); - controler.Bot.GetCommandsInterface.Call("GroupNotice", "" + group.ToString() + "~#~" + Noticetitle + "~#~" + Noticemessage, UUID.Zero); - await MarkMessage(message, "✅"); + //controler.Bot.GetCommandsInterface.Call("GroupNotice", "" + group.ToString() + "~#~" + Noticetitle + "~#~" + Noticemessage, UUID.Zero); + //await MarkMessage(message, "✅"); + await MarkMessage((IUserMessage)message, "❌").ConfigureAwait(false); } else { IGuildUser user = (IGuildUser)message.Author; - controler.Bot.GetCommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + message.Content, UUID.Zero); - await MarkMessage(message, "✅"); + //controler.Bot.GetCommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + message.Content, UUID.Zero); + //await MarkMessage(message, "✅"); + await MarkMessage((IUserMessage)message, "❌").ConfigureAwait(false); } } } diff --git a/BetterSecondbot/WikiMake/wiki_header.txt b/BetterSecondbot/WikiMake/wiki_header.txt index 8e3fcf5..e83ec5e 100644 --- a/BetterSecondbot/WikiMake/wiki_header.txt +++ b/BetterSecondbot/WikiMake/wiki_header.txt @@ -13,13 +13,11 @@ diff --git a/BetterSecondbot/WikiMake/wikimake.cs b/BetterSecondbot/WikiMake/wikimake.cs index 832274c..f33bcc4 100644 --- a/BetterSecondbot/WikiMake/wikimake.cs +++ b/BetterSecondbot/WikiMake/wikimake.cs @@ -4,6 +4,7 @@ using BetterSecondBotShared.IO; using BetterSecondBotShared.Json; using BetterSecondBotShared.logs; using BetterSecondBotShared.Static; +using Core.Static; using EmbedIO; using System; using System.Collections.Generic; @@ -288,11 +289,6 @@ namespace BetterSecondBot.WikiMake api_reports.Add("JSON", new KeyValuePair(defaultJson.ApiCommandsCount, "Ready")); InterfaceWiki("JSON", defaultJson); - // CMD - BetterSecondBot.Commands.CoreCommandsInterface cmd = new BetterSecondBot.Commands.CoreCommandsInterface(null); - api_reports.Add("Core", new KeyValuePair(cmd.ApiCommandsCount, "Good")); - InterfaceWiki("Core", cmd, true); - // HTTP HTTPWiki(); @@ -305,13 +301,13 @@ namespace BetterSecondBot.WikiMake LogFormater.Info("[WIKI] Starting area HTTP endpoint"); HTTPendpoint HTTP = new HTTPendpoint(); - HTTPmenu("HTTP", HTTP); + HTTPmenu("Commands", HTTP); // create workspaces - HTTPWorkspaces("HTTP", HTTP); + HTTPWorkspaces("Commands", HTTP); // create commands - HTTPCommands("HTTP", HTTP); + HTTPCommands("Commands", HTTP); HTTP = null; LogFormater.Info("[WIKI] Done with area"); @@ -350,9 +346,27 @@ namespace BetterSecondBot.WikiMake sb.Append("

[[COMMAND]]

"); sb.Append("[[URLENDPOINT]]/[[WORKSPACE]]/[[COMMAND]]/[[URLADDON]]
"); sb.Append("Method: [[APIMETHOD]]"); - sb.Append("
"); - sb.Append("[[HELP]]"); + sb.Append("
OR
"); Dictionary> values = HTTP.getCommandArgs(workspace, c); + sb.Append("[[COMMAND]]"); + string addon = ""; + List argsim = new List(values.Keys); + argsim.Remove("token"); + if(argsim.Count > 0) + { + sb.Append("|||"); + } + foreach (string entry in argsim) + { + sb.Append(addon); + sb.Append("{"); + sb.Append(entry); + sb.Append("}"); + addon = "~#~"; + } + sb.Append("

"); + sb.Append("[[HELP]]"); + int ValueCount = values.Count; if (ValueCount > 0) @@ -413,7 +427,7 @@ namespace BetterSecondBot.WikiMake StringBuilder sb = new StringBuilder(); sb.Append(html_header); sb.Append("

Interface:"); - sb.Append("HTTP"); + sb.Append("Commands"); sb.Append("


"); sb.Append("

Build: "); sb.Append(buildVersion); @@ -452,7 +466,7 @@ namespace BetterSecondBot.WikiMake sb.Append("

Build: "); sb.Append(buildVersion); sb.Append("


"); - sb.Append("
"); + sb.Append("
CommandMin args
"); foreach (string c in HTTP.getEndpointCommands(workspace)) { int args = HTTP.getCommandArgCount(workspace, c); @@ -462,7 +476,7 @@ namespace BetterSecondBot.WikiMake sb.Append(".html'>"); sb.Append(c); sb.Append(""); } sb.Append("
CommandMin args (+1 for HTTP)
"); - sb.Append(args.ToString()); + sb.Append((args-1).ToString()); sb.Append("
"); @@ -481,8 +495,6 @@ namespace BetterSecondBot.WikiMake public class HTTPendpoint { protected List endpoints = new List(); - - public void createEndpoint(string name, Type Api) { Endpoint Endpoint = new Endpoint(); @@ -521,7 +533,7 @@ namespace BetterSecondBot.WikiMake } if (httpverb != null) { - C.name = M.Name.ToLowerInvariant(); + C.name = M.Name; C.type = "Post"; C.about = "Http interface command about missing"; if (About != null) @@ -553,13 +565,11 @@ namespace BetterSecondBot.WikiMake } public HTTPendpoint() { - createEndpoint("core", typeof(HttpApiCore)); - createEndpoint("inventory", typeof(HTTP_Inventory)); - createEndpoint("im", typeof(HttpApiIM)); - createEndpoint("groups", typeof(HTTP_Group)); - createEndpoint("chat", typeof(HTTP_Chat)); - createEndpoint("parcel", typeof(HTTP_Parcel)); - createEndpoint("estate", typeof(HTTP_Estate)); + Dictionary commandmodules = http_commands_helper.getCommandModules(); + foreach (KeyValuePair entry in commandmodules) + { + createEndpoint(entry.Key, entry.Value); + } } public string getCommandMethod(string endpoint, string command) diff --git a/Core/HttpService/Animation.cs b/Core/Commands/Animation.cs similarity index 92% rename from Core/HttpService/Animation.cs rename to Core/Commands/Animation.cs index b5dcec8..5ee1267 100644 --- a/Core/HttpService/Animation.cs +++ b/Core/Commands/Animation.cs @@ -24,7 +24,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/AddToAllowAnimations/{avatar}/{token}")] public object AddToAllowAnimations(string avatar, string token) { - if (tokens.Allow(token, "animation", "addtoallowanimations", getClientIP()) == false) + if (tokens.Allow(token, "animation", "addtoallowanimations", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -49,7 +49,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/PlayGesture/{gesture}/{token}")] public object PlayGesture(string gesture, string token) { - if (tokens.Allow(token, "animation", "gesture", getClientIP()) == false) + if (tokens.Allow(token, "animation", "gesture", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -67,7 +67,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/ResetAnimations/{token}")] public object ResetAnimations(string token) { - if (tokens.Allow(token, "animation", "resetanimations", getClientIP()) == false) + if (tokens.Allow(token, "animation", "resetanimations", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } diff --git a/Core/HttpService/Avatars.cs b/Core/Commands/Avatars.cs similarity index 93% rename from Core/HttpService/Avatars.cs rename to Core/Commands/Avatars.cs index ecba2f6..a1df14d 100644 --- a/Core/HttpService/Avatars.cs +++ b/Core/Commands/Avatars.cs @@ -22,7 +22,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/NearmeWithDetails/{token}")] public object NearmeWithDetails(string token) { - if (tokens.Allow(token, "avatars", "nearmewithdetails", getClientIP()) == false) + if (tokens.Allow(token, "avatars", "nearmewithdetails", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -55,7 +55,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Nearme/{token}")] public object Nearme(string token) { - if (tokens.Allow(token, "avatars", "nearme", getClientIP()) == false) + if (tokens.Allow(token, "avatars", "nearme", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } diff --git a/Core/HttpService/Chat.cs b/Core/Commands/Chat.cs similarity index 86% rename from Core/HttpService/Chat.cs rename to Core/Commands/Chat.cs index db58aab..0f832ef 100644 --- a/Core/HttpService/Chat.cs +++ b/Core/Commands/Chat.cs @@ -21,11 +21,11 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/LocalChatHistory/{token}")] public object LocalChatHistory(string token) { - if (tokens.Allow(token, "chat", "localchathistory", getClientIP()) == true) + if (tokens.Allow(token, "chat", "localchathistory", handleGetClientIP()) == false) { - return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory())); + return Failure("Token not accepted"); } - return BasicReply("Token not accepted"); + return BasicReply(JsonConvert.SerializeObject(bot.getLocalChatHistory())); } [About("sends a message to localchat")] @@ -37,7 +37,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Say/{channel}/{token}")] public object Say(string channel,[FormField] string message,string token) { - if (tokens.Allow(token, "chat", "localchatsay", getClientIP()) == false) + if (tokens.Allow(token, "chat", "localchatsay", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -67,7 +67,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/IM/{avatar}/{token}")] public object IM(string avatar, [FormField] string message, string token) { - if (tokens.Allow(token, "chat", "im", getClientIP()) == false) + if (tokens.Allow(token, "chat", "im", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } diff --git a/Core/HttpService/Core.cs b/Core/Commands/Core.cs similarity index 54% rename from Core/HttpService/Core.cs rename to Core/Commands/Core.cs index ac83d88..85db105 100644 --- a/Core/HttpService/Core.cs +++ b/Core/Commands/Core.cs @@ -9,18 +9,13 @@ using EmbedIO.WebApi; using System; using System.Collections.Generic; using Newtonsoft.Json; +using System.Threading; namespace BetterSecondBot.HttpService { - public class HttpApiCore : WebApiControllerWithTokens + public class HTTP_Core : WebApiControllerWithTokens { - - protected JsonConfig config; - public HttpApiCore(JsonConfig myconfig, SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) - { - config = myconfig; - } - + public HTTP_Core(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } [About("Requests a new token (Vaild for 10 mins)
to use with all other requests")] [NeedsToken(false)] @@ -39,23 +34,17 @@ namespace BetterSecondBot.HttpService } if((dif < 30) && (dif > -30)) { - var raw = now.ToString() + config.Security_WebUIKey; + var raw = now.ToString() + bot.getMyConfig.Security_WebUIKey; string hash = helpers.GetSHA1(raw).Substring(0, 10); if (hash == authcode) { - string newtoken = tokens.CreateToken(getClientIP()); + string newtoken = tokens.CreateToken(handleGetClientIP()); if(newtoken != null) return BasicReply(newtoken); } } return Failure("Authcode not accepted"); } - - - - - - [About("Used to check HTTP connections")] [ReturnHints("world")] [NeedsToken(false)] @@ -65,6 +54,23 @@ namespace BetterSecondBot.HttpService return BasicReply("world"); } + [About("Delays a thead by X ms
Mostly pointless but good if your doing custom commands")] + [ReturnHints("Invaild amount")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/Delay/{amount}/{token}")] + public object Delay(string amount,string token) + { + if (tokens.Allow(token, "core", "Delay", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if(int.TryParse(amount,out int amountvalue) == false) + { + return Failure("Invaild amount"); + } + Thread.Sleep(amountvalue); + return BasicReply("Ok"); + } [About("Removes the given token from the accepted token pool")] [ReturnHints("Failed to remove token")] @@ -72,44 +78,11 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/LogoutUI/{token}")] public object LogoutUI(string token) { - if (tokens.Allow(token, "core", "LogoutUI", getClientIP()) == true) + if (tokens.Allow(token, "core", "LogoutUI", handleGetClientIP()) == false) { - return tokens.Expire(token); + return Failure("Token not accepted"); } - return Failure("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")] - [ReturnHints("Auth not accepted")] - [ReturnHints("Failed")] - [Route(HttpVerbs.Post, "/Command/{token}")] - public async Task Command(string token) - { - if (tokens.Allow(token, "core", "command", getClientIP()) == true) - { - CommandLibCall data = await HttpContext.GetRequestDataAsync(); - string compressedArgs = string.Join("~#~", data.Args); - string raw = data.Command + compressedArgs; - string cooked = helpers.GetSHA1(raw + config.Security_SignedCommandkey); - if (cooked == data.AuthCode) - { - bool status = bot.GetCommandsInterface.Call(data.Command.ToLowerInvariant(), compressedArgs, UUID.Zero, "~#~"); - if (status == true) - { - return BasicReply("accepted"); - } - return Failure("Failed"); - } - return Failure("Auth not accepted"); - } - return Failure("Token not accepted"); + return tokens.Expire(token); } } diff --git a/Core/HttpService/Dialogs.cs b/Core/Commands/Dialogs.cs similarity index 91% rename from Core/HttpService/Dialogs.cs rename to Core/Commands/Dialogs.cs index e016faa..1eadfa6 100644 --- a/Core/HttpService/Dialogs.cs +++ b/Core/Commands/Dialogs.cs @@ -26,7 +26,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/DialogRelay/{target}/{token}")] public object DialogRelay(string target,string token) { - if (tokens.Allow(token, "dialogs", "DialogRelay", getClientIP()) == false) + if (tokens.Allow(token, "dialogs", "DialogRelay", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -65,7 +65,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/DialogResponce/{dialogid}/{buttontext}/{token}")] public object DialogResponce(string dialogid, string buttontext, string token) { - if (tokens.Allow(token, "dialogs", "DialogResponce", getClientIP()) == false) + if (tokens.Allow(token, "dialogs", "DialogResponce", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -83,7 +83,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/DialogTrack/{status}/{token}")] public object DialogTrack(string status, string token) { - if (tokens.Allow(token, "dialogs", "DialogTrack", getClientIP()) == false) + if (tokens.Allow(token, "dialogs", "DialogTrack", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } diff --git a/Core/HttpService/Discord.cs b/Core/Commands/Discord.cs similarity index 96% rename from Core/HttpService/Discord.cs rename to Core/Commands/Discord.cs index da52785..59ff225 100644 --- a/Core/HttpService/Discord.cs +++ b/Core/Commands/Discord.cs @@ -30,7 +30,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_AddRole/{serverid}/{roleid}/{memberid}/{token}")] public object Discord_AddRole(string serverid,string roleid,string memberid,string token) { - if (tokens.Allow(token, "discord", "Discord_AddRole", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_AddRole", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -51,7 +51,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Discord_BanMember/{serverid}/{memberid}/{token}")] public object Discord_BanMember(string serverid, string memberid, [FormField] string why, string token) { - if (tokens.Allow(token, "discord", "Discord_BanMember", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_BanMember", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -74,7 +74,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_BulkClear_Messages/{serverid}/{memberid}/{token}")] public object Discord_BulkClear_Messages(string serverid, string memberid, string token) { - if (tokens.Allow(token, "discord", "Discord_BulkClear_Messages", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_BulkClear_Messages", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -94,7 +94,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Discord_Dm_Member/{serverid}/{memberid}/{token}")] public object Discord_Dm_Member(string serverid, string memberid, [FormField] string message, string token) { - if (tokens.Allow(token, "discord", "Discord_Dm_Member", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_Dm_Member", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -114,7 +114,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_MembersList/{serverid}/{token}")] public object Discord_MembersList(string serverid, string token) { - if (tokens.Allow(token, "discord", "Discord_MembersList", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_MembersList", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -135,7 +135,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Discord_MembersList/{serverid}/{tts}/{token}")] public object Discord_MessageChannel(string serverid, string channelid, string tts, [FormField] string message, string token) { - if (tokens.Allow(token, "discord", "Discord_MessageChannel", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_MessageChannel", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -159,7 +159,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_MuteMember/{serverid}/{memberid}/{mode}/{token}")] public object Discord_MuteMember(string serverid, string memberid, string mode, string token) { - if (tokens.Allow(token, "discord", "Discord_MuteMember", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_MuteMember", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -179,7 +179,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_Role_GetSettings/{serverid}/{roleid}/{token}")] public object Discord_Role_GetSettings(string serverid, string roleid, string token) { - if (tokens.Allow(token, "discord", "Discord_Role_GetSettings", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_Role_GetSettings", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -200,7 +200,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Discord_Role_UpdatePerms/{serverid}/{roleid}/{token}")] public object Discord_Role_UpdatePerms(string serverid, string roleid, [FormField] string flagscsv, string token) { - if (tokens.Allow(token, "discord", "Discord_Role_UpdatePerms", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_Role_UpdatePerms", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -220,7 +220,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_RoleCreate/{serverid}/{role}/{token}")] public object Discord_RoleCreate(string serverid, string role, string token) { - if (tokens.Allow(token, "discord", "Discord_RoleCreate", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_RoleCreate", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -238,7 +238,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_RoleList/{serverid}/{token}")] public object Discord_RoleList(string serverid, string token) { - if (tokens.Allow(token, "discord", "Discord_RoleList", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_RoleList", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -256,7 +256,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_RoleRemove/{serverid}/{roleid}/{token}")] public object Discord_RoleRemove(string serverid, string roleid, string token) { - if (tokens.Allow(token, "discord", "Discord_RoleRemove", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_RoleRemove", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -274,7 +274,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Discord_TextChannels_List/{serverid}/{roleid}/{token}")] public object Discord_TextChannels_List(string serverid, string token) { - if (tokens.Allow(token, "discord", "Discord_TextChannels_List", getClientIP()) == false) + if (tokens.Allow(token, "discord", "Discord_TextChannels_List", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/Estate.cs b/Core/Commands/Estate.cs similarity index 91% rename from Core/HttpService/Estate.cs rename to Core/Commands/Estate.cs index 9b84b46..3dfc990 100644 --- a/Core/HttpService/Estate.cs +++ b/Core/Commands/Estate.cs @@ -31,7 +31,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/SimRestart/{delay}/{mode}/{token}")] public object SimRestart(string delay, string mode, string token) { - if (tokens.Allow(token, "estate", "SimMessage", getClientIP()) == false) + if (tokens.Allow(token, "estate", "SimMessage", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -63,7 +63,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/SimMessage/{token}")] public object SimMessage([FormField] string message, string token) { - if (tokens.Allow(token, "estate", "SimMessage", getClientIP()) == false) + if (tokens.Allow(token, "estate", "SimMessage", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -86,7 +86,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetSimTexture/{regionname}/{token}")] public object GetSimTexture(string regionname, string token) { - if (tokens.Allow(token, "estate", "GetSimTexture", getClientIP()) == false) + if (tokens.Allow(token, "estate", "GetSimTexture", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -103,7 +103,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/EstateParcelReclaim/{token}")] public Object EstateParcelReclaim(string token) { - if (tokens.Allow(token, "estate", "EstateParcelReclaim", getClientIP()) == false) + if (tokens.Allow(token, "estate", "EstateParcelReclaim", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -122,7 +122,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetSimGlobalPos/{regionname}/{token}")] public Object GetSimGlobalPos(string regionname, string token) { - if (tokens.Allow(token, "estate", "GetSimGlobalPos", getClientIP()) == false) + if (tokens.Allow(token, "estate", "GetSimGlobalPos", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -142,7 +142,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetEstateBanList/{token}")] public Object GetEstateBanList(string token) { - if (tokens.Allow(token, "estate", "banlist", getClientIP()) == false) + if (tokens.Allow(token, "estate", "banlist", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -162,7 +162,7 @@ namespace BetterSecondBot.HttpService public Object UpdateEstateBanlist(string avatar, string mode, string global, string token) { - if (tokens.Allow(token, "estate", "banlist-add", getClientIP()) == false) + if (tokens.Allow(token, "estate", "banlist-add", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/Friends.cs b/Core/Commands/Friends.cs similarity index 94% rename from Core/HttpService/Friends.cs rename to Core/Commands/Friends.cs index fdf2d7f..405ba6e 100644 --- a/Core/HttpService/Friends.cs +++ b/Core/Commands/Friends.cs @@ -21,7 +21,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Friendslist/{token}")] public object Friendslist(string token) { - if (tokens.Allow(token, "friends", "Friendslist", getClientIP()) == true) + if (tokens.Allow(token, "friends", "Friendslist", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -39,7 +39,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/FriendFullPerms/{avatar}/{state}/{token}")] public object FriendFullPerms(string avatar, string state, string token) { - if (tokens.Allow(token, "friends", "FriendFullPerms", getClientIP()) == true) + if (tokens.Allow(token, "friends", "FriendFullPerms", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -78,7 +78,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/FriendRequest/{avatar}/{state}/{token}")] public object FriendRequest(string avatar, string state, string token) { - if (tokens.Allow(token, "friends", "FriendRequest", getClientIP()) == true) + if (tokens.Allow(token, "friends", "FriendRequest", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/Funds.cs b/Core/Commands/Funds.cs similarity index 91% rename from Core/HttpService/Funds.cs rename to Core/Commands/Funds.cs index 59f1f6b..ac72522 100644 --- a/Core/HttpService/Funds.cs +++ b/Core/Commands/Funds.cs @@ -22,7 +22,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Balance/{token}")] public object Balance(string token) { - if (tokens.Allow(token, "funds", "Balance", getClientIP()) == true) + if (tokens.Allow(token, "funds", "Balance", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -42,7 +42,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/PayAvatar/{avatar}/{amount}/{token}")] public object PayAvatar(string avatar, string amount, string token) { - if (tokens.Allow(token, "funds", "PayAvatar", getClientIP()) == false) + if (tokens.Allow(token, "funds", "PayAvatar", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -81,7 +81,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/PayObject/{object}/{primname}/{amount}/{token}")] public object PayObject(string objectuuid,string primname,string amount,string token) { - if (tokens.Allow(token, "funds", "PayObject", getClientIP()) == true) + if (tokens.Allow(token, "funds", "PayObject", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/Group.cs b/Core/Commands/Group.cs similarity index 91% rename from Core/HttpService/Group.cs rename to Core/Commands/Group.cs index f44b764..9a80d2a 100644 --- a/Core/HttpService/Group.cs +++ b/Core/Commands/Group.cs @@ -28,7 +28,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/IsGroupMember/{group}/{avatar}/{token}")] public object IsGroupMember(string group, string avatar, string token) { - if (tokens.Allow(token, "groups", "IsGroupMember", getClientIP()) == true) + if (tokens.Allow(token, "groups", "IsGroupMember", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -64,7 +64,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetGroupMembers/{group}/{token}")] public object GetGroupMembers(string group, string token) { - if (tokens.Allow(token, "groups", "GetGroupMembers", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GetGroupMembers", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -96,7 +96,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupEject/{group}/{avatar}/{token}")] public object GroupEject(string group, string avatar, string token) { - if (tokens.Allow(token, "groups", "GroupEject", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupEject", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -141,7 +141,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupAddRole/{group}/{avatar}/{role}/{token}")] public object GroupAddRole(string group, string avatar, string role, string token) { - if (tokens.Allow(token, "groups", "GroupAddRole", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupAddRole", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -190,7 +190,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupInvite/{group}/{avatar}/{role}/{token}")] public object GroupInvite(string group, string avatar, string role, string token) { - if (tokens.Allow(token, "groups", "GroupInvite", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupInvite", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -241,7 +241,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Groupnotice/{group}/{token}")] public object Groupnotice(string group, [FormField] string title, [FormField] string message, string token) { - if (tokens.Allow(token, "groups", "Groupnotice", getClientIP()) == true) + if (tokens.Allow(token, "groups", "Groupnotice", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -279,7 +279,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupActiveTitle/{group}/{token}")] public object GroupActiveTitle(string group, string role, string token) { - if (tokens.Allow(token, "groups", "GroupActiveTitle", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupActiveTitle", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -307,7 +307,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupActiveGroup/{group}/{token}")] public object GroupActiveGroup(string group, string role, string token) { - if (tokens.Allow(token, "groups", "GroupActiveTitle", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupActiveTitle", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -337,7 +337,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Groupnotice/{group}/{attachment}/{token}")] public object GroupnoticeWithAttachment(string group, [FormField] string title, [FormField] string message, string attachment, string token) { - if (tokens.Allow(token, "groups", "GroupnoticeWithAttachment", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupnoticeWithAttachment", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -376,7 +376,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetGroupList/{token}")] public object GetGroupList(string token) { - if (tokens.Allow(token, "groups", "GetGroupList", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GetGroupList", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -397,7 +397,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetGroupRoles/{group}/{token}")] public object GetGroupRoles(string group, string token) { - if (tokens.Allow(token, "groups", "GetGroupRoles", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GetGroupRoles", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -446,7 +446,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupchatListAllUnreadGroups/{token}")] public object GroupchatListAllUnreadGroups(string token) { - if (tokens.Allow(token, "groups", "GroupchatListAllUnreadGroups", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatListAllUnreadGroups", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -462,7 +462,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupchatGroupHasUnread/{group}/{token}")] public object GroupchatGroupHasUnread(string group,string token) { - if (tokens.Allow(token, "groups", "GroupchatListAllUnreadGroups", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatListAllUnreadGroups", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -484,11 +484,11 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupchatAnyUnread/{token}")] public object haveunreadgroupchat(string token) { - if (tokens.Allow(token, "groups", "GroupchatAnyUnread", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatAnyUnread", handleGetClientIP()) == false) { - return BasicReply(bot.HasUnreadGroupchats().ToString()); + return Failure("Token not accepted"); } - return Failure("Token not accepted"); + return BasicReply(bot.HasUnreadGroupchats().ToString()); } [About("Clears all group chat buffers at once")] @@ -496,12 +496,12 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupchatClearAll/{token}")] public object GroupchatClearAll(string token) { - if (tokens.Allow(token, "groups", "GroupchatClearAll", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatClearAll", handleGetClientIP()) == false) { - bot.ClearAllGroupchat(); - return BasicReply("ok"); + return Failure("Token not accepted"); } - return Failure("Token not accepted"); + bot.ClearAllGroupchat(); + return BasicReply("ok"); } [About("fetchs the groupchat history")] @@ -511,15 +511,15 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GroupchatHistory/{group}/{token}")] public object GroupchatHistory(string group, string token) { - if (tokens.Allow(token, "groups", "GroupchatHistory", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GroupchatHistory", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(group, out UUID groupUUID) == false) { - if (UUID.TryParse(group, out UUID groupUUID) == true) - { - return BasicReply(JsonConvert.SerializeObject(bot.GetGroupchat(groupUUID))); - } return Failure("Group UUID invaild"); } - return Failure("Token not accepted"); + return BasicReply(JsonConvert.SerializeObject(bot.GetGroupchat(groupUUID))); } [About("sends a message to the groupchat")] @@ -532,7 +532,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/Groupchat/{group}/{token}")] public object Groupchat(string group, [FormField] string message, string token) { - if (tokens.Allow(token, "groups", "Groupchat", getClientIP()) == true) + if (tokens.Allow(token, "groups", "Groupchat", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/Commands/Helpers/delay.cs b/Core/Commands/Helpers/delay.cs deleted file mode 100644 index 3dc8c4b..0000000 --- a/Core/Commands/Helpers/delay.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Text; -using System.Threading; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Helpers -{ - public class Delay : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Number" }; } } - public override string[] ArgHints { get { return new[] { "Delay in MS" }; } } - public override string Helpfile { get { return "Delays a thead by X ms
Mostly pointless but good if your doing custom commands"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (int.TryParse(args[0], out int delayms) == true) - { - Thread.Sleep(delayms); - return true; - } - else - { - return Failed("Delay is not vaild"); - } - } - return false; - } - } -} diff --git a/Core/HttpService/Home.cs b/Core/Commands/Home.cs similarity index 93% rename from Core/HttpService/Home.cs rename to Core/Commands/Home.cs index c8104a2..dc26b5e 100644 --- a/Core/HttpService/Home.cs +++ b/Core/Commands/Home.cs @@ -21,7 +21,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GoHome/{token}")] public object GoHome(string group, string token) { - if (tokens.Allow(token, "groups", "GetGroupMembers", getClientIP()) == true) + if (tokens.Allow(token, "groups", "GetGroupMembers", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/Im.cs b/Core/Commands/Im.cs similarity index 81% rename from Core/HttpService/Im.cs rename to Core/Commands/Im.cs index ee0d79e..02d5aaf 100644 --- a/Core/HttpService/Im.cs +++ b/Core/Commands/Im.cs @@ -11,16 +11,16 @@ using Newtonsoft.Json; namespace BetterSecondBot.HttpService { - public class HttpApiIM : WebApiControllerWithTokens + public class HTTP_IM : WebApiControllerWithTokens { - public HttpApiIM(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + public HTTP_IM(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) { - if (tokens.Allow(token, "im", "chatwindows", getClientIP()) == false) + if (tokens.Allow(token, "im", "chatwindows", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -32,7 +32,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/listwithunread/{token}")] public object listwithunread(string group, string token) { - if (tokens.Allow(token, "im", "listwithunread", getClientIP()) == false) + if (tokens.Allow(token, "im", "listwithunread", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -52,7 +52,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/haveunreadims/{token}")] public object haveunreadims(string token) { - if (tokens.Allow(token, "im", "haveunreadims", getClientIP()) == false) + if (tokens.Allow(token, "im", "haveunreadims", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -75,7 +75,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/getimchat/{window}/{token}")] public object getimchat(string window, string token) { - if (tokens.Allow(token, "im", "getimchat", getClientIP()) == false) + if (tokens.Allow(token, "im", "getimchat", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } diff --git a/Core/Commands/Info.cs b/Core/Commands/Info.cs new file mode 100644 index 0000000..19a4c18 --- /dev/null +++ b/Core/Commands/Info.cs @@ -0,0 +1,117 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Info : WebApiControllerWithTokens + { + public HTTP_Info(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Fetchs the current bot")] + [ReturnHints("The build ID of the bot")] + [Route(HttpVerbs.Get, "/Version/{token}")] + public object Version(string token) + { + if (tokens.Allow(token, "info", "Version", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + return BasicReply(bot.MyVersion); + + } + + [About("Fetchs the name of the bot")] + [ReturnHints("Firstname Lastname")] + [Route(HttpVerbs.Get, "/Name/{token}")] + public object Name(string token) + { + if (tokens.Allow(token, "info", "Name", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + return BasicReply(bot.GetClient.Self.FirstName + " " + bot.GetClient.Self.LastName); + } + + [About("Fetchs the current parcels name")] + [ReturnHints("Parcelname")] + [ReturnHints("Error parcel not found")] + [ReturnHints("Error not in a sim")] + [Route(HttpVerbs.Get, "/ParcelName/{token}")] + public object ParcelName(string token) + { + if (tokens.Allow(token, "info", "ParcelName", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim == null) + { + return Failure("Error not in a sim"); + } + int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); + if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == false) + { + return Failure("Error parcel not found"); + } + return BasicReply(bot.GetClient.Network.CurrentSim.Parcels[localid].Name); + } + + [About("Requests the current unixtime at the bot")] + [ReturnHints("Unixtime")] + [Route(HttpVerbs.Get, "/UnixTimeNow/{token}")] + public object UnixTimeNow(string token) + { + if (tokens.Allow(token, "info", "UnixTimeNow", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + return BasicReply(helpers.UnixTimeNow().ToString()); + } + + [About("Fetchs the current region name")] + [ReturnHints("Regionname")] + [ReturnHints("Error not in a sim")] + [Route(HttpVerbs.Get, "/SimName/{token}")] + public object SimName(string token) + { + if (tokens.Allow(token, "info", "SimName", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim == null) + { + return Failure("Error not in a sim"); + } + return BasicReply(bot.GetClient.Network.CurrentSim.Name); + } + + [About("Fetchs the current location of the bot")] + [ReturnHints("array of X,Y,Z values")] + [ReturnHints("Error not in a sim")] + [Route(HttpVerbs.Get, "/GetPosition/{token}")] + public object GetPosition(string token) + { + if (tokens.Allow(token, "info", "GetPosition", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bot.GetClient.Network.CurrentSim == null) + { + return Failure("Error not in a sim"); + } + 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)); + } + } +} diff --git a/Core/Commands/Inventory.cs b/Core/Commands/Inventory.cs new file mode 100644 index 0000000..2c787d1 --- /dev/null +++ b/Core/Commands/Inventory.cs @@ -0,0 +1,441 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using System.Linq; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Inventory : WebApiControllerWithTokens + { + public HTTP_Inventory(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) + { + if (tokens.Allow(token, "inventory", "RezObject", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + return Failure("Broken awaiting repairs"); + } + + + [About("renames a folder or inventory item")] + [ReturnHints("ok")] + [ReturnHints("invaild item uuid")] + [ReturnHints("Item name is to short")] + [ReturnHints("Unable to find inventory item")] + [ArgHints("item", "URLARG", "UUID of item/folder to name")] + [ArgHints("newname", "Text", "What we are changing it to")] + [Route(HttpVerbs.Post, "/RenameInventory/{item}/{token}")] + public object RenameInventory(string item, string token, [FormField] string newname) + { + if (tokens.Allow(token, "inventory", "RenameInventory", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(item, out UUID target) == false) + { + return Failure("invaild item uuid"); + } + if (newname.Length < 3) + { + return Failure("Item name is to short"); + } + InventoryItem realitem = HelperInventory.getItemByInventoryUUID(bot, target); + if (realitem == null) + { + return Failure("Unable to find inventory item"); + } + realitem.Name = newname; + bot.GetClient.Inventory.RequestUpdateItem(realitem); + return BasicReply("Ok"); + } + + [About("Attempts to Remove the given inventory item")] + [ReturnHints("ok")] + [ReturnHints("invaild item uuid")] + [ArgHints("item", "URLARG", "UUID of item")] + [Route(HttpVerbs.Get, "/DeleteInventoryItem/{item}/{token}")] + public object DeleteInventoryItem(string item, string token) + { + if (tokens.Allow(token, "inventory", "DeleteInventoryItem", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(item, out UUID target) == false) + { + return Failure("invaild item uuid"); + } + bot.GetClient.Inventory.Remove(new List() { target }, new List()); + return BasicReply("Ok"); + } + + [About("Attempts to Remove the given inventory folder")] + [ReturnHints("ok")] + [ReturnHints("invaild folder uuid")] + [ArgHints("folder", "URLARG", "UUID of folder")] + [Route(HttpVerbs.Get, "/DeleteInventoryFolder/{folder}/{token}")] + public object DeleteInventoryFolder(string folder, string token) + { + if (tokens.Allow(token, "inventory", "DeleteInventoryFolder", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(folder, out UUID target) == false) + { + return Failure("invaild folder uuid"); + } + bot.GetClient.Inventory.Remove(new List(), new List() { target }); + return BasicReply("Ok"); + } + + [About("Attempts to attach the given inventory item")] + [ReturnHints("ok")] + [ReturnHints("invaild item uuid")] + [ArgHints("item", "URLARG", "UUID of item")] + [Route(HttpVerbs.Get, "/Attach/{item}/{token}")] + public object Attach(string item, string token) + { + if (tokens.Allow(token, "inventory", "Attach", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if(UUID.TryParse(item,out UUID itemuuid) == false) + { + return Failure("invaild item uuid"); + } + InventoryItem realitem = HelperInventory.getItemByInventoryUUID(bot, itemuuid); + bot.GetClient.Appearance.AddAttachments(new List() { realitem }, false, false); + return BasicReply("Ok"); + } + + [About("Attempts to Remove the given inventory folder")] + [ReturnHints("ok")] + [ReturnHints("invaild item uuid")] + [ArgHints("item", "URLARG", "UUID of item")] + [Route(HttpVerbs.Get, "/Detach/{item}/{token}")] + public object Detach(string item, string token) + { + if (tokens.Allow(token, "inventory", "Detach", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(item, out UUID itemuuid) == false) + { + return Failure("invaild item uuid"); + } + InventoryItem realitem = HelperInventory.getItemByInventoryUUID(bot, itemuuid); + bot.GetClient.Appearance.RemoveFromOutfit(realitem); + return BasicReply("Ok"); + } + + [About("Replaces the current avatar outfit with the Clothing/[NAME] folder
Please note: This does not use the outfits folder!
Please do not use links in the folder!")] + [ReturnHints("ok")] + [ReturnHints("Named folder value is empty")] + [ReturnHints("Cant find Clothing folder")] + [ReturnHints("Cant find target folder")] + [ReturnHints("target folder is empty or so full I cant get it in 5 secs...")] + [ArgHints("name", "URLARG", "Name of the folder")] + [Route(HttpVerbs.Get, "/Outfit/{name}/{token}")] + public object Outfit(string name, string token) + { + if (tokens.Allow(token, "inventory", "Outfit", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (helpers.notempty(name) == false) + { + return Failure("Named folder value is empty"); + } + // uses the Clothing folder + // must be a full outfit (shapes/eyes ect) + InventoryFolder AA = bot.GetClient.Inventory.Store.RootFolder; + List T = bot.GetClient.Inventory.Store.GetContents(AA); + AA = null; + foreach (InventoryBase R in T) + { + if (R.Name == "Clothing") + { + AA = (InventoryFolder)R; + break; + } + } + if (AA == null) + { + return Failure("Cant find Clothing folder"); + } + T = bot.GetClient.Inventory.Store.GetContents(AA); + AA = null; + foreach (InventoryBase R in T) + { + if (R.Name == name) + { + AA = (InventoryFolder)R; + break; + } + } + if (AA == null) + { + return Failure("Cant find target folder"); + } + List contents = bot.GetClient.Inventory.FolderContents(AA.UUID, bot.GetClient.Self.AgentID, true, true, InventorySortOrder.ByName, 5 * 1000); + List wareables = new List(); + if (contents == null) + { + return Failure("target folder is empty or so full I cant get it in 5 secs..."); + } + foreach (InventoryBase item in contents) + { + if ((item is InventoryWearable) || (item is InventoryObject)) + { + wareables.Add((InventoryItem)item); + } + } + bot.GetClient.Appearance.ReplaceOutfit(wareables, false); + return BasicReply("ok"); + } + + + + [About("Searchs the notecards folder for notecards, any older than 31 days are deleted.
Depending on the number of notecards this might require multiple calls!")] + [ReturnHints("ok")] + [ReturnHints("Unable to find notecard folder")] + [Route(HttpVerbs.Get, "/InventoryPurgeNotecards/{token}")] + public object InventoryPurgeNotecards(string token) + { + if (tokens.Allow(token, "inventory", "InventoryPurgeNotecards", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + List T = bot.GetClient.Inventory.Store.GetContents(bot.GetClient.Inventory.Store.RootFolder); + InventoryBase NotecardFolder = null; + foreach (InventoryBase R in T) + { + if (R.Name == "Notecards") + { + NotecardFolder = R; + break; + } + } + if (NotecardFolder != null) + { + return Failure("Unable to find notecard folder"); + } + List purge_notecards = new List(); + List contents = bot.GetClient.Inventory.FolderContents(NotecardFolder.UUID, bot.GetClient.Self.AgentID, true, true, InventorySortOrder.ByDate, 40 * 1000); + foreach (InventoryBase C in contents) + { + InventoryItem A = (InventoryItem)C; + if (A.AssetType == AssetType.Notecard) + { + TimeSpan Dif = DateTime.Now - A.CreationDate; + if (Dif.Days >= 31) + { + purge_notecards.Add(C.UUID); + } + } + } + if (purge_notecards.Count() > 0) + { + bot.GetClient.Inventory.Remove(purge_notecards, new List()); + } + return BasicReply("Ok"); + } + + [About("converts a inventory uuid to a realworld uuid
Needed for texture preview")] + [ReturnHints("Asset UUID or UUID zero")] + [ReturnHints("Invaild item uuid")] + [ArgHints("item", "URLARG", "inventory level UUID of item")] + [Route(HttpVerbs.Get, "/getRealUUID/{item}/{token}")] + public object getRealUUID(string item, string token) + { + if (tokens.Allow(token, "inventory", "getRealUUID", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(item, out UUID itemUUID) == false) + { + return Failure("Invaild item uuid"); + } + UUID reply = HelperInventory.GetAssetUUID(bot, itemUUID); + return BasicReply(reply.ToString()); + } + + [About("sends a item to an avatar")] + [ReturnHints("ok")] + [ReturnHints("Failed")] + [ReturnHints("Invaild avatar uuid")] + [ReturnHints("Invaild item uuid")] + [ReturnHints("Unable to find item")] + [ArgHints("item", "URLARG", "UUID of item")] + [ArgHints("avatar", "URLARG", "a UUID or Firstname Lastname")] + [Route(HttpVerbs.Get, "/SendItem/{item}/{avatar}/{token}")] + public object SendItem(string item, string avatar, string token) + { + if (tokens.Allow(token, "inventory", "SendItem", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if(avataruuid == UUID.Zero) + { + return Failure("Invaild avatar uuid"); + } + if (UUID.TryParse(item, out UUID targetitem) == true) + { + return Failure("Invaild item uuid"); + } + InventoryItem itm = bot.GetClient.Inventory.FetchItem(targetitem, bot.GetClient.Self.AgentID, (3 * 1000)); + if (itm == null) + { + return Failure("Unable to find item"); + } + bot.GetClient.Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false); + return BasicReply("ok"); + } + + [About("Sends a folder to an avatar")] + [ReturnHints("ok")] + [ReturnHints("Failed")] + [ReturnHints("Invaild avatar uuid")] + [ReturnHints("Invaild folter uuid")] + [ReturnHints("Unable to find folder")] + [ArgHints("item", "URLARG", "UUID of item")] + [ArgHints("avatar", "URLARG", "a UUID or Firstname Lastname")] + [Route(HttpVerbs.Get, "/SendFolder/{folder}/{avatar}/{token}")] + public object SendFolder(string folder, string avatar, string token) + { + if (tokens.Allow(token, "inventory", "SendFolder", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar uuid"); + } + if (UUID.TryParse(folder, out UUID targetfolder) == true) + { + return Failure("Invaild folder uuid"); + } + InventoryBase FindFolderHelper = HelperInventory.FindFolder(bot, bot.GetClient.Inventory.Store.RootFolder, targetfolder); + if (FindFolderHelper == null) + { + return Failure("Unable to find folder"); + } + bot.GetClient.Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false); + return BasicReply("ok"); + } + + + + [About("Transfers a item [ARG 2] to a objects inventory [ARG 1] (And if set with the script running state [ARG 3])")] + [ReturnHints("Transfering running script")] + [ReturnHints("Transfering inventory")] + [ReturnHints("Invaild item uuid")] + [ReturnHints("Invaild object uuid")] + [ReturnHints("Unable to find inventory")] + [ReturnHints("Unable to find object")] + [ReturnHints("Invaild running")] + [ArgHints("item", "URLARG", "UUID of item")] + [ArgHints("object", "URLARG", "the uuid of the object")] + [ArgHints("running", "URLARG", "true if you wish the transfered script to be running otherwise false")] + + [Route(HttpVerbs.Get, "/TransferInventoryToObject/{item}/{objectuuid}/{running}/{token}")] + public object TransferInventoryToObject(string item, string objectuuid, string running, string token) + { + if (tokens.Allow(token, "inventory", "TransferInventoryToObject", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(item, out UUID itemuuid) == false) + { + return Failure("Invaild item uuid"); + } + if (UUID.TryParse(objectuuid, out UUID objectUUID) == false) + { + return Failure("Invaild object uuid"); + } + if (bool.TryParse(running, out bool runscript) == false) + { + return Failure("Invaild running"); + } + + InventoryItem itm = bot.GetClient.Inventory.FetchItem(itemuuid, bot.GetClient.Self.AgentID, (3 * 1000)); + if (itm == null) + { + return Failure("Unable to find inventory"); + } + Dictionary objects_copy = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); + KeyValuePair RealObject = new KeyValuePair(0,null); + foreach (KeyValuePair Obj in objects_copy) + { + if (Obj.Value.ID == objectUUID) + { + RealObject = Obj; + break; + } + } + if (RealObject.Value == null) + { + return Failure("Unable to find object"); + } + bool scriptState = runscript; + if (itm.AssetType != AssetType.LSLText) + { + scriptState = false; + } + if (itm.AssetType == AssetType.LSLText) + { + bot.GetClient.Inventory.CopyScriptToTask(RealObject.Key, itm, scriptState); + return BasicReply("Transfering script [state: "+scriptState.ToString()+"]"); + } + bot.GetClient.Inventory.UpdateTaskInventory(RealObject.Key, itm); + return BasicReply("Transfering inventory"); + } + + [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, "/InventoryFolders/{token}")] + public object InventoryFolders(string token) + { + if (tokens.Allow(token, "inventory", "InventoryFolders", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + string reply = HelperInventory.MapFolderJson(bot); + if (reply != null) return BasicReply(reply); + return Failure("Error"); + } + + [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, "/InventoryContents/{folderUUID}/{token}")] + public object InventoryContents(string folderUUID, string token) + { + if (tokens.Allow(token, "inventory", "InventoryContents", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (UUID.TryParse(folderUUID, out UUID folder) == false) + { + return Failure("Invaild folder UUID"); + } + return BasicReply(HelperInventory.MapFolderInventoryJson(bot, folder)); + } + } +} diff --git a/Core/Commands/Inventory/DeleteInventory.cs b/Core/Commands/Inventory/DeleteInventory.cs deleted file mode 100644 index 88e58b3..0000000 --- a/Core/Commands/Inventory/DeleteInventory.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class DeleteInventoryItem : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "UUID" }; } } - public override string[] ArgHints { get { return new[] { "inventory UUID" }; } } - public override string Helpfile { get { return "Attempts to Remove the given inventory item"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID removeme) == true) - { - bot.GetClient.Inventory.Remove(new List() { removeme }, new List()); - return true; - } - return Failed("Invaild inventory UUID"); - } - return false; - } - } - - public class DeleteInventoryFolder : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "UUID" }; } } - public override string[] ArgHints { get { return new[] { "inventory UUID" }; } } - public override string Helpfile { get { return "Attempts to Remove the given inventory folder"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID removeme) == true) - { - bot.GetClient.Inventory.Remove(new List(), new List() { removeme }); - return true; - } - return Failed("Invaild inventory UUID"); - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/InventoryPurgeNotecards.cs b/Core/Commands/Inventory/InventoryPurgeNotecards.cs deleted file mode 100644 index 6aa7b04..0000000 --- a/Core/Commands/Inventory/InventoryPurgeNotecards.cs +++ /dev/null @@ -1,55 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class InventoryPurgeNotecards : CoreCommand - { - public override string Helpfile { get { return "Searchs the notecards folder for notecards, any older than 31 days are deleted.
Depending on the number of notecards this might require multiple calls!"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - List T = bot.GetClient.Inventory.Store.GetContents(bot.GetClient.Inventory.Store.RootFolder); - InventoryBase NotecardFolder = null; - foreach (InventoryBase R in T) - { - if(R.Name == "Notecards") - { - NotecardFolder = R; - break; - } - } - if(NotecardFolder != null) - { - List purge_notecards = new List(); - List contents = bot.GetClient.Inventory.FolderContents(NotecardFolder.UUID, bot.GetClient.Self.AgentID, true, true, InventorySortOrder.ByDate, 40 * 1000); - foreach(InventoryBase C in contents) - { - InventoryItem A = (InventoryItem)C; - if(A.AssetType == AssetType.Notecard) - { - TimeSpan Dif = DateTime.Now - A.CreationDate; - if(Dif.Days >= 31) - { - purge_notecards.Add(C.UUID); - } - } - } - if(purge_notecards.Count() > 0) - { - bot.GetClient.Inventory.Remove(purge_notecards, new List()); - } - return true; - } - else - { - return Failed("Unable to find notecard folder"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/RenameInventory.cs b/Core/Commands/Inventory/RenameInventory.cs deleted file mode 100644 index a10f430..0000000 --- a/Core/Commands/Inventory/RenameInventory.cs +++ /dev/null @@ -1,41 +0,0 @@ -using BetterSecondBot.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class RenameInventory : CoreCommand_3arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "UUID", "Text" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP", "Inventory UUID", "New name" }; } } - public override string Helpfile - { - get - { - return "Renames an inventory item to something else."; - } - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[1], out UUID target) == true) - { - if (args[2].Length >= 1) - { - InventoryItem item = HelperInventory.getItemByInventoryUUID(bot, target); - if (item != null) - { - item.Name = args[2]; - bot.GetClient.Inventory.RequestUpdateItem(item); - return true; - } - return Failed("Unable to get base item"); - } - return Failed("Item name is to short"); - } - return Failed("Unable to get UUID from target"); - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/attach.cs b/Core/Commands/Inventory/attach.cs deleted file mode 100644 index d2e46f1..0000000 --- a/Core/Commands/Inventory/attach.cs +++ /dev/null @@ -1,80 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class Attach : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Text", "Text" }; } } - public override string[] ArgHints { get { return new[] { "Sub folder", "Item name" }; } } - public override string Helpfile { get { return "Attachs a item found inside the attachments / [ARG1] folder
that matchs the item name [ARG2]"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - // attachments/[arg1]/[arg2] - // arg1 = sub folder - // arg2 = itemname - InventoryFolder AA = bot.GetClient.Inventory.Store.RootFolder; - List T = bot.GetClient.Inventory.Store.GetContents(AA); - AA = null; - foreach (InventoryBase R in T) - { - if (R.Name == "attachments") - { - AA = (InventoryFolder)R; - break; - } - } - if (AA != null) - { - T = bot.GetClient.Inventory.Store.GetContents(AA); - AA = null; - foreach (InventoryBase R in T) - { - if (R.Name == args[0]) - { - AA = (InventoryFolder)R; - break; - } - } - if (AA != null) - { - List items = new List(); - List contents = bot.GetClient.Inventory.FolderContents(AA.UUID, bot.GetClient.Self.AgentID, true, true, InventorySortOrder.ByName, 20 * 1000); - foreach (InventoryBase item in contents) - { - if ((item is InventoryWearable) || (item is InventoryObject)) - { - if (item.Name == args[1]) - { - items.Add((InventoryItem)item); - break; - } - } - } - if (items.Count() > 0) - { - bot.GetClient.Appearance.AddAttachments(items, false, false); - return true; - } - else - { - return Failed("Unable to find attachment: " + args[1] + " in sub folder " + args[0] + ""); - } - } - else - { - return Failed("Unable to find subfolder " + args[0] + ""); - } - } - else - { - return Failed("Unable to find attachements folder"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/getRealUUID.cs b/Core/Commands/Inventory/getRealUUID.cs deleted file mode 100644 index 3d0af0b..0000000 --- a/Core/Commands/Inventory/getRealUUID.cs +++ /dev/null @@ -1,35 +0,0 @@ -using BetterSecondBot.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class getRealUUID : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Smart", "UUID" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP", "Inventory UUID" }; } } - public override string Helpfile - { - get - { - return "Converts a Inventory UUID into an asset UUID used to send? im not sure yet"; - } - } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(UUID.TryParse(args[1],out UUID target) == true) - { - UUID reply = HelperInventory.GetAssetUUID(bot, target); - if(reply != UUID.Zero) - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], reply.ToString(), CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "Unable to fetch asset UUID", CommandName); - } - return bot.GetCommandsInterface.SmartCommandReply(false, args[0], "Unable to process target UUID", CommandName); - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/inventoryContents.cs b/Core/Commands/Inventory/inventoryContents.cs deleted file mode 100644 index 603a84e..0000000 --- a/Core/Commands/Inventory/inventoryContents.cs +++ /dev/null @@ -1,52 +0,0 @@ -using System; -using OpenMetaverse; -using BetterSecondBot.Static; -using BetterSecondBotShared.Static; -using System.Collections.Generic; - -namespace BetterSecondBot.Commands.Inventory -{ - - public class InventoryContents : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Smart","UUID" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP","Folder" }; } } - public override string Helpfile { get { return "Maps the given inventory folder [ARG 2] for contents
" + - "Arg 1 *Avatar UUID* sends it via notecard to [ARG 1]
" + - "Arg 1 *Anything else*
as csv packed as follows folderinventory=UUID~|~entry~|~entry..." + - "entry is formated as follows: itemname###uuid###type
" + - "sent to smart reply target"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[1], out UUID targetfolder) == true) - { - if (UUID.TryParse(args[0], out UUID targetavatar) == true) - { - KeyValuePair content = HelperInventory.MapFolderInventoryHumanReadable(bot, targetfolder); - if (content.Value != null) - { - string notecardname = ""+content.Key+" Contents @" + helpers.UnixTimeNow().ToString() + ""; - bot.SendNotecard(notecardname, content.Value, targetavatar); - } - else - { - bot.GetClient.Self.InstantMessage(targetavatar, "Unable to load folder or it is empty"); - } - return true; - } - else - { - return bot.GetCommandsInterface.SmartCommandReply(true, args[0], HelperInventory.MapFolderInventoryJson(bot,targetfolder), CommandName); - } - } - else - { - return Failed("Invaild folder UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/inventoryFolders.cs b/Core/Commands/Inventory/inventoryFolders.cs deleted file mode 100644 index 078893a..0000000 --- a/Core/Commands/Inventory/inventoryFolders.cs +++ /dev/null @@ -1,36 +0,0 @@ -using OpenMetaverse; -using BetterSecondBot.Static; - -namespace BetterSecondBot.Commands.Inventory -{ - public class InventoryFolders : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Smart" }; } } - public override string[] ArgHints { get { return new[] { "Smart reply target: Channel,Avatar,HTTP url" }; } } - public override string Helpfile { get { return "Fully maps the avatars inventory folders
" + - "*[Arg 1 UUID] sends you a notecard with it
" + - "*[Arg 1 Anything else] Sends it as a CSV via the smart target
" + - "Formated as follows
" + - "entry,entry...
" + - "Where entry is formated foldername###level###UUID"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetavatar) == true) - { - bot.GetClient.Self.InstantMessage(targetavatar, "Building inventory folder map now [This might take a while]"); - string reply = HelperInventory.MapFolderHumanReadable(bot); - bot.SendNotecard("Inventory Folders", reply, targetavatar); - return true; - } - else - { - string reply = HelperInventory.MapFolderJson(bot); - return bot.GetCommandsInterface.SmartCommandReply(true,args[0], reply, CommandName); - } - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/outfit.cs b/Core/Commands/Inventory/outfit.cs deleted file mode 100644 index 5bd30a6..0000000 --- a/Core/Commands/Inventory/outfit.cs +++ /dev/null @@ -1,74 +0,0 @@ -using System.Collections.Generic; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class Outfit : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Text" }; } } - public override string[] ArgHints { get { return new[] { "Folder name" }; } } - public override string Helpfile { get { return "Replaces the current avatar outfit with the Clothing/[ARG1] folder
Please note: This does not use the outfits folder!"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - // uses the Clothing folder - // must be a full outfit (shapes/eyes ect) - InventoryFolder AA = bot.GetClient.Inventory.Store.RootFolder; - List T = bot.GetClient.Inventory.Store.GetContents(AA); - AA = null; - foreach (InventoryBase R in T) - { - if (R.Name == "Clothing") - { - AA = (InventoryFolder)R; - break; - } - } - if (AA != null) - { - T = bot.GetClient.Inventory.Store.GetContents(AA); - AA = null; - foreach (InventoryBase R in T) - { - if (R.Name == args[0]) - { - AA = (InventoryFolder)R; - break; - } - } - if (AA != null) - { - List contents = bot.GetClient.Inventory.FolderContents(AA.UUID, bot.GetClient.Self.AgentID, true, true, InventorySortOrder.ByName, 20 * 1000); - List wareables = new List(); - if (contents != null) - { - foreach (InventoryBase item in contents) - { - if ((item is InventoryWearable) || (item is InventoryObject)) - { - wareables.Add((InventoryItem)item); - } - } - bot.GetClient.Appearance.ReplaceOutfit(wareables, false); - return true; - } - else - { - return Failed("target folder is empty or so full I cant get it in 20 secs..."); - } - } - else - { - return Failed("Cant find target folder"); - } - } - else - { - return Failed("Cant find Clothing folder"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/sendFolder.cs b/Core/Commands/Inventory/sendFolder.cs deleted file mode 100644 index d0a8bb6..0000000 --- a/Core/Commands/Inventory/sendFolder.cs +++ /dev/null @@ -1,43 +0,0 @@ -using BetterSecondBot.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class SendFolder : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar","UUID" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "FOLDER" }; } } - public override string Helpfile { get { return "Sends a folder [ARG 2] to an avatar [ARG 1]"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (UUID.TryParse(args[0], out UUID targetavatar) == true) - { - if (UUID.TryParse(args[1], out UUID targetfolder) == true) - { - InventoryBase FindFolderHelper = HelperInventory.FindFolder(bot, bot.GetClient.Inventory.Store.RootFolder, targetfolder); - if (FindFolderHelper != null) - { - bot.GetClient.Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, targetavatar, false); - return true; - } - else - { - return Failed("Unable to find folder"); - } - } - else - { - return Failed("Invaild folder UUID"); - } - } - else - { - return Failed("Invaild avatar UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Inventory/sendItem.cs b/Core/Commands/Inventory/sendItem.cs deleted file mode 100644 index e79e4de..0000000 --- a/Core/Commands/Inventory/sendItem.cs +++ /dev/null @@ -1,47 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Inventory -{ - public class SendItem : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar", "UUID", "Number" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Item","Time to find item" }; } } - public override string Helpfile { get { return "Sends a item [ARG 2] to an avatar [ARG 1]. (Optional arg 3: How long to wait to find the item in secs, Defaults to 6)"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - int search_delay_time = 6; - if(args.Length == 3) - { - int.TryParse(args[2], out search_delay_time); - } - if (UUID.TryParse(args[0], out UUID targetavatar) == true) - { - if (UUID.TryParse(args[1], out UUID targetitem) == true) - { - InventoryItem itm = bot.GetClient.Inventory.FetchItem(targetitem, bot.GetClient.Self.AgentID, (search_delay_time * 1000)); - if (itm != null) - { - bot.GetClient.Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, targetavatar, false); - return true; - } - else - { - return Failed("Unable to find item"); - } - } - else - { - return Failed("Invaild item UUID"); - } - } - else - { - return Failed("Invaild avatar UUID"); - } - } - return false; - } - } -} diff --git a/Core/Commands/Movement.cs b/Core/Commands/Movement.cs new file mode 100644 index 0000000..5734592 --- /dev/null +++ b/Core/Commands/Movement.cs @@ -0,0 +1,304 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; +using System.Threading; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Movement : WebApiControllerWithTokens + { + public HTTP_Movement(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("uses the AutoPilot to move to a location")] + [ReturnHints("Error Unable to AutoPilot to location")] + [ReturnHints("Accepted")] + [ReturnHints("Convert to vector has failed")] + [ReturnHints("? value out of range 0-?")] + [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, "/AutoPilot/{x}/{y}/{z}/{token}")] + public object AutoPilot(string x, string y, string z, string token) + { + if (tokens.Allow(token, "movement", "AutoPilot", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (Vector3.TryParse("<" + x + "," + y + "," + z + ">", out Vector3 pos) == false) + { + return Failure("Convert to vector has failed"); + } + if (helpers.inrange(pos.X, 0, 255) == false) + { + return Failure("x value out of range 0-255"); + } + if (helpers.inrange(pos.Y, 0, 255) == false) + { + return Failure("y value out of range 0-255"); + } + if (helpers.inrange(pos.Z, 0, 5000) == false) + { + return Failure("z value out of range 0-5000"); + } + bot.GetClient.Self.AutoPilotCancel(); + bot.GetClient.Self.Movement.TurnToward(pos, true); + Thread.Sleep(500); + uint Globalx, Globaly; + Utils.LongToUInts(bot.GetClient.Network.CurrentSim.Handle, out Globalx, out Globaly); + bot.GetClient.Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z); + return true; + } + + [About("Attempt to teleport to a new region")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/AutoPilotStop/{token}")] + public object AutoPilotStop(string token) + { + if (tokens.Allow(token, "movement", "AutoPilotStop", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + bot.GetClient.Self.AutoPilotCancel(); + return BasicReply("ok"); + } + + [About("Make the bot request the target avatar teleport to the bot")] + [ReturnHints("ok")] + [ReturnHints("Invaild avatar UUID")] + [ArgHints("avatar", "URLARG", "Avatar UUID or Firstname Lastname")] + [Route(HttpVerbs.Get, "/SendTeleportLure/{avatar}/{token}")] + public object SendTeleportLure(string avatar,string token) + { + if (tokens.Allow(token, "movement", "SendTeleportLure", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if(avataruuid == UUID.Zero) + { + return Failure("Invaild avatar UUID"); + } + bot.GetClient.Self.SendTeleportLure(avataruuid); + return BasicReply("ok"); + } + + [About("Sends a teleport request (Move the bot to the avatar)")] + [ReturnHints("ok")] + [ReturnHints("Invaild avatar UUID")] + [ArgHints("avatar", "URLARG", "Avatar UUID or Firstname Lastname")] + [Route(HttpVerbs.Get, "/RequestTeleport/{avatar}/{token}")] + public object RequestTeleport(string avatar, string token) + { + if (tokens.Allow(token, "movement", "RequestTeleport", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar UUID"); + } + bot.Add_action_from("teleport", avataruuid); + bot.GetClient.Self.SendTeleportLureRequest(avataruuid, "I would like to teleport to you"); + return BasicReply("ok"); + } + + [About("Makes the bot fly (or not)")] + [ReturnHints("ok")] + [ReturnHints("Invaild mode")] + [ArgHints("mode", "URLARG", "true: Start flying, false: stop flying (super fun at height)")] + [Route(HttpVerbs.Get, "/Fly/{mode}/{token}")] + public object Fly(string mode, string token) + { + if (tokens.Allow(token, "movement", "Fly", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (bool.TryParse(mode, out bool flymode) == false) + { + return Failure("Invaild mode"); + } + bot.GetClient.Self.Movement.Fly = flymode; + bot.GetClient.Self.Movement.SendUpdate(); + return BasicReply("ok"); + } + + + + [About("Rotates the bot to face a vector from its current location")] + [ReturnHints("true|false")] + [ReturnHints("Invaild vector")] + [ReturnHints("Vector ? value is out of range 0-?")] + [ArgHints("vector", "Text", "a vector to face eg <123,45,44>")] + [Route(HttpVerbs.Post, "/RotateToFaceVector/{token}")] + public object RotateToFaceVector([FormField] string vector, string token) + { + if (tokens.Allow(token, "movement", "RotateToFaceVector", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (Vector3.TryParse(vector, out Vector3 pos) == false) + { + return Failure("Invaild vector"); + } + if (helpers.inrange(pos.X, 0, 255) == false) + { + return Failure("Vector x value is out of range 0-255"); + } + if (helpers.inrange(pos.Y, 0, 255) == false) + { + return Failure("Vector y value is out of range 0-255"); + } + if (helpers.inrange(pos.Z, 0, 5000) == false) + { + return Failure("Vector z value is out of range 0-5000"); + } + return BasicReply(bot.GetClient.Self.Movement.TurnToward(pos, true).ToString()); + } + + [About("Rotates the bot to face a avatar")] + [ReturnHints("true|false")] + [ReturnHints("Invaild avatar UUID")] + [ReturnHints("Unable to see avatar")] + [ArgHints("avatar", "URLARG", "An avatar UUID or Firstname Lastname")] + [Route(HttpVerbs.Post, "/RotateToFace/{avatar}/{token}")] + public object RotateToFace(string avatar, string token) + { + if (tokens.Allow(token, "movement", "RotateToFace", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + ProcessAvatar(avatar); + if(avataruuid == UUID.Zero) + { + return Failure("Invaild avatar UUID"); + } + if (bot.GetClient.Network.CurrentSim.AvatarPositions.ContainsKey(avataruuid) == false) + { + return Failure("Unable to see avatar"); + } + return BasicReply(bot.GetClient.Self.Movement.TurnToward(bot.GetClient.Network.CurrentSim.AvatarPositions[avataruuid], true).ToString()); + } + + + [About("Rotates the avatar to face a rotation from north in Degrees")] + [ReturnHints("ok")] + [ReturnHints("Unable to process rotation")] + [ArgHints("deg", "URLARG", "0 to 360")] + [Route(HttpVerbs.Post, "/RotateTo/{deg}/{token}")] + public object RotateTo(string deg, string token) + { + if (tokens.Allow(token, "movement", "RotateTo", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (float.TryParse(deg, out float target_yaw) == true) + { + return Failure("Unable to process rotation"); + } + float yaw = target_yaw; + bot.GetClient.Self.Movement.BodyRotation.GetEulerAngles(out float roll, out float pitch, out _); + roll *= 57.2958f; + pitch *= 57.2958f; + yaw *= 57.2958f; + float rollOver2 = roll * 0.5f; + float sinRollOver2 = (float)Math.Sin((double)rollOver2); + float cosRollOver2 = (float)Math.Cos((double)rollOver2); + float pitchOver2 = pitch * 0.5f; + float sinPitchOver2 = (float)Math.Sin((double)pitchOver2); + float cosPitchOver2 = (float)Math.Cos((double)pitchOver2); + float yawOver2 = yaw * 0.5f; + float sinYawOver2 = (float)Math.Sin((double)yawOver2); + float cosYawOver2 = (float)Math.Cos((double)yawOver2); + Quaternion result; + result.W = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2; + result.X = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2; + result.Y = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2; + result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2; + bot.GetClient.Self.Movement.BodyRotation = result; + bot.GetClient.Self.Movement.SendUpdate(); + return BasicReply("ok"); + } + + + + [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) + { + if (tokens.Allow(token, "movement", "Teleport", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + bool status = TeleportRequest(new string[] { region, x, y, z }); + if (status == false) + { + return Failure("Error Unable to Teleport to location"); + } + return BasicReply("Accepted"); + } + + + + protected bool TeleportRequest(string[] args) + { + bot.GetClient.Self.AutoPilotCancel(); + if (args[0].Contains("http://maps.secondlife.com/secondlife/") == true) + { + bot.TeleportWithSLurl(args[0]); + return true; + } + else + { + float posX = 128; + float posY = 128; + float posZ = 0; + string regionName = bot.GetClient.Network.CurrentSim.Name; + bool ok = true; + int offset = 0; + string[] tp_args = args[0].Split('/'); + if ((tp_args.Length == 4) || (tp_args.Length == 1)) + { + regionName = tp_args[0]; + offset = 1; + } + if (tp_args.Length >= 3) + { + float.TryParse(tp_args[offset + 0], out posX); + float.TryParse(tp_args[offset + 1], out posY); + float.TryParse(tp_args[offset + 2], out posZ); + } + else if (tp_args.Length == 2) + { + ok = false; + } + if (ok == true) + { + bot.SetTeleported(); + bool status = bot.GetClient.Self.Teleport(regionName, new Vector3(posX, posY, posZ)); + bot.ResetAnimations(); + return status; + } + else + { + return false; + } + } + } + } +} diff --git a/Core/Commands/Movement/AutoPilotStop.cs b/Core/Commands/Movement/AutoPilotStop.cs deleted file mode 100644 index eb1ea3a..0000000 --- a/Core/Commands/Movement/AutoPilotStop.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace BetterSecondBot.Commands.Movement -{ - public class AutoPilotStop : CoreCommand - { - public override string Helpfile { get { return "Stops any current AutoPilot"; } } - public override bool CallFunction(string[] args) - { - bot.GetClient.Self.AutoPilotCancel(); - return true; - } - } - -} diff --git a/Core/Commands/Movement/Fly.cs b/Core/Commands/Movement/Fly.cs deleted file mode 100644 index 50d1fdc..0000000 --- a/Core/Commands/Movement/Fly.cs +++ /dev/null @@ -1,35 +0,0 @@ -using System.Threading; - -namespace BetterSecondBot.Commands.Movement -{ - public class BotFly : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "True|False" }; } } - public override string[] ArgHints { get { return new[] { "Should the bot be flying" }; } } - public override string Helpfile { get { return "Makes the bot fly (or not)"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (bool.TryParse(args[0], out bool status) == true) - { - if(status == false) - { - bot.GetClient.Self.Movement.Fly = true; - bot.GetClient.Self.Movement.SendUpdate(); - Thread.Sleep(200); - } - bot.GetClient.Self.Movement.Fly = status; - bot.GetClient.Self.Movement.SendUpdate(); - return true; - } - else - { - return Failed("Unable to process rotation"); - } - } - return false; - } - } - -} diff --git a/Core/Commands/Movement/RequestTeleport.cs b/Core/Commands/Movement/RequestTeleport.cs deleted file mode 100644 index 0fa44d6..0000000 --- a/Core/Commands/Movement/RequestTeleport.cs +++ /dev/null @@ -1,26 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Movement -{ - public class RequestTeleport : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar UUID or Firstname Lastname" }; } } - public override string Helpfile { get { return "Sends a teleport lure request (Move the bot to the avatar)"; } } - - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID avatar) == true) - { - bot.Add_action_from("teleport", avatar); - bot.GetClient.Self.SendTeleportLureRequest(avatar, "I would like to teleport to you"); - return true; - } - return Failed("Unable to process avatar on arg 1"); - } - return false; - } - } -} diff --git a/Core/Commands/Movement/RotateToFace.cs b/Core/Commands/Movement/RotateToFace.cs deleted file mode 100644 index 42fd711..0000000 --- a/Core/Commands/Movement/RotateToFace.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using OpenMetaverse; -namespace BetterSecondBot.Commands.Movement -{ - public class RotateToFace : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar UUID or Firstname Lastname" }; } } - public override string Helpfile { get { return "Rotates the bot to face an avatar"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID avatar) == true) - { - if (bot.GetClient.Network.CurrentSim.AvatarPositions.ContainsKey(avatar) == true) - { - return bot.GetClient.Self.Movement.TurnToward(bot.GetClient.Network.CurrentSim.AvatarPositions[avatar], true); - } - Failed("Unable to find avatar in local sim memory"); - } - return Failed("Unable to process avatar on arg 1"); - } - return false; - } - } - -} diff --git a/Core/Commands/Movement/RotateToFaceVector.cs b/Core/Commands/Movement/RotateToFaceVector.cs deleted file mode 100644 index b944dbb..0000000 --- a/Core/Commands/Movement/RotateToFaceVector.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System; -using BetterSecondBotShared.Static; -using OpenMetaverse; -namespace BetterSecondBot.Commands.Movement -{ - public class RotateToFaceVector : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Vector" }; } } - public override string[] ArgHints { get { return new[] { "The location to face Example: <25,123,33>" }; } } - public override string Helpfile { get { return "Rotates the bot to face a vector from its current location"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if(Vector3.TryParse(args[0],out Vector3 pos) == true) - { - if (helpers.inrange(pos.X, 0, 255) == true) - { - if (helpers.inrange(pos.Y, 0, 255) == true) - { - if (helpers.inrange(pos.Z, 0, 5000) == true) - { - return bot.GetClient.Self.Movement.TurnToward(pos, true); - } - return Failed("Arg 1 - Vector Z is out of range"); - } - return Failed("Arg 2 - Vector Y is out of range"); - } - return Failed("Arg 1 - Vector X is out of range"); - } - return Failed("Unable to process vector on arg 1"); - } - return false; - } - } - -} diff --git a/Core/Commands/Movement/SendTeleportLure.cs b/Core/Commands/Movement/SendTeleportLure.cs deleted file mode 100644 index fc9cf38..0000000 --- a/Core/Commands/Movement/SendTeleportLure.cs +++ /dev/null @@ -1,25 +0,0 @@ -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Movement -{ - public class SendTeleportLure : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Avatar" }; } } - public override string[] ArgHints { get { return new[] { "Avatar UUID or Firstname Lastname" }; } } - public override string Helpfile { get { return "Make the bot request the target avatar teleport to the bot"; } } - - public override bool CallFunction(string[] args) - { - if(base.CallFunction(args) == true) - { - if(UUID.TryParse(args[0],out UUID avatar) == true) - { - bot.GetClient.Self.SendTeleportLure(avatar); - return true; - } - return Failed("Unable to process avatar on arg 1"); - } - return false; - } - } -} diff --git a/Core/Commands/Movement/rotateTo.cs b/Core/Commands/Movement/rotateTo.cs deleted file mode 100644 index 8338de0..0000000 --- a/Core/Commands/Movement/rotateTo.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using OpenMetaverse; -namespace BetterSecondBot.Commands.Movement -{ - public class RotateTo : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Number" }; } } - public override string[] ArgHints { get { return new[] { "0 to 360" }; } } - public override string Helpfile { get { return "Rotates the avatar to face a rotation from north in Degrees"; } } - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - if (float.TryParse(args[0], out float target_yaw) == true) - { - float yaw = target_yaw; - bot.GetClient.Self.Movement.BodyRotation.GetEulerAngles(out float roll, out float pitch, out _); - roll *= 57.2958f; - pitch *= 57.2958f; - yaw *= 57.2958f; - float rollOver2 = roll * 0.5f; - float sinRollOver2 = (float)Math.Sin((double)rollOver2); - float cosRollOver2 = (float)Math.Cos((double)rollOver2); - float pitchOver2 = pitch * 0.5f; - float sinPitchOver2 = (float)Math.Sin((double)pitchOver2); - float cosPitchOver2 = (float)Math.Cos((double)pitchOver2); - float yawOver2 = yaw * 0.5f; - float sinYawOver2 = (float)Math.Sin((double)yawOver2); - float cosYawOver2 = (float)Math.Cos((double)yawOver2); - Quaternion result; - result.W = cosYawOver2 * cosPitchOver2 * cosRollOver2 + sinYawOver2 * sinPitchOver2 * sinRollOver2; - result.X = cosYawOver2 * sinPitchOver2 * cosRollOver2 + sinYawOver2 * cosPitchOver2 * sinRollOver2; - result.Y = sinYawOver2 * cosPitchOver2 * cosRollOver2 - cosYawOver2 * sinPitchOver2 * sinRollOver2; - result.Z = cosYawOver2 * cosPitchOver2 * sinRollOver2 - sinYawOver2 * sinPitchOver2 * cosRollOver2; - bot.GetClient.Self.Movement.BodyRotation = result; - bot.GetClient.Self.Movement.SendUpdate(); - return true; - } - else - { - return Failed("Unable to process rotation"); - } - } - return false; - } - } - -} diff --git a/Core/Commands/Notecard.cs b/Core/Commands/Notecard.cs new file mode 100644 index 0000000..e644683 --- /dev/null +++ b/Core/Commands/Notecard.cs @@ -0,0 +1,97 @@ +using BetterSecondBot.bottypes; +using BetterSecondBot.Static; +using EmbedIO; +using EmbedIO.Routing; +using EmbedIO.WebApi; +using System; +using System.Collections.Generic; +using System.Text; +using OpenMetaverse; +using Newtonsoft.Json; +using System.Reflection; +using BetterSecondBotShared.Static; + +namespace BetterSecondBot.HttpService +{ + public class HTTP_Notecard : WebApiControllerWithTokens + { + public HTTP_Notecard(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } + + [About("Adds content to the Collection
Also creates the Collection if it does not exist")] + [ReturnHints("Collection value is empty")] + [ReturnHints("Content value is empty")] + [ReturnHints("ok")] + [Route(HttpVerbs.Post, "/NotecardAdd/{collection}/{token}")] + public object NotecardAdd(string collection, [FormField] string content, string token) + { + if (tokens.Allow(token, "notecard", "NotecardAdd", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (helpers.notempty(collection) == false) + { + return Failure("Collection value is empty"); + } + if (helpers.notempty(content) == false) + { + return Failure("Content value is empty"); + } + bot.NotecardAddContent(collection, content); + return BasicReply("ok"); + } + + [About("Adds content to the Collection
Also creates the Collection if it does not exist")] + [ReturnHints("Collection value is empty")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/NotecardClear/{collection}/{token}")] + public object NotecardClear(string collection, string token) + { + if (tokens.Allow(token, "notecard", "NotecardClear", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (helpers.notempty(collection) == false) + { + return Failure("Collection value is empty"); + } + bot.ClearNotecardStorage(collection); + return BasicReply("ok"); + } + + [About("Adds content to the Collection
Also creates the Collection if it does not exist")] + [ReturnHints("True|False")] + [ReturnHints("Collection value is empty")] + [ReturnHints("Notecardname value is empty")] + [ReturnHints("Invaild avatar uuid")] + [ReturnHints("No content in notecard storage ?")] + [ReturnHints("ok")] + [Route(HttpVerbs.Get, "/NotecardSend/{avatar}/{collection}/{notecardname}/{token}")] + public object NotecardSend(string avatar, string collection, string notecardname, string token) + { + if (tokens.Allow(token, "notecard", "NotecardSend", handleGetClientIP()) == false) + { + return Failure("Token not accepted"); + } + if (helpers.notempty(collection) == false) + { + return Failure("Collection value is empty"); + } + if (helpers.notempty(notecardname) == false) + { + return Failure("Notecardname value is empty"); + } + ProcessAvatar(avatar); + if(avataruuid == UUID.Zero) + { + return Failure("Invaild avatar uuid"); + } + string content = bot.GetNotecardContent(collection); + if (content == null) + { + return Failure("No content in notecard storage " + collection); + } + bot.ClearNotecardStorage(collection); + return BasicReply(bot.SendNotecard(notecardname, content, avataruuid).ToString()); + } + } +} diff --git a/Core/Commands/Notecard/notecardAdd.cs b/Core/Commands/Notecard/notecardAdd.cs deleted file mode 100644 index 4d35fe8..0000000 --- a/Core/Commands/Notecard/notecardAdd.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace BetterSecondBot.Commands.Notecard -{ - class NotecardAdd : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Text","Text" }; } } - public override string[] ArgHints { get { return new[] { "Collection","Content" }; } } - public override string Helpfile { get { return "Adds [ARG 2] to the Collection [ARG 1]
Also creates the collection if it does not exist"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bot.NotecardAddContent(args[0], args[1]); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Notecard/notecardClear.cs b/Core/Commands/Notecard/notecardClear.cs deleted file mode 100644 index 8df95d6..0000000 --- a/Core/Commands/Notecard/notecardClear.cs +++ /dev/null @@ -1,19 +0,0 @@ -namespace BetterSecondBot.Commands.Notecard -{ - class NotecardClear : CoreCommand_1arg - { - public override string[] ArgTypes { get { return new[] { "Text" }; } } - public override string[] ArgHints { get { return new[] { "Collection" }; } } - public override string Helpfile { get { return "Clears Collection [ARG 1]"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - bot.ClearNotecardStorage(args[0]); - return true; - } - return false; - } - } -} diff --git a/Core/Commands/Notecard/notecardSend.cs b/Core/Commands/Notecard/notecardSend.cs deleted file mode 100644 index 0c34eaa..0000000 --- a/Core/Commands/Notecard/notecardSend.cs +++ /dev/null @@ -1,45 +0,0 @@ -using BetterSecondBotShared.Static; -using OpenMetaverse; - -namespace BetterSecondBot.Commands.Notecard -{ - class NotecardSend : CoreCommand_2arg - { - public override string[] ArgTypes { get { return new[] { "Avatar","Text","Text" }; } } - public override string[] ArgHints { get { return new[] { "Avatar [UUID or Firstname Lastname]", "Collection","Notecard name" }; } } - public override string Helpfile { get { return "Creats and send a notecard to [ARG 1]
" + - " using the collection [ARG 2] as the content
" + - " Optional: You can name the notecard using [ARG 3]"; } } - - public override bool CallFunction(string[] args) - { - if (base.CallFunction(args) == true) - { - // target UUID,notecard storage id,["notecard title" or defaults to: New notecard for ] - if (UUID.TryParse(args[0], out UUID target) == true) - { - string content = bot.GetNotecardContent(args[1]); - if (content != null) - { - bot.ClearNotecardStorage(args[1]); - string notecard_name = "New notecard for " + args[0] + " " + helpers.UnixTimeNow().ToString() + ""; - if (args.Length == 3) - { - notecard_name = args[2] + " " + helpers.UnixTimeNow().ToString() + ""; - } - return bot.SendNotecard(notecard_name, content, target); - } - else - { - return Failed("No content in notecard storage " + args[1]); - } - } - else - { - return Failed("Arg 0 not a UUID"); - } - } - return false; - } - } -} diff --git a/Core/HttpService/Parcel.cs b/Core/Commands/Parcel.cs similarity index 96% rename from Core/HttpService/Parcel.cs rename to Core/Commands/Parcel.cs index 67e68f8..4043620 100644 --- a/Core/HttpService/Parcel.cs +++ b/Core/Commands/Parcel.cs @@ -135,7 +135,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/ParcelEject/{avatar}/{token}")] public object ParcelEject(string avatar,string token) { - if (tokens.Allow(token, "parcel", "ParcelEject", getClientIP()) == false) + if (tokens.Allow(token, "parcel", "ParcelEject", handleGetClientIP()) == false) { return BasicReply("Token not accepted"); } @@ -429,7 +429,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/ParcelFreeze/{avatar}/{state}/{token}")] public object ParcelFreeze(string avatar, string state, string token) { - if (tokens.Allow(token, "parcel", "ParcelFreeze", getClientIP()) == false) + if (tokens.Allow(token, "parcel", "ParcelFreeze", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -476,7 +476,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/UnRezObject/{objectuuid}/{token}")] public object UnRezObject(string objectuuid,string token) { - if (tokens.Allow(token, "parcel", "UnRezObject", getClientIP()) == false) + if (tokens.Allow(token, "parcel", "UnRezObject", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/Self.cs b/Core/Commands/Self.cs similarity index 89% rename from Core/HttpService/Self.cs rename to Core/Commands/Self.cs index b55cb6e..6aa4ba3 100644 --- a/Core/HttpService/Self.cs +++ b/Core/Commands/Self.cs @@ -23,7 +23,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/PointAt/{avatar}/{token}")] public object PointAt(string avatar, string token) { - if (tokens.Allow(token, "self", "PointAt", getClientIP()) == false) + if (tokens.Allow(token, "self", "PointAt", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -49,7 +49,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Sit/{target}/{token}")] public object Sit(string target, string token) { - if (tokens.Allow(token, "self", "Sit", getClientIP()) == false) + if (tokens.Allow(token, "self", "Sit", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -71,7 +71,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Stand/{token}")] public object Stand(string target, string token) { - if (tokens.Allow(token, "self", "Stand", getClientIP()) == false) + if (tokens.Allow(token, "self", "Stand", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -88,7 +88,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/ClickObject/{object}/{token}")] public object ClickObject(string target, string token) { - if (tokens.Allow(token, "self", "ClickObject", getClientIP()) == false) + if (tokens.Allow(token, "self", "ClickObject", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -115,7 +115,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Logoff/{token}")] public object Logoff(string token) { - if (tokens.Allow(token, "self", "Logoff", getClientIP()) == false) + if (tokens.Allow(token, "self", "Logoff", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -132,7 +132,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Logout/{token}")] public object Logout(string token) { - if (tokens.Allow(token, "self", "Logout", getClientIP()) == false) + if (tokens.Allow(token, "self", "Logout", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -149,7 +149,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/Bye/{token}")] public object Bye(string token) { - if (tokens.Allow(token, "self", "Bye", getClientIP()) == false) + if (tokens.Allow(token, "self", "Bye", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -165,7 +165,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/GetLastCommands/{token}")] public object GetLastCommands(string token) { - if (tokens.Allow(token, "self", "GetLastCommands", getClientIP()) == false) + if (tokens.Allow(token, "self", "GetLastCommands", handleGetClientIP()) == false) { return Failure("Token not accepted"); } @@ -184,7 +184,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Get, "/SetPermFlag/{avatar}/{flag}/{state}/{sticky}/{token}")] public object SetPermFlag(string avatar, string flag, string state, string sticky, string token) { - if (tokens.Allow(token, "self", "SetPermFlag", getClientIP()) == false) + if (tokens.Allow(token, "self", "SetPermFlag", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/HttpService/StreamAdmin.cs b/Core/Commands/StreamAdmin.cs similarity index 96% rename from Core/HttpService/StreamAdmin.cs rename to Core/Commands/StreamAdmin.cs index cb1ab9f..1d814e4 100644 --- a/Core/HttpService/StreamAdmin.cs +++ b/Core/Commands/StreamAdmin.cs @@ -31,7 +31,7 @@ namespace BetterSecondBot.HttpService [Route(HttpVerbs.Post, "/FetchNextNotecard/{token}")] public object FetchNextNotecard([FormField] string endpoint, [FormField] string endpointcode, string token) { - if (tokens.Allow(token, "avatars", "FetchNextNotecard", getClientIP()) == false) + if (tokens.Allow(token, "avatars", "FetchNextNotecard", handleGetClientIP()) == false) { return Failure("Token not accepted"); } diff --git a/Core/Commands/commandlib.cs b/Core/Commands/commandlib.cs deleted file mode 100644 index 97f7c1c..0000000 --- a/Core/Commands/commandlib.cs +++ /dev/null @@ -1,398 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Linq; -using OpenMetaverse; -using System.Net.Http; -using BetterSecondBot.bottypes; -using BetterSecondBotShared.API; -using BetterSecondBotShared.Static; -using BetterSecondBotShared.logs; -using Newtonsoft.Json; - -namespace BetterSecondBot.Commands -{ - public class pending_avatar_lookup - { - public CoreCommand GetCommand { get { return Command; } } - public List Getargs { get { return args; } } - public pending_avatar_lookup(CoreCommandsInterface set_master,CoreCommand set_cmd,string[] set_args) - { - Master = set_master; - Command = set_cmd; - args = set_args.ToList(); - } - public KeyValuePair Callnow() - { - bool result = Command.CallFunction(args.ToArray()); - return new KeyValuePair(result, Command.GetInfoBlob); - } - public bool needs_lookup() - { - List need_lookup_on_indexs = new List(); - int loop = 0; - foreach (string atype in Command.ArgTypes) - { - if (loop < args.Count) - { - if (atype == "Avatar") - { - need_lookup_on_indexs.Add(loop); - } - else if(atype == "Smart") - { - if(args[loop].StartsWith("http") == false) - { - // not a url request - if (int.TryParse(args[loop],out _) == false) - { - // Not a channel - need_lookup_on_indexs.Add(loop); - } - } - } - loop++; - } - else - { - break; - } - } - bool has_required_lookups = false; - foreach (int A in need_lookup_on_indexs) - { - if(UUID.TryParse(args[A],out _) == false) - { - // not a uuid - string get_or_request_uuid = Master.GetBot.FindAvatarName2Key(args[A]); - if(get_or_request_uuid == "lookup") - { - has_required_lookups = true; - } - else - { - args[A] = get_or_request_uuid; - } - } - } - return has_required_lookups; - } - protected CoreCommand Command; - protected List args; - protected CoreCommandsInterface Master; - } - public class CoreCommandsInterface : API_supported_interface - { - protected CommandsBot bot; - public CommandsBot GetBot { get { return bot; } } - - protected long giveup_waiting_for_lookup = 240; - protected int next_lookup_id; - protected Dictionary commands_pending_avatar_lookups = new Dictionary(); - protected Dictionary commands_pending_avatar_lookups_ages = new Dictionary(); - - public void StatusTick() - { - List purge_indexs = new List(); - List call_indexs = new List(); - long now = helpers.UnixTimeNow(); - foreach (KeyValuePair pair in commands_pending_avatar_lookups_ages) - { - if (commands_pending_avatar_lookups[pair.Key].needs_lookup() == true) - { - long dif = now - pair.Value; - if (dif > giveup_waiting_for_lookup) - { - purge_indexs.Add(pair.Key); - } - } - else - { - call_indexs.Add(pair.Key); - } - } - foreach(int a in purge_indexs) - { - commands_pending_avatar_lookups_ages.Remove(a); - commands_pending_avatar_lookups.Remove(a); - } - foreach(int a in call_indexs) - { - KeyValuePair result = commands_pending_avatar_lookups[a].Callnow(); - bot.CommandHistoryAdd(commands_pending_avatar_lookups[a].GetCommand.CommandName, String.Join("~#~", commands_pending_avatar_lookups[a].Getargs), result.Key, result.Value); - commands_pending_avatar_lookups_ages.Remove(a); - commands_pending_avatar_lookups.Remove(a); - } - } - - public CoreCommandsInterface(CommandsBot linktobot) - { - bot = linktobot; - API_type = typeof(CoreCommand); - LoadCommandsList(); - } - protected HttpClient HTTPclient = new HttpClient(); - - - public bool SmartCommandReply(bool run_status, string target, string output, string command) - { - return SmartCommandReply(run_status, target, output, command, null); - } - - public bool SmartCommandReply(bool run_status, string target, string output, string command, Dictionary collection) - { - string mode = "CHAT"; - UUID target_avatar = UUID.Zero; - int target_channel = 0; - if (target.StartsWith("http://")) - { - mode = "HTTP"; - } - else if (UUID.TryParse(target, out target_avatar) == true) - { - mode = "IM"; - } - else - { - if (int.TryParse(target, out target_channel) == false) - { - run_status = false; - } - } - - if (collection != null) - { - var reply_object = new CoreCommand_json_reply_wit_collection(); - reply_object.status = run_status; - reply_object.command = command; - reply_object.output = output; - reply_object.collection = collection; - output = JsonConvert.SerializeObject(reply_object); - } - else - { - var reply_object = new CoreCommand_json_reply(); - reply_object.status = run_status; - reply_object.command = command; - reply_object.output = output; - output = JsonConvert.SerializeObject(reply_object); - } - - if (mode == "CHAT") - { - if (target_channel >= 0) - { - bot.GetClient.Self.Chat(output, target_channel, ChatType.Normal); - } - else - { - run_status = false; - LogFormater.Crit("[SmartReply] output Channel must be zero or higher"); - } - } - else if (mode == "IM") - { - bot.GetClient.Self.InstantMessage(target_avatar, output); - } - else if (mode == "HTTP") - { - Dictionary values = new Dictionary - { - { "reply", output }, - }; - - var content = new FormUrlEncodedContent(values); - try - { - HTTPclient.PostAsync(target, content); - } - catch (Exception e) - { - run_status = false; - LogFormater.Crit("[SmartReply] HTTP failed: " + e.Message + ""); - } - } - else - { - LogFormater.Crit("[SmartReply] Unsupported output target"); - return false; - } - return run_status; - } - - protected List suppress_warnings = new List(); - public bool Call(string command) - { - return Call(command, ""); - } - public bool Call(string command, string arg) - { - return Call(command, arg, UUID.Zero); - } - public bool Call(string command, string arg, UUID caller) - { - return Call(command, arg, caller, "~#~"); - } - public bool Call(string command, string arg, UUID caller, string split_args_on) - { - KeyValuePair result = CallCommand(command, arg, caller, split_args_on); - bot.CommandHistoryAdd(command, arg, result.Key, result.Value); - return result.Key; - } - - protected KeyValuePair CallCommand(string command, string arg, UUID caller, string split_args_on) - { - command = command.ToLowerInvariant(); - CoreCommand cmd = (CoreCommand)GetCommand(command); - if (cmd != null) - { - cmd.Setup(bot, caller); - string[] args = new string[] { }; - if (helpers.notempty(arg) == true) - { - args = arg.Split(new[] { split_args_on }, StringSplitOptions.RemoveEmptyEntries); - } - if ((cmd.ArgTypes.Contains("Avatar") == true) || (cmd.ArgTypes.Contains("Smart") == true)) - { - if (cmd.Min_Required_args <= args.Length) - { - pending_avatar_lookup pending = new pending_avatar_lookup(this, cmd, args); - if (pending.needs_lookup() == true) - { - commands_pending_avatar_lookups.Add(next_lookup_id, pending); - commands_pending_avatar_lookups_ages.Add(next_lookup_id, helpers.UnixTimeNow()); - next_lookup_id++; - if (next_lookup_id == 13000) - { - next_lookup_id = 0; - } - return new KeyValuePair(true,"Lookup underway"); - } - else - { - return pending.Callnow(); - } - } - else - { - return new KeyValuePair(false, "Required args count not sent! expected: "+ cmd.Min_Required_args.ToString()+" but got "+ args.Length.ToString()+ ""); - } - } - else - { - bool result = cmd.CallFunction(args); - return new KeyValuePair(result, cmd.GetInfoBlob); - } - } - else - { - if (suppress_warnings.Contains(command) == false) - { - suppress_warnings.Add(command); - return new KeyValuePair(false, "unknown"); - } - } - return new KeyValuePair(false, "--"); - } - } - class CoreCommand_json_reply_wit_collection : CoreCommand_json_reply - { - public Dictionary collection = new Dictionary(); - } - class CoreCommand_json_reply - { - public bool status; - public string command; - public string output; - } - - - public abstract class CoreCommand_1arg : CoreCommand - { - public override int Min_Required_args { get { return 1; } } - } - public abstract class CoreCommand_2arg : CoreCommand - { - public override int Min_Required_args { get { return 2; } } - } - public abstract class CoreCommand_3arg : CoreCommand - { - public override int Min_Required_args { get { return 3; } } - } - public abstract class CoreCommand_4arg : CoreCommand - { - public override int Min_Required_args { get { return 4; } } - } - - public abstract class CoreCommand_SmartReply_1arg : CoreCommand_1arg - { - protected Dictionary collection = new Dictionary(); - public override string[] ArgTypes { get { return new[] { "Smart" }; } } - public override string[] ArgHints { get { return new[] { "Mixed [Channel|Avatar uuid|Avatar name|http url]" }; } } - } - public abstract class CoreCommand_SmartReply_2arg : CoreCommand_SmartReply_1arg - { - public override int Min_Required_args { get { return 2; } } - } - public abstract class CoreCommand_SmartReply_3arg : CoreCommand_SmartReply_1arg - { - public override int Min_Required_args { get { return 3; } } - } - - - public abstract class CoreCommand : API_interface - { - protected CommandsBot bot; - - /// - /// The UUID of the object/Avatar that called this function, you should still test if its not UUID zero and is a avatar - /// - protected UUID caller = UUID.Zero; - public void Setup(CommandsBot setBot,UUID setCaller) - { - bot = setBot; - caller = setCaller; - } - public virtual void Callback(string[] args, EventArgs e,bool status) - { - bot.CommandHistoryAdd("Callback finished-> " + this.GetType().Name, String.Join(",", args), status, GetInfoBlob); - } - public virtual void Callback(string[] args, EventArgs e) - { - bot.CommandHistoryAdd("Callback finished-> " + this.GetType().Name, String.Join(",", args), true, GetInfoBlob); - } - public virtual bool CallFunction(string[] args) - { - if (helpers.notempty(args) == true) - { - if (args.Length < Min_Required_args) - { - return Failed("Incorrect number of args"); - } - else - { - return true; - } - } - else - { - if(Min_Required_args == 0) - { - return true; - } - else - { - return Failed("Incorrect number of args"); - } - } - } - public bool Failed(string why_failed) - { - InfoBlob = why_failed; - LogFormater.Warn("Called failed because: " + why_failed); - return false; - } - } - - -} diff --git a/Core/HttpService/HttpAsService.cs b/Core/HttpService/HttpAsService.cs index f300c37..8ee345b 100644 --- a/Core/HttpService/HttpAsService.cs +++ b/Core/HttpService/HttpAsService.cs @@ -17,6 +17,8 @@ using Newtonsoft.Json; using OpenMetaverse; using System.Reflection; using System.Linq; +using System.Threading.Tasks; +using Core.Static; namespace BetterSecondBot.HttpService { @@ -173,32 +175,14 @@ namespace BetterSecondBot.HttpService .WithUrlPrefix(url) .WithMode(HttpListenerMode.EmbedIO)) .WithCors() - //.WithIPBanning(o => o - // .WithMaxRequestsPerSecond(30) - // .WithRegexRules("HTTP exception 404") - //) - .WithWebApi("/inventory", m => m - .WithController(() => new HTTP_Inventory(Bot, Tokens)) - ) - .WithWebApi("/chat", m => m - .WithController(() => new HTTP_Chat(Bot, Tokens)) - ) - .WithWebApi("/groups", m => m - .WithController(() => new HTTP_Group(Bot, Tokens)) - ) - .WithWebApi("/ims", m => m - .WithController(() => new HttpApiIM(Bot, Tokens)) - ) - .WithWebApi("/core", m => m - .WithController(() => new HttpApiCore(Config, Bot, Tokens)) - ) - .WithWebApi("/parcel", m => m - .WithController(() => new HTTP_Parcel(Bot,Tokens)) - ) - .WithWebApi("/estate", m => m - .WithController(() => new HTTP_Estate(Bot, Tokens)) - ) .WithModule(new ActionModule("/", HttpVerbs.Any, ctx => ctx.SendDataAsync(new { Message = "Error" }))); + Dictionary commandmodules = http_commands_helper.getCommandModules(); + foreach (KeyValuePair entry in commandmodules) + { + server.WithWebApi("/" + entry.Key, m => m + .WithController(() => (WebApiControllerWithTokens)Activator.CreateInstance(entry.Value, args: new object[] { Bot, Tokens })) + ); + } return server; } @@ -262,6 +246,8 @@ namespace BetterSecondBot.HttpService protected Dictionary scopedtokens = new Dictionary(); + + protected List OneTimeTokens = new List(); public string OneTimeToken() @@ -395,38 +381,34 @@ namespace BetterSecondBot.HttpService { protected TokenStorage tokens; protected SecondBot bot; + public bool needsToken { get; set; } protected UUID avataruuid = UUID.Zero; protected Parcel targetparcel = null; - protected string CallMethod(string name,string[] args) + protected bool disableIPchecks = false; + public void disableIPlockout() { - MethodInfo[] methods = this.GetType().GetMethods(); - MethodInfo found = null; - foreach(MethodInfo M in methods) - { - if(M.Name == name) - { - found = M; - break; - } - } - if(found == null) - { - return "Failed:Not Found"; - } - List settings = new List(args); - settings.Add(tokens.OneTimeToken()); - if(found.GetParameters().Length != settings.Count) - { - return "Failed:Incorrect args"; - } - string reply = (string)found.Invoke(this, settings.Cast().ToArray()); - return "Passed:"+ reply; + disableIPchecks = true; } + + public IPAddress handleGetClientIP() + { + if(disableIPchecks == true) + { + return IPAddress.Parse("127.0.0.1"); + } + else + { + return HttpContext.Request.RemoteEndPoint.Address; + } + } + + + protected KeyValuePair SetupCurrentParcel(string token,string usenamespace,string command) { - if (tokens.Allow(token, usenamespace, command, getClientIP()) == false) + if (tokens.Allow(token, usenamespace, command, handleGetClientIP()) == false) { return new KeyValuePair(false, "Token not accepted"); } @@ -437,11 +419,18 @@ namespace BetterSecondBot.HttpService int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == false) { - return new KeyValuePair(false, "Parcel data not ready"); + Thread.Sleep(2000); + localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); + if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == false) + { + return new KeyValuePair(false, "Parcel data not ready"); + } } Parcel targetparcel = bot.GetClient.Network.CurrentSim.Parcels[localid]; return new KeyValuePair(true, ""); } + + protected void ProcessAvatar(string avatar) { string[] bits = avatar.Split(' '); @@ -449,6 +438,11 @@ namespace BetterSecondBot.HttpService if (bits.Length == 2) { avatar = bot.FindAvatarName2Key(avatar); + if(avatar == "lookup") + { + Thread.Sleep(2000); + avatar = bot.FindAvatarName2Key(avatar); + } } UUID.TryParse(avatar, out avataruuid); } @@ -468,6 +462,7 @@ namespace BetterSecondBot.HttpService { bot = mainbot; tokens = setuptokens; + } /* @@ -479,13 +474,10 @@ namespace BetterSecondBot.HttpService } */ - public IPAddress getClientIP() - { - return HttpContext.Request.RemoteEndPoint.Address; - } - } + + public class tokenInfo { public long Expires = 0; diff --git a/Core/HttpService/Info.cs b/Core/HttpService/Info.cs deleted file mode 100644 index 8d56528..0000000 --- a/Core/HttpService/Info.cs +++ /dev/null @@ -1,116 +0,0 @@ -using BetterSecondBot.bottypes; -using BetterSecondBot.Static; -using EmbedIO; -using EmbedIO.Routing; -using EmbedIO.WebApi; -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; -using Newtonsoft.Json; -using BetterSecondBotShared.Static; - -namespace BetterSecondBot.HttpService -{ - public class HTTP_Info : WebApiControllerWithTokens - { - public HTTP_Info(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } - - [About("Fetchs the current bot")] - [ReturnHints("The build ID of the bot")] - [Route(HttpVerbs.Get, "/Version/{token}")] - public object Version(string token) - { - if (tokens.Allow(token, "info", "Version", getClientIP()) == true) - { - return BasicReply(bot.MyVersion); - } - return Failure("Token not accepted"); - } - - [About("Fetchs the name of the bot")] - [ReturnHints("Firstname Lastname")] - [Route(HttpVerbs.Get, "/Name/{token}")] - public object Name(string token) - { - if (tokens.Allow(token, "info", "Name", getClientIP()) == true) - { - return BasicReply(bot.GetClient.Self.FirstName + " " + bot.GetClient.Self.LastName); - } - return Failure("Token not accepted"); - } - - [About("Fetchs the current parcels name")] - [ReturnHints("Parcelname")] - [ReturnHints("Error parcel not found")] - [ReturnHints("Error not in a sim")] - [Route(HttpVerbs.Get, "/ParcelName/{token}")] - public object ParcelName(string token) - { - if (tokens.Allow(token, "info", "ParcelName", getClientIP()) == true) - { - if (bot.GetClient.Network.CurrentSim != null) - { - int localid = bot.GetClient.Parcels.GetParcelLocalID(bot.GetClient.Network.CurrentSim, bot.GetClient.Self.SimPosition); - if (bot.GetClient.Network.CurrentSim.Parcels.ContainsKey(localid) == true) - { - return BasicReply(bot.GetClient.Network.CurrentSim.Parcels[localid].Name); - } - return Failure("Error parcel not found"); - } - return Failure("Error not in a sim"); - } - return Failure("Token not accepted"); - } - - [About("Requests the current unixtime at the bot")] - [ReturnHints("Unixtime")] - [Route(HttpVerbs.Get, "/UnixTimeNow/{token}")] - public object UnixTimeNow(string token) - { - if (tokens.Allow(token, "info", "UnixTimeNow", getClientIP()) == true) - { - return BasicReply(helpers.UnixTimeNow().ToString()); - } - return Failure("Token not accepted"); - } - - [About("Fetchs the current region name")] - [ReturnHints("Regionname")] - [ReturnHints("Error not in a sim")] - [Route(HttpVerbs.Get, "/SimName/{token}")] - public object SimName(string token) - { - if (tokens.Allow(token, "info", "SimName", getClientIP()) == true) - { - if (bot.GetClient.Network.CurrentSim != null) - { - return BasicReply(bot.GetClient.Network.CurrentSim.Name); - } - return Failure("Error not in a sim"); - } - return Failure("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, "/GetPosition/{token}")] - public object GetPosition(string token) - { - if (tokens.Allow(token, "info", "GetPosition", getClientIP()) == true) - { - 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 Failure("Error not in a sim"); - } - return Failure("Token not accepted"); - } - } -} diff --git a/Core/HttpService/Inventory.cs b/Core/HttpService/Inventory.cs deleted file mode 100644 index 1a6ae67..0000000 --- a/Core/HttpService/Inventory.cs +++ /dev/null @@ -1,218 +0,0 @@ -using BetterSecondBot.bottypes; -using BetterSecondBot.Static; -using EmbedIO; -using EmbedIO.Routing; -using EmbedIO.WebApi; -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; - -namespace BetterSecondBot.HttpService -{ - public class HTTP_Inventory : WebApiControllerWithTokens - { - public HTTP_Inventory(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) - { - if (tokens.Allow(token, "inventory", "RezObject", getClientIP()) == true) - { - bool status = bot.GetCommandsInterface.Call("RezObject", item); - return BasicReply(status.ToString()); - } - 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) - { - if (tokens.Allow(token, "inventory", "Rename", getClientIP()) == true) - { - bool status = bot.GetCommandsInterface.Call("RenameInventory", "12~#~" + item + "~#~" + newname); - return BasicReply(status.ToString()); - } - 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) - { - if (tokens.Allow(token, "inventory", "realuuid", getClientIP()) == true) - { - if (UUID.TryParse(item, out UUID itemUUID) == true) - { - UUID reply = HelperInventory.GetAssetUUID(bot, itemUUID); - if (reply != UUID.Zero) - { - return BasicReply(reply.ToString()); - } - } - return BasicReply("Failed"); - } - 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) - { - if (tokens.Allow(token, "inventory", "send", getClientIP()) == true) - { - if (UUID.TryParse(item, out UUID itemUUID) == true) - { - bool status = bot.GetCommandsInterface.Call("SendItem", avatar+"~#~"+item); - return BasicReply(status.ToString()); - } - return BasicReply("Failed - item must be a vaild UUID"); - } - return BasicReply("Token not accepted"); - } - - [About("Transfers a item [ARG 2] to a objects inventory [ARG 1] (And if set with the script running state [ARG 3])")] - [ReturnHints("Transfering running script")] - [ReturnHints("Transfering inventory")] - [ReturnHints("Invaild item uuid")] - [ReturnHints("Invaild object uuid")] - [ReturnHints("Unable to find inventory")] - [ReturnHints("Unable to find object")] - [ReturnHints("Invaild running")] - [ArgHints("item", "URLARG", "UUID of item")] - [ArgHints("object", "URLARG", "the uuid of the object")] - [ArgHints("running", "URLARG", "true if you wish the transfered script to be running otherwise false")] - - [Route(HttpVerbs.Get, "/TransferInventoryToObject/{item}/{objectuuid}/{running}/{token}")] - public object TransferInventoryToObject(string item, string objectuuid, string running, string token) - { - if (tokens.Allow(token, "inventory", "TransferInventoryToObject", getClientIP()) == true) - { - return Failure("Token not accepted"); - } - if (UUID.TryParse(item, out UUID itemuuid) == false) - { - return Failure("Invaild item uuid"); - } - if (UUID.TryParse(objectuuid, out UUID objectUUID) == false) - { - return Failure("Invaild object uuid"); - } - if (bool.TryParse(running, out bool runscript) == false) - { - return Failure("Invaild running"); - } - - InventoryItem itm = bot.GetClient.Inventory.FetchItem(itemuuid, bot.GetClient.Self.AgentID, (3 * 1000)); - if (itm == null) - { - return Failure("Unable to find inventory"); - } - Dictionary objects_copy = bot.GetClient.Network.CurrentSim.ObjectsPrimitives.Copy(); - KeyValuePair RealObject = new KeyValuePair(0,null); - foreach (KeyValuePair Obj in objects_copy) - { - if (Obj.Value.ID == objectUUID) - { - RealObject = Obj; - break; - } - } - if (RealObject.Value == null) - { - return Failure("Unable to find object"); - } - bool scriptState = runscript; - if (itm.AssetType != AssetType.LSLText) - { - scriptState = false; - } - if (itm.AssetType == AssetType.LSLText) - { - bot.GetClient.Inventory.CopyScriptToTask(RealObject.Key, itm, scriptState); - return BasicReply("Transfering script [state: "+scriptState.ToString()+"]"); - } - bot.GetClient.Inventory.UpdateTaskInventory(RealObject.Key, itm); - return BasicReply("Transfering inventory"); - } - - - [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) - { - if (tokens.Allow(token, "inventory", "delete", getClientIP()) == true) - { - if (UUID.TryParse(item, out UUID itemUUID) == true) - { - if (bool.TryParse(isfolder, out bool asfolder) == true) - { - bool status = false; - if (asfolder == true) status = bot.GetCommandsInterface.Call("DeleteInventoryFolder", item); - else status = bot.GetCommandsInterface.Call("DeleteInventoryItem", item); - return BasicReply(status.ToString()); - } - return BasicReply("Failed - isfolder must be True or False"); - } - return BasicReply("Failed - item must be a vaild UUID"); - } - 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) - { - if(tokens.Allow(token, "inventory", "folders", getClientIP()) == true) - { - string reply = HelperInventory.MapFolderJson(bot); - if(reply != null) return BasicReply(reply); - 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) - { - if (tokens.Allow(token, "inventory", "contents", getClientIP()) == true) - { - if (UUID.TryParse(folderUUID, out UUID folder) == true) - { - return BasicReply(HelperInventory.MapFolderInventoryJson(bot, folder)); - } - return BasicReply("Invaild folder UUID"); - } - return BasicReply("Token not accepted"); - - } - - } - -} diff --git a/Core/HttpService/Movement.cs b/Core/HttpService/Movement.cs deleted file mode 100644 index 096979d..0000000 --- a/Core/HttpService/Movement.cs +++ /dev/null @@ -1,131 +0,0 @@ -using BetterSecondBot.bottypes; -using BetterSecondBot.Static; -using EmbedIO; -using EmbedIO.Routing; -using EmbedIO.WebApi; -using System; -using System.Collections.Generic; -using System.Text; -using OpenMetaverse; -using Newtonsoft.Json; -using System.Reflection; -using System.Threading; -using BetterSecondBotShared.Static; - -namespace BetterSecondBot.HttpService -{ - public class HTTP_Movement : WebApiControllerWithTokens - { - public HTTP_Movement(SecondBot mainbot, TokenStorage setuptokens) : base(mainbot, setuptokens) { } - - [About("uses the AutoPilot to move to a location")] - [ReturnHints("Error Unable to AutoPilot to location")] - [ReturnHints("Accepted")] - [ReturnHints("Convert to vector has failed")] - [ReturnHints("? value out of range 0-?")] - [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, "/AutoPilot/{x}/{y}/{z}/{token}")] - public object AutoPilot(string x, string y, string z, string token) - { - if (tokens.Allow(token, "movement", "AutoPilot", getClientIP()) == false) - { - return Failure("Token not accepted"); - } - if (Vector3.TryParse("<" + x + "," + y + "," + z + ">", out Vector3 pos) == false) - { - return Failure("Convert to vector has failed"); - } - if (helpers.inrange(pos.X, 0, 255) == false) - { - return Failure("x value out of range 0-255"); - } - if (helpers.inrange(pos.Y, 0, 255) == false) - { - return Failure("y value out of range 0-255"); - } - if (helpers.inrange(pos.Z, 0, 5000) == false) - { - return Failure("z value out of range 0-5000"); - } - bot.GetClient.Self.AutoPilotCancel(); - bot.GetClient.Self.Movement.TurnToward(pos, true); - Thread.Sleep(500); - uint Globalx, Globaly; - Utils.LongToUInts(bot.GetClient.Network.CurrentSim.Handle, out Globalx, out Globaly); - bot.GetClient.Self.AutoPilot((ulong)(Globalx + pos.X), (ulong)(Globaly + pos.Y), pos.Z); - return true; - } - - [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) - { - if (tokens.Allow(token, "core", "Teleport", getClientIP()) == true) - { - bool status = TeleportRequest(new string[] { region, x, y, z }); - if (status == true) - { - return BasicReply("Accepted"); - } - return Failure("Error Unable to Teleport to location"); - } - return Failure("Token not accepted"); - } - - - - protected bool TeleportRequest(string[] args) - { - bot.GetClient.Self.AutoPilotCancel(); - if (args[0].Contains("http://maps.secondlife.com/secondlife/") == true) - { - bot.TeleportWithSLurl(args[0]); - return true; - } - else - { - float posX = 128; - float posY = 128; - float posZ = 0; - string regionName = bot.GetClient.Network.CurrentSim.Name; - bool ok = true; - int offset = 0; - string[] tp_args = args[0].Split('/'); - if ((tp_args.Length == 4) || (tp_args.Length == 1)) - { - regionName = tp_args[0]; - offset = 1; - } - if (tp_args.Length >= 3) - { - float.TryParse(tp_args[offset + 0], out posX); - float.TryParse(tp_args[offset + 1], out posY); - float.TryParse(tp_args[offset + 2], out posZ); - } - else if (tp_args.Length == 2) - { - ok = false; - } - if (ok == true) - { - bot.SetTeleported(); - bool status = bot.GetClient.Self.Teleport(regionName, new Vector3(posX, posY, posZ)); - bot.ResetAnimations(); - return status; - } - else - { - return false; - } - } - } - } -} diff --git a/Core/Static/http_commands_helper.cs b/Core/Static/http_commands_helper.cs new file mode 100644 index 0000000..488db92 --- /dev/null +++ b/Core/Static/http_commands_helper.cs @@ -0,0 +1,33 @@ +using BetterSecondBot.HttpService; +using System; +using System.Collections.Generic; +using System.Text; + +namespace Core.Static +{ + public static class http_commands_helper + { + public static Dictionary getCommandModules() + { + Dictionary reply = new Dictionary(); + reply.Add("animation", typeof(HTTP_Animation)); + reply.Add("avatars", typeof(HTTP_Avatars)); + reply.Add("chat", typeof(HTTP_Chat)); + reply.Add("core", typeof(HTTP_Core)); + reply.Add("dialogs", typeof(HTTP_Dialogs)); + reply.Add("estate", typeof(HTTP_Estate)); + reply.Add("friends", typeof(HTTP_Friends)); + reply.Add("group", typeof(HTTP_Group)); + reply.Add("home", typeof(HTTP_Home)); + reply.Add("im", typeof(HTTP_IM)); + reply.Add("info", typeof(HTTP_Info)); + reply.Add("inventory", typeof(HTTP_Inventory)); + reply.Add("movement", typeof(HTTP_Movement)); + reply.Add("notecard", typeof(HTTP_Notecard)); + reply.Add("parcel", typeof(HTTP_Parcel)); + reply.Add("self", typeof(HTTP_Self)); + reply.Add("streamadmin", typeof(HTTP_StreamAdmin)); + return reply; + } + } +} diff --git a/Core/bottypes/AVstorageBot.cs b/Core/bottypes/AVstorageBot.cs index babef89..6bb1775 100644 --- a/Core/bottypes/AVstorageBot.cs +++ b/Core/bottypes/AVstorageBot.cs @@ -226,6 +226,7 @@ namespace BetterSecondBot.bottypes FindAvatarName2Key(myconfig.Security_MasterUsername); } } + base.AfterBotLoginHandler(); } diff --git a/Core/bottypes/AnimationsBot.cs b/Core/bottypes/AnimationsBot.cs index 4311fab..807a758 100644 --- a/Core/bottypes/AnimationsBot.cs +++ b/Core/bottypes/AnimationsBot.cs @@ -14,8 +14,8 @@ namespace BetterSecondBot.bottypes if (reconnect == false) { Client.Avatars.AvatarAnimation += AvatarAnimationHandler; - } - base.AfterBotLoginHandler(); + } + reconnect = true; } public override void ResetAnimations() diff --git a/Core/bottypes/AwaitReplyEventBot.cs b/Core/bottypes/AwaitReplyEventBot.cs index 5e2160a..b37cfae 100644 --- a/Core/bottypes/AwaitReplyEventBot.cs +++ b/Core/bottypes/AwaitReplyEventBot.cs @@ -1,5 +1,4 @@ -using BetterSecondBot.Commands; -using System; +using System; using System.Collections.Generic; using System.Text; using OpenMetaverse; @@ -25,31 +24,6 @@ namespace BetterSecondBot.bottypes protected override void GroupMembersReplyHandler(object sender, GroupMembersReplyEventArgs e) { base.GroupMembersReplyHandler(sender, e); - if (await_events.ContainsKey("groupmembersreply") == true) - { - List PurgeAwaiters = new List(); - foreach (KeyValuePair> await_reply in await_events["groupmembersreply"]) - { - // eventid - // KeyValuePair - // Args: Group, args, args - if (UUID.TryParse(await_reply.Value.Value[0], out UUID test_group) == true) - { - if (test_group == e.GroupID) - { - // oh shit its for me - PurgeAwaiters.Add(await_reply.Key); - await_reply.Value.Key.Callback(await_reply.Value.Value, e); - } - } - } - foreach (string eventid in PurgeAwaiters) - { - await_event_ages.Remove(eventid); - await_event_idtolistener.Remove(eventid); - await_events["groupmembersreply"].Remove(eventid); - } - } } protected virtual void GroupchatJoinHandler(object sender, GroupChatJoinedEventArgs e) @@ -61,52 +35,10 @@ namespace BetterSecondBot.bottypes active_group_chat_sessions.Add(e.SessionID); } } - if (await_events.ContainsKey("groupchatjoin") == true) - { - List PurgeAwaiters = new List(); - foreach (KeyValuePair> await_reply in await_events["groupchatjoin"]) - { - // eventid - // KeyValuePair - // Args: Group, Message - if (await_reply.Value.Value.Length == 2) - { - if (UUID.TryParse(await_reply.Value.Value[0], out UUID test_group) == true) - { - if (test_group == e.SessionID) - { - // oh shit its for me - PurgeAwaiters.Add(await_reply.Key); - await_reply.Value.Key.Callback(await_reply.Value.Value, e); - } - } - } - } - foreach (string eventid in PurgeAwaiters) - { - await_event_ages.Remove(eventid); - await_event_idtolistener.Remove(eventid); - await_events["groupchatjoin"].Remove(eventid); - } - } } protected virtual void ObjectOwnersHandler(object sender, ParcelObjectOwnersReplyEventArgs e) { - if (await_events.ContainsKey("parcelobjectowners") == true) - { - List PurgeAwaiters = new List(); - foreach (KeyValuePair> await_reply in await_events["parcelobjectowners"]) - { - PurgeAwaiters.Add(await_reply.Key); - await_reply.Value.Key.Callback(await_reply.Value.Value, e); - } - foreach (string eventid in PurgeAwaiters) - { - await_event_ages.Remove(eventid); - await_event_idtolistener.Remove(eventid); - await_events["parcelobjectowners"].Remove(eventid); - } - } + } protected void GroupRolesData(object sender,GroupRolesDataReplyEventArgs e) { @@ -126,38 +58,6 @@ namespace BetterSecondBot.bottypes { mygrouprolesstorage[e.GroupID] = storage; } - // trigger events - if (await_events.ContainsKey("grouproles") == true) - { - List PurgeAwaiters = new List(); - foreach(KeyValuePair> await_reply in await_events["grouproles"]) - { - // eventid - // KeyValuePair - // Args: ReplyConfig, GroupUUID - if (await_reply.Value.Value.Length == 2) - { - if(UUID.TryParse(await_reply.Value.Value[1], out UUID test_group) == true) - { - if(test_group == e.GroupID) - { - // oh shit its for me - PurgeAwaiters.Add(await_reply.Key); - await_reply.Value.Key.Callback(await_reply.Value.Value,e); - } - } - } - } - foreach(string eventid in PurgeAwaiters) - { - await_event_ages.Remove(eventid); - await_event_idtolistener.Remove(eventid); - await_events["grouproles"].Remove(eventid); - } - - } } - - } } \ No newline at end of file diff --git a/Core/bottypes/CommandsBot.cs b/Core/bottypes/CommandsBot.cs index 56ba8af..07743ef 100644 --- a/Core/bottypes/CommandsBot.cs +++ b/Core/bottypes/CommandsBot.cs @@ -7,16 +7,16 @@ using OpenMetaverse.Assets; using BetterSecondBotShared.Static; using BetterSecondBotShared.logs; using System.Threading; - +using BetterSecondBot.HttpService; +using Core.Static; +using System.Reflection; +using Newtonsoft.Json; +using System.Net.Http; + namespace BetterSecondBot.bottypes { public abstract class CommandsBot : AVstorageBot { - protected CommandsBot() - { - CommandsInterface = new Commands.CoreCommandsInterface(this); - } - protected List CommandHistory = new List(); protected int commandid = 1; public virtual string CommandHistoryAdd(string command, string arg, bool status,string infomessage) @@ -84,9 +84,6 @@ namespace BetterSecondBot.bottypes Client.Self.InstantMessage(avatar, message); } - public Commands.CoreCommandsInterface GetCommandsInterface { get { return CommandsInterface; } } - protected Commands.CoreCommandsInterface CommandsInterface; - protected Dictionary Scripts_content = new Dictionary(); protected Dictionary notecards_content = new Dictionary(); protected Dictionary> group_invite_lockout_timer = new Dictionary>(); @@ -100,7 +97,6 @@ namespace BetterSecondBot.bottypes last_cleanup_commands = helpers.UnixTimeNow(); PurgeOldGroupinviteLockouts(); } - CommandsInterface.StatusTick(); return base.GetStatus(); } public bool GetAllowGroupInvite(UUID avatar, UUID group) @@ -112,18 +108,6 @@ namespace BetterSecondBot.bottypes return true; } - public void GroupInviteLockoutArm(UUID avatar, UUID group) - { - if (group_invite_lockout_timer.ContainsKey(group) == false) - { - group_invite_lockout_timer.Add(group, new Dictionary()); - } - if (group_invite_lockout_timer[group].ContainsKey(avatar) == false) - { - group_invite_lockout_timer[group].Add(avatar,0); - } - group_invite_lockout_timer[group][avatar] = helpers.UnixTimeNow(); - } protected void PurgeOldGroupinviteLockouts() { long now = helpers.UnixTimeNow(); @@ -145,80 +129,17 @@ namespace BetterSecondBot.bottypes } } - public void custom_commands_loop(string command,string arg,UUID caller) - { - List customargs = arg.Split(new[] { "~#~" }, StringSplitOptions.RemoveEmptyEntries).ToList(); - while(customargs.Count < 5) - { - customargs.Add("notset"); - } - foreach (string A in custom_commands[command]) - { - List command_args_split = A.Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries).ToList(); - int loop = 1; - string args_passed = ""; - if (command_args_split.Count() == 2) - { - args_passed = command_args_split[1]; - while (loop <= 5) - { - args_passed = args_passed.Replace("[C_ARG_"+loop.ToString()+"]", customargs[loop-1]); - loop++; - } - } - CommandsInterface.Call(command_args_split[0], args_passed, caller, "~#~"); - } - } - protected virtual void CallCommandLib(string command, string arg) - { - CallCommandLib(command, arg, UUID.Zero); - } - protected virtual void CallCommandLib(string command, string arg, UUID caller) - { - CallCommandLib(command, arg, caller, "~#~"); - } - protected virtual void CallCommandLib(string command, string arg, UUID caller,string signed_with) - { - if(custom_commands.ContainsKey(command) == false) - { - CommandsInterface.Call(command, arg, caller, signed_with); - } - else - { - Thread t = new Thread(() => custom_commands_loop(command, arg, caller)); - t.Start(); - } - } - public override void AfterBotLoginHandler() { - if (reconnect == false) - { - CommandsInterface = new Commands.CoreCommandsInterface(this); + if (reconnect == false) + { + loadCommands(); + LoadCustomCommands(); } Client.Self.RequestBalance(); base.AfterBotLoginHandler(); } - protected override void CoreCommandLib(UUID fromUUID, bool from_accepted_avatar, string command, string arg, string signing_code, string signed_with) - { - if (CommandsInterface != null) - { - if (from_accepted_avatar == true) - { - CallCommandLib(command, arg, fromUUID, signed_with); - } - else if (signing_code != "") - { - string raw = "" + command + "" + arg + "" + myconfig.Security_SignedCommandkey + ""; - string hashcheck = helpers.GetSHA1(raw); - if (hashcheck == signing_code) - { - CallCommandLib(command, arg, fromUUID, signed_with); - } - } - } - } public void NotecardAddContent(string target_notecard_storage_id, string content) { NotecardAddContent(target_notecard_storage_id, content, true, "\n\r"); @@ -313,92 +234,234 @@ namespace BetterSecondBot.bottypes ); return returnstatus; } - public void ScriptAddContent(string target_Script_storage_id, string content) - { - ScriptAddContent(target_Script_storage_id, content, true, "\n\r"); - } - public void ScriptAddContent(string target_Script_storage_id, string content, bool add_newline) - { - ScriptAddContent(target_Script_storage_id, content, add_newline, "\n\r"); - } - public void ScriptAddContent(string target_Script_storage_id, string content, bool add_newline, string newlinevalue) - { - if (Scripts_content.ContainsKey(target_Script_storage_id) == false) - { - Scripts_content.Add(target_Script_storage_id, ""); - } - if (add_newline == true) - { - content = "" + newlinevalue + "" + content; - } - Scripts_content[target_Script_storage_id] = Scripts_content[target_Script_storage_id] + "" + content; - } - public string GetScriptContent(string target_Script_storage_id) - { - if (Scripts_content.ContainsKey(target_Script_storage_id) == true) - { - return Scripts_content[target_Script_storage_id]; - } - return null; - } - public void ClearScriptStorage(string target_Script_storage_id) - { - if (Scripts_content.ContainsKey(target_Script_storage_id) == true) - { - Scripts_content.Remove(target_Script_storage_id); - } - } - public bool SendScript(string name, string content, UUID sendToUUID) + protected Dictionary commandEndpoints = new Dictionary(); + protected Dictionary endpointcommandmap = new Dictionary(); // command = endpoint + protected Dictionary commandnameLowerToReal = new Dictionary(); + protected TokenStorage Tokens = new TokenStorage(); + protected bool commandsLoaded = false; + + protected override void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar, bool group, UUID group_uuid, bool localchat, bool fromme) { - bool returnstatus = true; - Client.Inventory.RequestCreateItem( - Client.Inventory.FindFolderForType(AssetType.LSLText), - name, - name, - AssetType.LSLText, - UUID.Random(), - InventoryType.LSL, - PermissionMask.All, - (bool Success, InventoryItem item) => + base.BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme); + if ((group == false) && (localchat == false) && (fromme == false)) + { + string signing_code = ""; + string[] input = message.Split(new[] { "@@@" }, StringSplitOptions.RemoveEmptyEntries); + if (input.Count() == 2) + { + message = input[0]; + signing_code = input[1]; + } + List bits = message.Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries).ToList(); + if (bits.Count == 1) + { + bits.Add(""); + } + if (bits.Count == 2) + { + bits.Add("none"); + } + bool frommaster = false; + if ((avatar == true) && ((sender_uuid == master_uuid) || (SubMasters.Contains(sender_name) == true))) + { + frommaster = true; + } + CoreCommandLib(sender_uuid, frommaster, bits[0], bits[1].Split("~#~"), signing_code,bits[2]); + } + } + + protected KeyValuePair callAPIcommand(string command, string[] args) + { + command = commandnameLowerToReal[command.ToLowerInvariant()]; + try + { + string ott = Tokens.OneTimeToken(); + WebApiControllerWithTokens Endpoint = commandEndpoints[endpointcommandmap[command]]; + MethodInfo theMethod = Endpoint.GetType().GetMethod(command); + List argsList = args.ToList(); + argsList.Add(ott); + string reply = "Inconnect number of args"; + bool status = false; + if (argsList.Count == theMethod.GetParameters().Count()) + { + status = true; + object processed = theMethod.Invoke(Endpoint, argsList.ToArray()); + reply = JsonConvert.SerializeObject(processed); + } + return new KeyValuePair(status, reply); + } + catch (Exception e) + { + return new KeyValuePair(false, e.Message); + } + } + + protected void CoreCommandLib(UUID sender, bool Master, string command, string[] args, string signingcode, string targetreply) + { + bool accepted = Master; + if(accepted == false) + { + string raw = "" + command + "" + string.Join("~#~", args) + "" + myconfig.Security_SignedCommandkey + ""; + string hashcheck = helpers.GetSHA1(raw); + if (hashcheck == signingcode) + { + accepted = true; + } + } + if (accepted == true) + { + CallAPI(command, args, targetreply); + } + } + + public void CallAPI(string command, string[] args) + { + CallAPI(command, args, "None"); + } + public void CallAPI(string command, string[] args, string replyvia) + { + CallAPI(command, args, replyvia, false); + } + public void CallAPI(string command, string[] args, string replyvia, bool customcommand) + { + if(commandnameLowerToReal.ContainsKey(command.ToLowerInvariant()) == false) + { + if (custom_commands.ContainsKey(command) == false) + { + SmartCommandReply(false, replyvia, "Unknown command", command); + return; + } + if(customcommand == true) + { + SmartCommandReply(false, replyvia, "Custom command lockout", command); + return; + } + foreach (string A in custom_commands[command]) + { + List command_args_split = A.Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries).ToList(); + int loop = 1; + string args_passed = ""; + if (command_args_split.Count() == 2) + { + args_passed = command_args_split[1]; + while ((loop <= 5) && (loop <= args.Length)) + { + args_passed = args_passed.Replace("[C_ARG_" + loop.ToString() + "]", args[loop - 1]); + loop++; + } + } + CallAPI(command_args_split[0], args_passed.Split("~#~"),"None",true); + } + return; + } + KeyValuePair statusreply = callAPIcommand(command, args); + SmartCommandReply(statusreply.Key, replyvia, statusreply.Value, command); + } + + protected HttpClient HTTPclient = new HttpClient(); + + protected void SmartCommandReply(bool run_status, string target, string output, string command) + { + string mode = "CHAT"; + UUID target_avatar = UUID.Zero; + int target_channel = 0; + if (target.StartsWith("http://")) + { + mode = "HTTP"; + } + else if (UUID.TryParse(target, out target_avatar) == true) + { + mode = "IM"; + } + else + { + if (int.TryParse(target, out target_channel) == false) { - if (Success) - { - AssetScriptText empty = new AssetScriptText { Source = "\n" }; - empty.Encode(); - Client.Inventory.RequestUpdateScriptAgentInventory(new byte[] { }, item.UUID, true, - (bool uploadSuccess, string uploadStatus, bool compileSuccess, List compileMessages, UUID itemID, UUID assetID) => - { - if (uploadSuccess) - { - empty.AssetData = Encoding.ASCII.GetBytes(content); - Client.Inventory.RequestUpdateScriptAgentInventory(empty.AssetData, itemID,true, - (bool finaluploadSuccess, string finaluploadStatus, bool finalcompileSuccess, List finalcompileMessages, UUID finalitemID, UUID finalassetID) => - { - if (finalcompileSuccess == false) - { - Warn("Script failed to compile, sending anyway."); - } - Client.Inventory.GiveItem(finalitemID, name, AssetType.LSLText, sendToUUID, false); - - }); - } - else - { - Crit("The fuck empty success Script create"); - returnstatus = false; - } - }); - } - else - { - Warn("Unable to find default Scripts folder"); - returnstatus = false; - } + mode = "None"; } - ); - return returnstatus; + } + if (mode == "CHAT") + { + if (target_channel >= 0) + { + Client.Self.Chat(output, target_channel, ChatType.Normal); + } + else + { + run_status = false; + LogFormater.Crit("[SmartReply] output Channel must be zero or higher"); + } + } + else if (mode == "IM") + { + Client.Self.InstantMessage(target_avatar, output); + } + else if (mode == "HTTP") + { + Dictionary values = new Dictionary + { + { "reply", output }, + { "command", command }, + }; + + var content = new FormUrlEncodedContent(values); + try + { + HTTPclient.PostAsync(target, content); + } + catch (Exception e) + { + LogFormater.Crit("[SmartReply] HTTP failed: " + e.Message + ""); + } + } + } + + + + protected void loadCommands() + { + commandsLoaded = true; + Dictionary commandmodules = http_commands_helper.getCommandModules(); + foreach (Type entry in commandmodules.Values) + { + LoadCommandEndpoint(entry); + } + } + + protected virtual void LoadCommandEndpoint(Type endpointtype) + { + WebApiControllerWithTokens controler = (WebApiControllerWithTokens)Activator.CreateInstance(endpointtype, args: new object[] { this, Tokens }); + controler.disableIPlockout(); + commandEndpoints.Add(endpointtype.Name, controler); + foreach (MethodInfo M in endpointtype.GetMethods()) + { + bool isCallable = false; + foreach (CustomAttributeData At in M.CustomAttributes) + { + if (At.AttributeType.Name == "RouteAttribute") + { + isCallable = true; + break; + } + } + if (isCallable == true) + { + if (endpointcommandmap.ContainsKey(M.Name) == true) + { + Warn("Namespace: "+endpointtype.Name+" / Command: " + M.Name + " already found in " + endpointcommandmap[M.Name]); + continue; + } + if(commandnameLowerToReal.ContainsKey(M.Name.ToLowerInvariant()) == true) + { + Warn("Namespace: " + endpointtype.Name + " / Command: " + M.Name + " already found in " + endpointcommandmap[M.Name]); + continue; + } + endpointcommandmap.Add(M.Name, endpointtype.Name); + commandnameLowerToReal.Add(M.Name.ToLowerInvariant(), M.Name); + } + } } } } diff --git a/Core/bottypes/DialogsBot.cs b/Core/bottypes/DialogsBot.cs index 3da85ed..337c1ad 100644 --- a/Core/bottypes/DialogsBot.cs +++ b/Core/bottypes/DialogsBot.cs @@ -97,17 +97,17 @@ namespace BetterSecondBot.bottypes string DialogMessage = "NewDialog###" + dialogID.ToString() + "###"+ Dmess + "###" + String.Join("~|~",e.ButtonLabels) + ""; if (RelayDialogsToChannel != 0) { - CommandsInterface.SmartCommandReply(true,RelayDialogsToChannel.ToString(), DialogMessage,"NewDialogNotice"); + SmartCommandReply(true, RelayDialogsToChannel.ToString(), DialogMessage, "NewDialogNotice"); } if(RelayDialogsToAvatar != UUID.Zero) - { - CommandsInterface.SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice"); + { + SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice"); } if(RelayDialogsToHttp != null) { if (RelayDialogsToHttp.StartsWith("http") == true) { - CommandsInterface.SmartCommandReply(true, RelayDialogsToAvatar.ToString(), DialogMessage, "NewDialogNotice"); + SmartCommandReply(true, RelayDialogsToHttp, DialogMessage, "NewDialogNotice"); } } } diff --git a/Core/bottypes/EventsBot.cs b/Core/bottypes/EventsBot.cs index 1977b16..184c5b3 100644 --- a/Core/bottypes/EventsBot.cs +++ b/Core/bottypes/EventsBot.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Text; using BetterSecondBotShared.Static; -using BetterSecondBot.Commands; using OpenMetaverse; using OpenMetaverse.Imaging; using OpenMetaverse.Packets; @@ -288,6 +287,8 @@ namespace BetterSecondBot.bottypes return result; } + long last_cleanup = 0; + protected void Cleanup_group_member_storage() { lock (group_members_storage) @@ -325,7 +326,6 @@ namespace BetterSecondBot.bottypes if (dif > 30) { last_cleanup = helpers.UnixTimeNow(); - Cleanup_await_events(); Cleanup_group_member_storage(); } if (delay_group_fetch > 0) @@ -533,58 +533,5 @@ namespace BetterSecondBot.bottypes Client.Groups.RequestCurrentGroups(); } } - - protected void Cleanup_await_events() - { - long dif; - List purge_event_ids = new List(); - foreach (KeyValuePair CheckEvent in await_event_ages) - { - dif = last_cleanup - CheckEvent.Value; - if (dif > 240) - { - purge_event_ids.Add(CheckEvent.Key); - } - } - foreach (string eventid in purge_event_ids) - { - string listener = await_event_idtolistener[eventid]; - await_event_idtolistener.Remove(eventid); - await_event_ages.Remove(eventid); - await_events[listener].Remove(eventid); - } - } - - protected long last_cleanup; - - protected Dictionary>> await_events = new Dictionary>>(); - protected Dictionary await_event_ages = new Dictionary(); - protected Dictionary await_event_idtolistener = new Dictionary(); - protected int next_await_id = 1; - - - public bool CreateAwaitEventReply(string event_listener, CoreCommand command, string[] args) - { - string eventid = "" + event_listener + "" + next_await_id.ToString() + ""; - next_await_id++; - if (await_events.ContainsKey(event_listener) == false) - { - await_events.Add(event_listener, new Dictionary>()); - } - if (await_events[event_listener].ContainsKey(eventid) == false) - { - if (await_event_ages.ContainsKey(eventid) == false) - { - if (await_event_idtolistener.ContainsKey(eventid) == false) - { - await_events[event_listener].Add(eventid, new KeyValuePair(command, args)); - await_event_ages.Add(eventid, helpers.UnixTimeNow()); - await_event_idtolistener.Add(eventid, event_listener); - return true; - } - } - } - return false; - } } } diff --git a/Core/bottypes/MessageSwitcherBot.cs b/Core/bottypes/MessageSwitcherBot.cs index d7174b2..c955c87 100644 --- a/Core/bottypes/MessageSwitcherBot.cs +++ b/Core/bottypes/MessageSwitcherBot.cs @@ -98,64 +98,6 @@ namespace BetterSecondBot.bottypes } } } - string signing_code = ""; - string[] input = message.Split(new[] { "@@@" }, StringSplitOptions.RemoveEmptyEntries); - if (input.Count() == 2) - { - message = input[0]; - signing_code = input[1]; - } - List bits = message.Split(new[] { "|||" }, StringSplitOptions.RemoveEmptyEntries).ToList(); - if (bits.Count == 1) - { - bits.Add(""); - } - string arg_signed_with = "~#~"; - if (bits.Count > 2) - { - arg_signed_with = "|||"; - List newbits = new List - { - bits[0] - }; - StringBuilder B = new StringBuilder(); - int loop = 1; - string addon = ""; - while (loop < bits.Count) - { - B.Append(addon); - B.Append(bits[loop]); - addon = arg_signed_with; - loop++; - } - newbits.Add(B.ToString()); - bits = newbits; - } - if (avatar == false) - { - CoreCommandLib(sender_uuid, false, bits.ElementAt(0), bits.ElementAt(1), signing_code, arg_signed_with); - } - else - { - bool run_command; - if (Is_avatar_master(sender_name) == true) - { - run_command = true; - } - else - { - run_command = Accept_action_from("command", sender_uuid); - if (run_command == true) - { - Remove_action_from("command", sender_uuid); - } - } - if (run_command == true) - { - CoreCommandLib(sender_uuid, true, bits.ElementAt(0), bits.ElementAt(1), signing_code, arg_signed_with); - } - - } } } } diff --git a/Core/bottypes/SecondBot.cs b/Core/bottypes/SecondBot.cs index 2368b9b..7c36b7b 100644 --- a/Core/bottypes/SecondBot.cs +++ b/Core/bottypes/SecondBot.cs @@ -29,9 +29,10 @@ namespace BetterSecondBot.bottypes started_friendship_hug = true; if (Client.Friends.FriendList.ContainsKey(master_uuid) == false) { - CommandsInterface.Call("IM", String.Join("~#~", new string[] { myconfig.Security_MasterUsername, "Hello master, I am sending you a friend request now!" })); + CallAPI("IM", new string[] { myconfig.Security_MasterUsername, "Hello master, I am sending you a friend request now!" }); } - CommandsInterface.Call("FriendFullPerms", String.Join("~#~", new string[] { master_uuid.ToString(), "true" }), Client.Self.AgentID); + CallAPI("FriendRequest", new string[] { master_uuid.ToString(), "true" }); + CallAPI("FriendFullPerms", new string[] { master_uuid.ToString(), "true" }); } } @@ -60,7 +61,7 @@ namespace BetterSecondBot.bottypes { if(E.AgentName == myconfig.Security_MasterUsername) { - CommandsInterface.Call("FriendFullPerms", String.Join("~#~", new string[] { myconfig.Security_MasterUsername, "true" }), Client.Self.AgentID); + CallAPI("FriendFullPerms", new string[] { myconfig.Security_MasterUsername, "true" }); } } } diff --git a/Shared/BotTypes/BasicBot.cs b/Shared/BotTypes/BasicBot.cs index 9f20db8..a8330de 100644 --- a/Shared/BotTypes/BasicBot.cs +++ b/Shared/BotTypes/BasicBot.cs @@ -12,10 +12,21 @@ namespace BetterSecondBotShared.bottypes { public abstract class BasicBot { + protected BasicBot() { LastStatusMessage = "No status"; } + + + protected Dictionary mygroups = new Dictionary(); + + protected Dictionary>> mygrouprolesstorage = new Dictionary>>(); + public Dictionary MyGroups { get { return mygroups; } } + public Dictionary>> MyGroupRolesStorage { get { return mygrouprolesstorage; } } + + protected GridClient Client; + public GridClient GetClient { get { return Client; } } protected List SubMasters = new List(); public bool Is_avatar_master(string name) { @@ -29,6 +40,33 @@ namespace BetterSecondBotShared.bottypes } } + protected bool running_in_docker = false; + public void AsDocker() + { + running_in_docker = true; + } + + protected bool killMe; + protected JsonConfig myconfig; + public JsonConfig getMyConfig { get { return myconfig; } } + protected string version = "NotSet V1.0.0.0"; + + protected bool reconnect; + public string MyVersion { get { return version; } } + public string Name { get { return myconfig.Basic_BotUserName; } } + public string OwnerName { get { return myconfig.Security_MasterUsername; } } + public bool GetAllowFunds { get { return myconfig.Setting_AllowFunds; } } + public string LastStatusMessage { get; set; } + + public virtual bool KillMe { get { return killMe; } } + + protected bool teleported; + public void SetTeleported() + { + teleported = true; + } + + protected Dictionary custom_commands = new Dictionary(); public Dictionary getCustomCommands { get { return custom_commands; } } protected bool loaded_custom_commands = false; @@ -68,7 +106,7 @@ namespace BetterSecondBotShared.bottypes try { LoadedCommands = JsonConvert.DeserializeObject(json); - foreach(string loaded in LoadedCommands.CustomCommands) + foreach (string loaded in LoadedCommands.CustomCommands) { string[] bits = loaded.Split(new string[] { "!!!" }, StringSplitOptions.None); if (bits.Length == 2) @@ -99,49 +137,16 @@ namespace BetterSecondBotShared.bottypes io.WriteJsonCommands(LoadedCommands, CommandsFile); } } - if(custom_commands.Count > 0) + if (custom_commands.Count > 0) { Info("Custom commands: " + custom_commands.Count.ToString()); } } - protected bool running_in_docker = false; - public void AsDocker() - { - running_in_docker = true; - } - - protected bool killMe; - protected JsonConfig myconfig; - protected string version = "NotSet V1.0.0.0"; - - protected bool reconnect; - public string MyVersion { get { return version; } } - public string Name { get { return myconfig.Basic_BotUserName; } } - public string OwnerName { get { return myconfig.Security_MasterUsername; } } - public bool GetAllowFunds { get { return myconfig.Setting_AllowFunds; } } - public string LastStatusMessage { get; set; } - - public virtual bool KillMe { get { return killMe; } } - - protected bool teleported; - public void SetTeleported() - { - teleported = true; - } - - protected Dictionary mygroups = new Dictionary(); - protected Dictionary>> mygrouprolesstorage = new Dictionary>>(); - - public Dictionary MyGroups { get { return mygroups; } } - public Dictionary>> MyGroupRolesStorage { get { return mygrouprolesstorage; } } - - protected GridClient Client; - public GridClient GetClient { get { return Client; } } public virtual void KillMePlease() { killMe = true; - Client.Network.BeginLogout(); + Client.Network.BeginLogout(); } public virtual void Setup(JsonConfig config, string Version) { @@ -266,7 +271,7 @@ namespace BetterSecondBotShared.bottypes { Info("Recovery login: using home location"); Lp.Start = "home"; - + } Lp.Start = myconfig.Basic_LoginLocation; @@ -301,11 +306,6 @@ namespace BetterSecondBotShared.bottypes protected string BasicBot_laststatus = ""; public virtual string GetStatus() { - if (loaded_custom_commands == false) - { - loaded_custom_commands = true; - LoadCustomCommands(); - } string reply = "Info: No client"; if (Client != null) { @@ -322,14 +322,9 @@ namespace BetterSecondBotShared.bottypes } } } - } - - if (reply != BasicBot_laststatus) - { - BasicBot_laststatus = reply; - return reply; - } - return ""; + } + BasicBot_laststatus = reply; + return reply; } protected virtual void LoginHandler(object o, LoginProgressEventArgs e) @@ -379,29 +374,14 @@ namespace BetterSecondBotShared.bottypes Debug("ChatInputHandler proc not overridden"); } - protected virtual void CoreCommandLib(UUID fromUUID, bool from_accepted_avatar, string command, string arg) - { - CoreCommandLib(fromUUID, from_accepted_avatar, command, arg, ""); - } - - protected virtual void CoreCommandLib(UUID fromUUID, bool from_accepted_avatar, string command, string arg, string signing_code) - { - CoreCommandLib(fromUUID, from_accepted_avatar, command, arg, signing_code, "~#~"); - } - - protected virtual void CoreCommandLib(UUID fromUUID,bool from_accepted_avatar,string command,string arg,string signing_code,string signed_with) - { - Debug("CoreCommandLib proc not overridden"); - } - public virtual void ResetAnimations() - { - Debug("reset_animations not enabled at this level"); + { + Debug("reset_animations not enabled at this level"); } public virtual void Warn(string message) { - Log2File(LogFormater.Warn(message,false), ConsoleLogLogLevel.Warn); + Log2File(LogFormater.Warn(message, false), ConsoleLogLogLevel.Warn); } public virtual void Crit(string message) { From 91c0c2fa1d6810cec1a8535d039f8ba7d6e8e88b Mon Sep 17 00:00:00 2001 From: Madpeterz <57852827+Madpeterz@users.noreply.github.com> Date: Thu, 18 Feb 2021 10:34:22 +0000 Subject: [PATCH 5/5] Cleanup and removing old systems goodbye Discord webhook relay (You will return as part of the custom_relay system later) goodbye DiscordTTS system (used for a bit) goodbye RelayIMToAvatar (The custom relay system is better) --- BetterSecondbot/CliDocker.cs | 2 +- BetterSecondbot/CliHardware.cs | 2 +- .../DiscordSupervisor/ChannelControl.cs | 2 +- .../DiscordTTS/DiscordTTS.cs | 77 ------------------- BetterSecondbot/DiscordSupervisor/Inbound.cs | 38 ++++++--- BetterSecondbot/DiscordSupervisor/relay.cs | 26 ------- BetterSecondbot/Dockerfile | 9 --- Core/bottypes/CommandsBot.cs | 11 ++- Core/bottypes/MessageSwitcherBot.cs | 27 +------ Shared/Json/JsonConfig.cs | 13 ---- Shared/Json/JsonConfigApi.cs | 58 +------------- 11 files changed, 44 insertions(+), 221 deletions(-) delete mode 100644 BetterSecondbot/DiscordSupervisor/DiscordTTS/DiscordTTS.cs diff --git a/BetterSecondbot/CliDocker.cs b/BetterSecondbot/CliDocker.cs index a455c7e..122ba0c 100644 --- a/BetterSecondbot/CliDocker.cs +++ b/BetterSecondbot/CliDocker.cs @@ -18,7 +18,7 @@ namespace BetterSecondBot LogFormater.Status("-> Getting config from Docker"); JsonConfig Config = MakeJsonConfig.FromENV(); Config = MakeJsonConfig.Http_config_check(Config); - new DiscordTTS(Config,true); + new Discord_super(Config,true); } } } diff --git a/BetterSecondbot/CliHardware.cs b/BetterSecondbot/CliHardware.cs index 6b9574f..4b7b54f 100644 --- a/BetterSecondbot/CliHardware.cs +++ b/BetterSecondbot/CliHardware.cs @@ -79,7 +79,7 @@ namespace BetterSecondBot if(ok_to_try_start == true) { Config = MakeJsonConfig.Http_config_check(Config); - new DiscordTTS(Config, false); + new Discord_super(Config, false); } } } diff --git a/BetterSecondbot/DiscordSupervisor/ChannelControl.cs b/BetterSecondbot/DiscordSupervisor/ChannelControl.cs index a5aeed6..e0d8972 100644 --- a/BetterSecondbot/DiscordSupervisor/ChannelControl.cs +++ b/BetterSecondbot/DiscordSupervisor/ChannelControl.cs @@ -177,7 +177,7 @@ namespace BetterSecondBot.DiscordSupervisor string display_topic = "" + channeltopictype + ":" + sender_id + ""; if (channelname == "interface") { - display_topic = "Actions -> !clear, !commands, !help command or command"; + display_topic = "Actions -> !clear, !commands"; } else if (channelname == "status") { diff --git a/BetterSecondbot/DiscordSupervisor/DiscordTTS/DiscordTTS.cs b/BetterSecondbot/DiscordSupervisor/DiscordTTS/DiscordTTS.cs deleted file mode 100644 index 626dab0..0000000 --- a/BetterSecondbot/DiscordSupervisor/DiscordTTS/DiscordTTS.cs +++ /dev/null @@ -1,77 +0,0 @@ -using System; -using System.Collections.Generic; -using OpenMetaverse; -using Discord; -using BetterSecondBotShared.Static; -using Discord.WebSocket; -using System.Threading.Tasks; -using System.Linq; -using BetterSecondBotShared.Json; - -namespace BetterSecondBot.DiscordSupervisor -{ - public class DiscordTTS : Discord_super - { - public DiscordTTS(JsonConfig configfile, bool as_docker) : base(configfile, as_docker) - { - - } - protected ITextChannel TTSchannel; - protected IGuild TTSDiscordServer; - protected override async Task DiscordClientReady() - { - await base.DiscordClientReady(); - if (myconfig.DiscordTTS_Enable == true) - { - TTSDiscordServer = DiscordClient.GetGuild(myconfig.DiscordTTS_server_id); - if (TTSDiscordServer != null) - { - IGuildUser user = await TTSDiscordServer.GetCurrentUserAsync(); - await user.ModifyAsync(x => - { - x.Nickname = myconfig.DiscordTTS_Nickname; - }); - FindTTsChannel(); - } - } - return Task.CompletedTask; - } - - protected async void FindTTsChannel() - { - if (myconfig.DiscordTTS_Enable == true) - { - TTSchannel = await FindTextChannel(TTSDiscordServer, myconfig.DiscordTTS_channel_name); - } - } - - protected override async Task DiscordIMMessage(UUID sender_uuid, string sender_name, string message) - { - if (myconfig.DiscordTTS_Enable == true) - { - if ((helpers.notempty(sender_name) == true) && (helpers.notempty(message) == true)) - { - if (sender_uuid.ToString() == myconfig.DiscordTTS_avatar_uuid) - { - if (TTSchannel == null) - { - FindTTsChannel(); - } - if (TTSchannel != null) - { - await TTSchannel.SendMessageAsync(message, true); - } - } - else - { - await base.DiscordIMMessage(sender_uuid, sender_name, message); - } - } - } - else - { - await base.DiscordIMMessage(sender_uuid, sender_name, message); - } - } - } -} diff --git a/BetterSecondbot/DiscordSupervisor/Inbound.cs b/BetterSecondbot/DiscordSupervisor/Inbound.cs index 6c821c8..90375d8 100644 --- a/BetterSecondbot/DiscordSupervisor/Inbound.cs +++ b/BetterSecondbot/DiscordSupervisor/Inbound.cs @@ -92,14 +92,12 @@ namespace BetterSecondBot.DiscordSupervisor { if (message.Content == "!commands") { - await SendMessageToChannelAsync("interface", "broken", "bot", UUID.Zero, "bot"); - } - else if (message.Content.StartsWith("!help") == true) - { - await SendMessageToChannelAsync("interface", "broken", "bot", UUID.Zero, "bot"); + string[] commands = controler.Bot.getFullListOfCommands(); + await SendMessageToChannelAsync("interface", string.Join("\n",commands)+ " \n For more details please see the wiki \n https://wiki.magicmadpeter.xyz/", "bot", UUID.Zero, "bot"); } else { + await MarkMessage(message, "❌").ConfigureAwait(false); output.Append("Unknown request: "); output.Append(message.Content); await SendMessageToChannelAsync("interface", output.ToString(), "bot", UUID.Zero, "bot"); @@ -107,6 +105,24 @@ namespace BetterSecondBot.DiscordSupervisor } else { + string[] bits = message.Content.Split("|||"); + if(bits.Length >= 2) + { + string target = "None"; + if (bits.Length == 3) + { + target = bits[2]; + } + if (controler.Bot.getFullListOfCommands().Contains(bits[0].ToLowerInvariant()) == true) + { + controler.Bot.CallAPI(bits[0], bits[1].Split("~#~"), target); + await MarkMessage(message, "✅").ConfigureAwait(false); + } + else + { + await MarkMessage(message, "❌").ConfigureAwait(false); + } + } await MarkMessage(message, "❌").ConfigureAwait(false); } } @@ -128,7 +144,7 @@ namespace BetterSecondBot.DiscordSupervisor else { await MarkMessage(message, "⏳").ConfigureAwait(true); - Thread.Sleep(200); + Thread.Sleep(400); string[] bits = Chan.Topic.Split(':'); if (bits.Length >= 2) { @@ -180,16 +196,14 @@ namespace BetterSecondBot.DiscordSupervisor } Noticetitle = Noticetitle.Replace("!notice ", ""); Noticetitle = Noticetitle.Trim(); - //controler.Bot.GetCommandsInterface.Call("GroupNotice", "" + group.ToString() + "~#~" + Noticetitle + "~#~" + Noticemessage, UUID.Zero); - //await MarkMessage(message, "✅"); - await MarkMessage((IUserMessage)message, "❌").ConfigureAwait(false); + controler.Bot.CallAPI("Groupnotice", new string[] { Noticetitle, Noticemessage }); + await MarkMessage(message, "✅"); } else { IGuildUser user = (IGuildUser)message.Author; - //controler.Bot.GetCommandsInterface.Call("Groupchat", "" + group.ToString() + "~#~" + message.Content, UUID.Zero); - //await MarkMessage(message, "✅"); - await MarkMessage((IUserMessage)message, "❌").ConfigureAwait(false); + controler.Bot.CallAPI("Groupchat", new string[] { group.ToString(), message.Content }); + await MarkMessage(message, "✅"); } } } diff --git a/BetterSecondbot/DiscordSupervisor/relay.cs b/BetterSecondbot/DiscordSupervisor/relay.cs index a3762a4..e7a78e0 100644 --- a/BetterSecondbot/DiscordSupervisor/relay.cs +++ b/BetterSecondbot/DiscordSupervisor/relay.cs @@ -60,32 +60,6 @@ namespace BetterSecondBot.DiscordSupervisor { if (fromme == false) { - if (discord_group_relay == true) - { - // GroupChat Relay only - if (group == true) - { - if (myconfig.DiscordRelay_URL != "") - { - if ((myconfig.DiscordRelay_GroupUUID == group_uuid.ToString()) || (myconfig.DiscordRelay_GroupUUID == "*") || (myconfig.DiscordRelay_GroupUUID == "all")) - { - Group Gr = controler.Bot.MyGroups[group_uuid]; - try - { - using var DWHclient = new DiscordWebhookClient(myconfig.DiscordRelay_URL); - string SendMessage = "(" + Gr.Name + ") @" + sender_name + ":" + message + ""; - await DWHclient.SendMessageAsync(text: SendMessage).ConfigureAwait(false); - DWHclient.Dispose(); - } - catch - { - controler.Bot.Info("Discord web hook has failed - marking as disabled untill next restart!"); - myconfig.DiscordRelay_URL = ""; - } - } - } - } - } if (DiscordClientConnected == true) { if (avatar == true) diff --git a/BetterSecondbot/Dockerfile b/BetterSecondbot/Dockerfile index ce22268..67c2de3 100644 --- a/BetterSecondbot/Dockerfile +++ b/BetterSecondbot/Dockerfile @@ -37,12 +37,9 @@ ENV Security_WebUIKey='' ENV Setting_AllowRLV='false' ENV Setting_AllowFunds='false' ENV Setting_LogCommands='false' -ENV Setting_RelayImToAvatarUUID='' ENV Setting_DefaultSit_UUID='' ENV Setting_loginURI='secondlife' -ENV DiscordRelay_URL='' -ENV DiscordRelay_GroupUUID='' ENV DiscordFull_Enable='false' ENV DiscordFull_Token='' ENV DiscordFull_ServerID='' @@ -55,12 +52,6 @@ ENV Name2Key_Enable='false' ENV Name2Key_Url='http://localhost:1234' ENV Name2Key_Key='magic' -ENV DiscordTTS_Enable='false' -ENV DiscordTTS_server_id='' -ENV DiscordTTS_channel_name='' -ENV DiscordTTS_avatar_uuid='' -ENV DiscordTTS_Nickname='' - ENV Log2File_Enable='false' ENV Log2File_Level=1 diff --git a/Core/bottypes/CommandsBot.cs b/Core/bottypes/CommandsBot.cs index 07743ef..045b632 100644 --- a/Core/bottypes/CommandsBot.cs +++ b/Core/bottypes/CommandsBot.cs @@ -84,7 +84,6 @@ namespace BetterSecondBot.bottypes Client.Self.InstantMessage(avatar, message); } - protected Dictionary Scripts_content = new Dictionary(); protected Dictionary notecards_content = new Dictionary(); protected Dictionary> group_invite_lockout_timer = new Dictionary>(); protected long last_cleanup_commands; @@ -140,6 +139,16 @@ namespace BetterSecondBot.bottypes base.AfterBotLoginHandler(); } + public string[] getFullListOfCommands() + { + List output = new List(); + foreach(string A in endpointcommandmap.Keys) + { + output.Add(A.ToLowerInvariant()); + } + return output.ToArray(); + } + public void NotecardAddContent(string target_notecard_storage_id, string content) { NotecardAddContent(target_notecard_storage_id, content, true, "\n\r"); diff --git a/Core/bottypes/MessageSwitcherBot.cs b/Core/bottypes/MessageSwitcherBot.cs index c955c87..aef321a 100644 --- a/Core/bottypes/MessageSwitcherBot.cs +++ b/Core/bottypes/MessageSwitcherBot.cs @@ -75,32 +75,7 @@ namespace BetterSecondBot.bottypes { BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, false); } - protected override void BotChatControler(string message, string sender_name, UUID sender_uuid, bool avatar,bool group, UUID group_uuid, bool localchat,bool fromme) - { - base.BotChatControler(message, sender_name, sender_uuid, avatar, group, group_uuid, localchat, fromme); - if (fromme == false) - { - if (localchat == false) - { - if(avatar == true) - { - if (myconfig.Setting_RelayImToAvatarUUID != null) - { - if (myconfig.Setting_RelayImToAvatarUUID != UUID.Zero.ToString()) - { - if (myconfig.Setting_RelayImToAvatarUUID.Length == UUID.Zero.ToString().Length) - { - if (UUID.TryParse(myconfig.Setting_RelayImToAvatarUUID, out UUID targetav) == true) - { - Client.Self.InstantMessage(targetav, "Relay-> " + sender_name + ": " + message + ""); - } - } - } - } - } - } - } - } + protected override void MessageHandler(object sender, InstantMessageEventArgs e) { bool fromme = false; diff --git a/Shared/Json/JsonConfig.cs b/Shared/Json/JsonConfig.cs index 398699d..cab6c00 100644 --- a/Shared/Json/JsonConfig.cs +++ b/Shared/Json/JsonConfig.cs @@ -40,14 +40,9 @@ namespace BetterSecondBotShared.Json // Settings public bool Setting_AllowRLV { get; set; } public bool Setting_AllowFunds { get; set; } - public string Setting_RelayImToAvatarUUID { get; set; } public string Setting_DefaultSit_UUID { get; set; } public string Setting_loginURI { get; set; } - // Discord Relay - public string DiscordRelay_URL { get; set; } - public string DiscordRelay_GroupUUID { get; set; } - // Discord FullFat public bool DiscordFull_Enable { get; set; } public string DiscordFull_Token { get; set; } @@ -64,14 +59,6 @@ namespace BetterSecondBotShared.Json public string Name2Key_Url { get; set; } public string Name2Key_Key { get; set; } - - // TTS - public bool DiscordTTS_Enable { get; set; } - public ulong DiscordTTS_server_id { get; set; } - public string DiscordTTS_channel_name { get; set; } - public string DiscordTTS_avatar_uuid { get; set; } - public string DiscordTTS_Nickname { get; set; } - // Logs public bool Log2File_Enable { get; set; } public int Log2File_Level { get; set; } diff --git a/Shared/Json/JsonConfigApi.cs b/Shared/Json/JsonConfigApi.cs index bbbe441..d2068fb 100644 --- a/Shared/Json/JsonConfigApi.cs +++ b/Shared/Json/JsonConfigApi.cs @@ -72,10 +72,6 @@ namespace BetterSecondBotShared.Json { return "Allow the bot to transfer L$ and get a non zero balance"; } - else if (cmd == "Setting_RelayImToAvatarUUID") - { - return "UUID of who the bot should relay IMs to in secondlife"; - } else if (cmd == "Setting_DefaultSit_UUID") { return "UUID of a object the bot should attempt to sit on after logging in"; @@ -93,15 +89,7 @@ namespace BetterSecondBotShared.Json protected string GetHelp_Discord(string cmd) { // Discord - if (cmd == "DiscordRelay_URL") - { - return "The webhook URL to send group chat to"; - } - else if (cmd == "DiscordRelay_GroupUUID") - { - return "The group UUID to relay group chat for"; - } - else if (cmd == "DiscordFull_Enable") + if (cmd == "DiscordFull_Enable") { return "Allow the bot to fully connect to discord (Disables relay)"; } @@ -132,31 +120,7 @@ namespace BetterSecondBotShared.Json } return ""; } - protected string GetHelp_DiscordTTS(string cmd) - { - // Discord TTS - if (cmd == "DiscordTTS_Enable") - { - return "Enable discord TTS helper (Requires DiscordFull_Enable set to true) "; - } - else if (cmd == "DiscordTTS_server_id") - { - return "The server ID to use for TTS"; - } - else if (cmd == "DiscordTTS_channel_name") - { - return "The channel name to use (found on the server set by DiscordTTS_server_id)"; - } - else if (cmd == "DiscordTTS_avatar_uuid") - { - return "The avatar UUID whos IMs will be turned into TTS"; - } - else if (cmd == "DiscordTTS_Nickname") - { - return "The nickname to use on the TTS server"; - } - return ""; - } + protected string GetHelp_Logs(string cmd) { // Logs @@ -186,7 +150,6 @@ namespace BetterSecondBotShared.Json if (cmd.StartsWith("Basic") == true) { return GetHelp_Basic(cmd); } else if (cmd.StartsWith("Security") == true) { return GetHelp_Security(cmd); } else if (cmd.StartsWith("Settings") == true) { return GetHelp_Settings(cmd); } - else if (cmd.StartsWith("DiscordTTS") == true) { return GetHelp_DiscordTTS(cmd); } else if (cmd.StartsWith("Discord") == true) { return GetHelp_Discord(cmd); } else if (cmd.StartsWith("Http_") == true) { return GetHelp_HTTP(cmd); } else { return GetHelp_Logs(cmd); } @@ -243,7 +206,6 @@ namespace BetterSecondBotShared.Json // Settings if (cmd == "Setting_AllowRLV") { return "False"; } else if (cmd == "Setting_AllowFunds") { return "True"; } - else if (cmd == "Setting_RelayImToAvatarUUID") { return ""; } else if (cmd == "Setting_DefaultSit_UUID") { return ""; } else if (cmd == "Setting_loginURI") { return "secondlife"; } else if (cmd == "Setting_LogCommands") { return "True"; } @@ -252,9 +214,7 @@ namespace BetterSecondBotShared.Json protected string GetValueHint_Discord(string cmd) { // Discord - if (cmd == "DiscordRelay_URL") { return ""; } - else if (cmd == "DiscordRelay_GroupUUID") { return ""; } - else if (cmd == "DiscordFull_Enable") { return "False"; } + if (cmd == "DiscordFull_Enable") { return "False"; } else if (cmd == "DiscordFull_Token") { return ""; } else if (cmd == "DiscordFull_ServerID") { return ""; } else if (cmd == "DiscordFull_Keep_GroupChat") { return "False"; } @@ -267,16 +227,7 @@ namespace BetterSecondBotShared.Json else if (cmd == "Http_Host") { return "http://*:8080"; } return ""; } - protected string GetValueHint_DiscordTTS(string cmd) - { - // Discord TTS - if (cmd == "DiscordTTS_Enable") { return "False"; } - else if (cmd == "DiscordTTS_server_id") { return ""; } - else if (cmd == "DiscordTTS_channel_name") { return ""; } - else if (cmd == "DiscordTTS_avatar_uuid") { return ""; } - else if (cmd == "DiscordTTS_Nickname") { return ""; } - return ""; - } + protected string GetValueHint_Logs(string cmd) { // Logs @@ -294,7 +245,6 @@ namespace BetterSecondBotShared.Json if (cmd.StartsWith("Basic") == true) { return GetValueHint_Basic(cmd); } else if (cmd.StartsWith("Security") == true) { return GetValueHint_Security(cmd); } else if (cmd.StartsWith("Setting_") == true) { return GetValueHint_Settings(cmd); } - else if (cmd.StartsWith("DiscordTTS_") == true) { return GetValueHint_DiscordTTS(cmd); } else if (cmd.StartsWith("Discord") == true) { return GetValueHint_Discord(cmd); } else if (cmd.StartsWith("Http_") == true) { return GetValueHint_HTTP(cmd); } else { return GetValueHint_Logs(cmd); }