diff --git a/SecondBotEvents/Commands/Animation.cs b/SecondBotEvents/Commands/Animation.cs index 8f24bc7..4852f4f 100644 --- a/SecondBotEvents/Commands/Animation.cs +++ b/SecondBotEvents/Commands/Animation.cs @@ -41,7 +41,7 @@ namespace SecondBotEvents.Commands { return BasicReply("Error with gesture", new [] { gesture }); } - InventoryItem itm = GetClient().Inventory.FetchItem(gestureUUID, GetClient().Self.AgentID, new TimeSpan(0, 0, 3)); + InventoryItem itm = GetClient().Inventory.FetchItem(gestureUUID, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); GetClient().Self.PlayGesture(itm.AssetUUID); return BasicReply("Accepted", new [] { gesture }); } diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs index 02d6b9a..289b132 100644 --- a/SecondBotEvents/Commands/Inventory.cs +++ b/SecondBotEvents/Commands/Inventory.cs @@ -74,7 +74,7 @@ namespace SecondBotEvents.Commands { return Failure("Invaild item UUID: "+ item, new [] { item }); } - InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, new TimeSpan(0, 0, 5)); + InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { return Failure("Unable to find item: " + item, new [] { item }); @@ -203,7 +203,7 @@ namespace SecondBotEvents.Commands { return Failure("invaild folder uuid", new[] { folder }); } - List contents = GetClient().Inventory.FolderContents(folderUUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, new TimeSpan(0,0,5)); + List contents = GetClient().Inventory.FolderContents(folderUUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, TimeSpan.FromSeconds(15)); List wareables = new(); if (contents == null) { @@ -264,7 +264,7 @@ namespace SecondBotEvents.Commands { return Failure("Cant find target folder", new [] { name }); } - List contents = GetClient().Inventory.FolderContents(AA.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, new TimeSpan(0, 0, 5)); + List contents = GetClient().Inventory.FolderContents(AA.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByName, TimeSpan.FromSeconds(15)); List wareables = new(); if (contents == null) { @@ -303,7 +303,7 @@ namespace SecondBotEvents.Commands return Failure("Unable to find notecard folder"); } List purge_notecards = new(); - List contents = GetClient().Inventory.FolderContents(NotecardFolder.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByDate, new TimeSpan(0, 0, 5)); + List contents = GetClient().Inventory.FolderContents(NotecardFolder.UUID, GetClient().Self.AgentID, true, true, InventorySortOrder.ByDate, TimeSpan.FromSeconds(15)); foreach (InventoryBase C in contents) { InventoryItem A = (InventoryItem)C; @@ -351,12 +351,12 @@ namespace SecondBotEvents.Commands { return Failure("Invaild avatar uuid", new[] { path, avatar }); } - UUID targetitem = GetClient().Inventory.FindObjectByPath(GetClient().Inventory.Store.RootFolder.UUID, GetClient().Self.AgentID, path, new TimeSpan(0, 0, 3)); + UUID targetitem = GetClient().Inventory.FindObjectByPath(GetClient().Inventory.Store.RootFolder.UUID, GetClient().Self.AgentID, path, TimeSpan.FromSeconds(15)); if(targetitem == UUID.Zero) { return Failure("Unable to find item via path", new[] { path, avatar }); } - InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, new TimeSpan(0, 0, 3)); + InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { return Failure("Unable to find item with found uuid", new[] { path, avatar }); @@ -384,7 +384,7 @@ namespace SecondBotEvents.Commands { return Failure("Invaild item uuid", new [] { item, avatar }); } - InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, new TimeSpan(0, 0, 3)); + InventoryItem itm = GetClient().Inventory.FetchItem(targetitem, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { return Failure("Unable to find item", new [] { item, avatar }); @@ -469,7 +469,7 @@ namespace SecondBotEvents.Commands return Failure("Invaild running", new [] { item, objectuuid, running }); } - InventoryItem itm = GetClient().Inventory.FetchItem(itemuuid, GetClient().Self.AgentID, new TimeSpan(0, 0, 3)); + InventoryItem itm = GetClient().Inventory.FetchItem(itemuuid, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if (itm == null) { return Failure("Unable to find inventory", new [] { item, objectuuid, running }); diff --git a/SecondBotEvents/Commands/Notecard.cs b/SecondBotEvents/Commands/Notecard.cs index 29acd1c..25eb2ab 100644 --- a/SecondBotEvents/Commands/Notecard.cs +++ b/SecondBotEvents/Commands/Notecard.cs @@ -1,5 +1,8 @@ -using OpenMetaverse; +using Newtonsoft.Json; +using OpenMetaverse; +using OpenMetaverse.Assets; using SecondBotEvents.Services; +using static OpenAI.ObjectModels.StaticValues.AssistantsStatics.MessageStatics; namespace SecondBotEvents.Commands @@ -11,6 +14,78 @@ namespace SecondBotEvents.Commands { } + [About("Reads the notecards content, if it is able to read the notecard will give a json reply of notecarduuid name and contents")] + [ReturnHintsFailure("Not a vaild UUID")] + [ReturnHintsFailure("Unable to find inventory item")] + [ReturnHintsFailure("Inventory item is not a notecard")] + [ReturnHintsFailure("replytarget not set")] + [ReturnHints("Making request to get data from notecard")] + [ArgHints("notecardInventoryUUID", "The inventory UUID of the notecard to read")] + [ArgHints("replytarget", "where to send the results to (smartreply target Avatar UUID, HTTP url, chat channel")] + public object NotecardRead(string notecardInventoryUUID, string replytarget) + { + if(SecondbotHelpers.isempty(replytarget) == true) + { + return Failure("replytarget not set"); + } + NotecardReadReply reply = new NotecardReadReply(); + reply.uuid = notecardInventoryUUID; + reply.name = "?"; + reply.status = false; + reply.content = "Not a vaild UUID"; + if (UUID.TryParse(notecardInventoryUUID, out var uuid) == false) + { + master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); + return Failure(reply.content, new[] { notecardInventoryUUID }); + } + reply.content = "Unable to find inventory item"; + InventoryItem item = GetClient().Inventory.FetchItem(uuid, GetClient().Self.AgentID, new System.TimeSpan(0, 1, 30)); + if (item == null) + { + master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); + return Failure(reply.content, new[] { notecardInventoryUUID }); + } + reply.content = "Inventory item is not a notecard"; + if (item.InventoryType != InventoryType.Notecard) + { + master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); + return Failure(reply.content, new[] { notecardInventoryUUID }); ; + } + InventoryNotecard notecard = (InventoryNotecard)item; + GetClient().Assets.RequestInventoryAsset(notecard, true, UUID.Random(), (AssetDownload transfer, Asset asset) => + { + if (transfer.Success == false) + { + reply.content = "!ERROR! - unable to read notecard"; + master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); + } + else + { + AssetNotecard note = (AssetNotecard)asset; + note.Decode(); + string contents = ""; + for (int index = 0; index < note.BodyText.Length; index++) + { + char c = note.BodyText[index]; + if ((int)c == 0xdbc0) + { + contents = "[ATTACHMENT]"; + } + else + { + contents += c; + } + } + reply.content = contents; + reply.name = notecard.Name; + reply.status = true; + master.CommandsService.SmartCommandReply(replytarget, JsonConvert.SerializeObject(reply), "NotecardRead"); + } + } + ); + return BasicReply("Making request to get data from notecard"); + } + [About("Adds content to the Collection
Also creates the Collection if it does not exist")] [ReturnHintsFailure("Collection value is empty")] [ReturnHintsFailure("Content value is empty")] @@ -114,4 +189,12 @@ namespace SecondBotEvents.Commands return BasicReply("ok"); } } + + public class NotecardReadReply + { + public string uuid; + public string name; + public string content; + public bool status; + } } diff --git a/SecondBotEvents/Services/ChatGptService.cs b/SecondBotEvents/Services/ChatGptService.cs index 856e0e5..3b80e13 100644 --- a/SecondBotEvents/Services/ChatGptService.cs +++ b/SecondBotEvents/Services/ChatGptService.cs @@ -337,7 +337,7 @@ namespace SecondBotEvents.Services { return chatHistoryAI[store]; // nothing in memory use the default store } - redisDb.KeyExpire(readkey, new TimeSpan(0, myConfig.GetRedisMaxageMins(), 0)); // update the expire value + redisDb.KeyExpire(readkey, TimeSpan.FromMinutes(myConfig.GetRedisMaxageMins())); // update the expire value return JsonConvert.DeserializeObject>>(rawstring); } return NoRedisStoreFound(store); @@ -459,7 +459,7 @@ namespace SecondBotEvents.Services RedisValue storeme = new RedisValue(savestring); if(redisDb.StringSet(writekey, storeme) == true) { - return redisDb.KeyExpire(writekey, new TimeSpan(0, myConfig.GetRedisMaxageMins(), 0)); + return redisDb.KeyExpire(writekey, TimeSpan.FromMinutes(myConfig.GetRedisMaxageMins())); } return false; } diff --git a/SecondBotEvents/Services/InteractionService.cs b/SecondBotEvents/Services/InteractionService.cs index 79142db..a58333a 100644 --- a/SecondBotEvents/Services/InteractionService.cs +++ b/SecondBotEvents/Services/InteractionService.cs @@ -251,7 +251,7 @@ namespace SecondBotEvents.Services master.DataStoreService.AddAvatar(e.Offer.FromAgentID, e.Offer.FromAgentName); details.Add("itemuuid", e.ObjectID.ToString()); details.Add("itemname", "?"); - InventoryItem itm = GetClient().Inventory.FetchItem(e.ObjectID, GetClient().Self.AgentID, new TimeSpan(0, 0, 2)); + InventoryItem itm = GetClient().Inventory.FetchItem(e.ObjectID, GetClient().Self.AgentID, TimeSpan.FromSeconds(15)); if(itm != null) { details["itemname"] = itm.Name; diff --git a/SecondBotEvents/Static/Inventory.cs b/SecondBotEvents/Static/Inventory.cs index a767527..1622993 100644 --- a/SecondBotEvents/Static/Inventory.cs +++ b/SecondBotEvents/Static/Inventory.cs @@ -24,7 +24,7 @@ namespace BetterSecondBot.Static { public static InventoryItem getItemByInventoryUUID(GridClient bot, UUID target) { - return bot.Inventory.FetchItem(target, bot.Self.AgentID, new TimeSpan(0, 0, 3)); + return bot.Inventory.FetchItem(target, bot.Self.AgentID, TimeSpan.FromSeconds(15)); } public static UUID GetAssetUUID(GridClient bot, UUID target) { @@ -123,7 +123,7 @@ namespace BetterSecondBot.Static mapitem.id = node.Data.UUID.ToString(); mapitem.typename = "Folder"; entrys.Add(mapitem); - List contents = bot.Inventory.FolderContents(folder, bot.Self.AgentID, true, true, InventorySortOrder.ByDate, new TimeSpan(0, 0, 45), true); + List contents = bot.Inventory.FolderContents(folder, bot.Self.AgentID, true, true, InventorySortOrder.ByDate, TimeSpan.FromSeconds(45), true); if (contents != null) { if (contents.Count > 0)