adds new SendFolderByPath command

This commit is contained in:
Madpeter 2024-08-18 15:41:14 +01:00
parent 06c5d5cbe2
commit c338b9c617
2 changed files with 78 additions and 0 deletions

View file

@ -392,6 +392,28 @@ namespace SecondBotEvents.Commands
GetClient().Inventory.GiveItem(itm.UUID, itm.Name, itm.AssetType, avataruuid, false);
return BasicReply("ok", new [] { item, avatar });
}
[About("Sends a folder to an avatar")]
[ReturnHints("ok")]
[ReturnHints("Invaild avatar uuid")]
[ReturnHints("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)
{
ProcessAvatar(avatar);
if (avataruuid == UUID.Zero)
{
return Failure("Invaild avatar uuid", new[] { path, avatar });
}
InventoryFolder FindFolderHelper = HelperInventory.FindFolderByPath(GetClient(), path);
if (FindFolderHelper == null)
{
return Failure("Unable to find folder", new[] { path, avatar });
}
GetClient().Inventory.GiveFolder(FindFolderHelper.UUID, FindFolderHelper.Name, avataruuid, false);
return BasicReply("ok", new[] { path, avatar });
}
[About("Sends a folder to an avatar")]
[ReturnHints("ok")]

View file

@ -1,5 +1,6 @@
using Newtonsoft.Json;
using OpenMetaverse;
using OpenMetaverse.ImportExport.Collada14;
using System;
using System.Collections.Generic;
using System.Text;
@ -34,6 +35,61 @@ namespace BetterSecondBot.Static
}
return UUID.Zero;
}
public static InventoryFolder FindFolderByPath(GridClient bot, string path)
{
return DigFolderForPath(bot, path, 0, bot.Inventory.Store.RootFolder.UUID);
}
private static InventoryFolder DigFolderForPath(GridClient bot, string path, int level, UUID folder)
{
string[] bits = path.Split('/');
List<InventoryBase> T = bot.Inventory.Store.GetContents(folder);
InventoryFolder foundFolder = null;
bool found = false;
foreach (InventoryBase t in T)
{
if (t.GetType() == typeof(InventoryFolder))
{
if (t.Name == bits[level])
{
folder = t.UUID;
if (bits.Length > (level+1))
{
// need to go deeper
foundFolder = DigFolderForPath(bot, path, level + 1, folder);
if (foundFolder != null)
{
found = true;
}
}
else
{
// we are here
foundFolder = (InventoryFolder)t;
found = true;
break;
}
}
else
{
continue;
}
}
else
{
continue;
}
}
if(found == true)
{
return foundFolder;
}
else
{
return null;
}
}
public static InventoryBase FindFolder(GridClient bot, InventoryFolder current,UUID target)
{
List<InventoryBase> T = bot.Inventory.Store.GetContents(current);