Add cached inventory mapping and log truncation
Introduces InventoryContentsCatched to return mapped inventory using cached data and adds InventoryNodeEntry for structured inventory representation. Also truncates command log results to 100 characters in CommandsService for improved logging.
This commit is contained in:
parent
c00a11a99d
commit
0139326d67
2 changed files with 51 additions and 0 deletions
|
|
@ -2,6 +2,7 @@
|
|||
using Newtonsoft.Json;
|
||||
using OpenMetaverse;
|
||||
using OpenMetaverse.Assets;
|
||||
using Org.BouncyCastle.Tls;
|
||||
using SecondBotEvents.Services;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
|
@ -1074,6 +1075,44 @@ namespace SecondBotEvents.Commands
|
|||
return BasicReply(HelperInventory.MapFolderInventoryJson(GetClient(), folder), [folderUUID]);
|
||||
}
|
||||
|
||||
|
||||
[About("Requests the mapped inventory on the bot using catched data only")]
|
||||
[ReturnHints("a json data object with: " +
|
||||
"{" +
|
||||
"Name: String"+
|
||||
"UUID: String"+
|
||||
"InventoryType: String"+
|
||||
"Children: null or a copy of this data object"+
|
||||
"}")]
|
||||
[CmdTypeGet()]
|
||||
public object InventoryContentsCatched()
|
||||
{
|
||||
InventoryNodeEntry root = LoadInventoryNode(GetClient().Inventory.Store.RootFolder.UUID,"root");
|
||||
return BasicReply(JsonConvert.SerializeObject(root));
|
||||
}
|
||||
|
||||
protected InventoryNodeEntry LoadInventoryNode(UUID folder, string name="")
|
||||
{
|
||||
InventoryNodeEntry myentry = new InventoryNodeEntry();
|
||||
myentry.Name = name;
|
||||
myentry.UUID = folder.Guid.ToString();
|
||||
myentry.InventoryType = "folder";
|
||||
List<InventoryBase> folderlist = GetClient().Inventory.Store.GetContents(folder);
|
||||
foreach (InventoryBase entry in folderlist)
|
||||
{
|
||||
if(entry is InventoryFolder)
|
||||
{
|
||||
myentry.Children.Add(LoadInventoryNode(entry.UUID, entry.Name));
|
||||
}
|
||||
else if (entry is InventoryItem)
|
||||
{
|
||||
myentry.Children.Add(new InventoryNodeEntry() { Children = null, InventoryType = "item", Name = entry.Name, UUID = entry.UUID.ToString() });
|
||||
}
|
||||
}
|
||||
return myentry;
|
||||
}
|
||||
|
||||
|
||||
[About("Requests the contents of a folder as an array of InventoryMapItem")]
|
||||
[ReturnHints("RequestUUID check the smart reply for results")]
|
||||
[ReturnHints("Smart reply: json object of {request:\"\",status:BOOL,message:\"\",data:\"\"")]
|
||||
|
|
@ -1199,6 +1238,14 @@ namespace SecondBotEvents.Commands
|
|||
}
|
||||
}
|
||||
|
||||
public class InventoryNodeEntry
|
||||
{
|
||||
public string UUID { get; set; }
|
||||
public string Name { get; set; }
|
||||
public List<InventoryNodeEntry> Children { get; set; } = new List<InventoryNodeEntry>();
|
||||
public string InventoryType { get; set; }
|
||||
}
|
||||
|
||||
public class InventoryAsyncReply
|
||||
{
|
||||
public string requestUUID;
|
||||
|
|
|
|||
|
|
@ -446,6 +446,10 @@ namespace SecondBotEvents.Services
|
|||
}
|
||||
if (master.BotClient.basicCfg.GetLogCommands() == true)
|
||||
{
|
||||
if(e.results.Length >= 100)
|
||||
{
|
||||
e.results = e.results.Substring(0, 100) + "...";
|
||||
}
|
||||
LogFormater.Info("Command log:" + JsonConvert.SerializeObject(e));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue