diff --git a/SecondBotEvents/Commands/Avatars.cs b/SecondBotEvents/Commands/Avatars.cs index 6c83c93..1882ee2 100644 --- a/SecondBotEvents/Commands/Avatars.cs +++ b/SecondBotEvents/Commands/Avatars.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using OpenMetaverse; using Newtonsoft.Json; using SecondBotEvents.Services; +using System.Threading.Tasks; namespace SecondBotEvents.Commands { @@ -42,6 +43,97 @@ namespace SecondBotEvents.Commands return BasicReply(JsonConvert.SerializeObject(BetterNearMe)); } + [About("Requests the given avatars profile image")] + [ReturnHints("profile UUID")] + [ReturnHintsFailure("Invaild avatar uuid")] + [ReturnHints("Requesting avatar details [Retry later]")] + [ArgHints("avatar", "a UUID or Firstname Lastname")] + public object GetProfileImage(string avatar) + { + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar uuid", new[] { avatar }); + } + KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(avataruuid); + if(reply.Key == false) + { + return Failure("Requesting avatar details [Retry later]", new[] { avatar }); + } + return BasicReply(reply.Value.ProfileImage.ToString()); + } + + [About("Requests the bot updates its profile image")] + [ReturnHints("ok")] + [ReturnHints("Requesting avatar details [Retry later]")] + [ReturnHintsFailure("Invaild texture uuid")] + [ArgHints("texture", "a UUID of a texture to use")] + public object SetProfileImage(string texture) + { + if (UUID.TryParse(texture, out UUID textureUUID) == false) + { + return Failure("Invaild texture uuid\"", new[] { texture }); + } + KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(GetClient().Self.AgentID); + if (reply.Key == false) + { + return Failure("Requesting avatar details [Retry later]", new[] { texture }); + } + Avatar.AvatarProperties props = reply.Value; + props.ProfileImage = textureUUID; + GetClient().Self.UpdateProfile(props); + return BasicReply("ok"); + } + + [About("Requests the given avatars profile about me")] + [ReturnHints("profile UUID")] + [ReturnHintsFailure("Invaild avatar uuid")] + [ReturnHints("Requesting avatar details [Retry later]")] + [ArgHints("avatar", "a UUID or Firstname Lastname")] + public object GetProfileAbout(string avatar) + { + ProcessAvatar(avatar); + if (avataruuid == UUID.Zero) + { + return Failure("Invaild avatar uuid", new[] { avatar }); + } + KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(avataruuid); + if (reply.Key == false) + { + return Failure("Requesting avatar details [Retry later]", new[] { avatar }); + } + return BasicReply(reply.Value.AboutText.ToString()); + } + + [About("Requests the bot updates its about me")] + [ReturnHints("ok")] + [ReturnHints("Requesting avatar details [Retry later]")] + [ReturnHintsFailure("about text to short")] + [ReturnHintsFailure("about text to long")] + [ArgHints("abouttext", "text to use in the about me area, length 10 to 300")] + public object SetProfileAbout(string abouttext) + { + if(abouttext.Length < 10) + { + return Failure("About text to short", new string[] { abouttext }); + } + else if (abouttext.Length > 300) + { + return Failure("About text to long", new string[] { abouttext }); + } + KeyValuePair reply = master.DataStoreService.GetAvatarAvatarProperties(GetClient().Self.AgentID); + if (reply.Key == false) + { + return Failure("Requesting avatar details [Retry later]", new[] { abouttext }); + } + Avatar.AvatarProperties props = reply.Value; + props.AboutText = abouttext; + GetClient().Self.UpdateProfile(props); + return BasicReply("ok"); + } + + + [About("returns a list of all known avatars nearby")] [ReturnHints("array UUID = Name")] [ReturnHintsFailure("Error not in a sim")] diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs index 87f7b54..4892999 100644 --- a/SecondBotEvents/Commands/Inventory.cs +++ b/SecondBotEvents/Commands/Inventory.cs @@ -394,8 +394,8 @@ namespace SecondBotEvents.Commands } [About("Sends a folder to an avatar")] [ReturnHints("ok")] - [ReturnHints("Invaild avatar uuid")] - [ReturnHints("Unable to find folder")] + [ReturnHintsFailure("Invaild avatar uuid")] + [ReturnHintsFailure("Unable to find folder")] [ArgHints("path", "path to the folder from root")] [ArgHints("avatar", "a UUID or Firstname Lastname")] public object SendFolderByPath(string path, string avatar) diff --git a/SecondBotEvents/Services/DataStoreService.cs b/SecondBotEvents/Services/DataStoreService.cs index 02d2860..82ae539 100644 --- a/SecondBotEvents/Services/DataStoreService.cs +++ b/SecondBotEvents/Services/DataStoreService.cs @@ -43,6 +43,7 @@ namespace SecondBotEvents.Services + protected long lastCleanupKeyValueStore = 0; protected long lastCleanupAvatarStore = 0; @@ -153,7 +154,7 @@ namespace SecondBotEvents.Services int sum = commandHistories.Count + KeyValueStoreLastUsed.Count + KeyValueStore.Count + chatWindowsOwner.Count + chatWindowsIsGroup.Count + chatWindowsUnread.Count + chatWindows.Count + localChatHistory.Count + groupRoles.Count + - groupMembers.Count + groupsKey2Name.Count + avatarsName2Key.Count; + groupMembers.Count + groupsKey2Name.Count + avatarsName2Key.Count + avprops.Count; return sum.ToString(); } @@ -901,6 +902,26 @@ namespace SecondBotEvents.Services } + Dictionary avprops = new Dictionary(); + public KeyValuePair GetAvatarAvatarProperties(UUID agentID) + { + if (avprops.ContainsKey(agentID) == false) + { + GetClient().Avatars.RequestAvatarProperties(agentID); + return new KeyValuePair(false, new Avatar.AvatarProperties()); + } + return new KeyValuePair(true, avprops[agentID]); + } + + protected void AvatarDetailsReply(object sender, AvatarPropertiesReplyEventArgs e) + { + if(avprops.ContainsKey(e.AvatarID) == false) + { + avprops.Add(e.AvatarID,new Avatar.AvatarProperties()); + } + avprops[e.AvatarID] = e.Properties; + } + protected void attachEventsAfterDelay() { GetClient().Groups.CurrentGroups += GroupCurrent; @@ -915,6 +936,7 @@ namespace SecondBotEvents.Services GetClient().Groups.GroupRoleDataReply += GroupRoles; GetClient().Estate.EstateBansReply += EstateBans; GetClient().Friends.FriendFoundReply += FindFriendReply; + GetClient().Avatars.AvatarPropertiesReply += AvatarDetailsReply; GetClient().Groups.RequestCurrentGroups(); GetClient().Self.RetrieveInstantMessages(); } @@ -1130,6 +1152,7 @@ namespace SecondBotEvents.Services GetClient().Groups.GroupRoleDataReply -= GroupRoles; GetClient().Estate.EstateBansReply -= EstateBans; GetClient().Friends.FriendFoundReply -= FindFriendReply; + GetClient().Avatars.AvatarPropertiesReply -= AvatarDetailsReply; } }