From c40c551316c0bdc357489e5e00125cec3ead07b0 Mon Sep 17 00:00:00 2001
From: Madpeter <57852827+Madpeterz@users.noreply.github.com>
Date: Wed, 1 Oct 2025 10:00:08 +0100
Subject: [PATCH] Add async inventory contents retrieval method
Introduces AsyncInventoryContents to fetch folder contents asynchronously, allowing non-blocking operations. Also updates documentation for the blocking method to clarify its behavior and output format.
---
SecondBotEvents/Commands/Inventory.cs | 25 +++++++++++++++++++++++--
1 file changed, 23 insertions(+), 2 deletions(-)
diff --git a/SecondBotEvents/Commands/Inventory.cs b/SecondBotEvents/Commands/Inventory.cs
index 3d782b3..e3831fb 100644
--- a/SecondBotEvents/Commands/Inventory.cs
+++ b/SecondBotEvents/Commands/Inventory.cs
@@ -1060,8 +1060,8 @@ namespace SecondBotEvents.Commands
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")]
+ [About("[Blocking] Requests the contents of a folder as an array of InventoryMapItem
Can block for upto 45 secs!")]
+ [ReturnHints("array of InventoryMapItem Formated as follows
InventoryMapItem
- id: UUID
- name: String
- typename: String
")]
[ReturnHintsFailure("Invaild folder UUID")]
[ArgHints("folderUUID", "the folder to fetch (Found via: inventory/folders)","UUID")]
[CmdTypeGet()]
@@ -1074,6 +1074,27 @@ namespace SecondBotEvents.Commands
return BasicReply(HelperInventory.MapFolderInventoryJson(GetClient(), folder), [folderUUID]);
}
+ [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:\"\"")]
+ [ReturnHintsFailure("Invaild folder UUID")]
+ [ArgHints("folderUUID", "the folder to fetch (Found via: inventory/folders)", "UUID")]
+ [CmdTypeGet()]
+ public object AsyncInventoryContents(string folderUUID, string replyto)
+ {
+ if (UUID.TryParse(folderUUID, out UUID folder) == false)
+ {
+ return Failure("Invaild folder UUID", [folderUUID]);
+ }
+ string request = UUID.Random().Guid.ToString();
+ Task.Run(() => {
+ string results = HelperInventory.MapFolderInventoryJson(GetClient(), folder);
+ string reply = new InventoryAsyncReply(request, true, folderUUID, results).ToJson();
+ master.CommandsService.SmartCommandReply(replyto, reply, "AsyncInventoryContents");
+ });
+ return BasicReply(request, [folderUUID, replyto]);
+ }
+
[About("creates a folder in a folder")]
[ReturnHints("Ok")]
[ReturnHintsFailure("invaild parent folder UUID")]