From cf50efba495951859c496425eb7383fc33428062 Mon Sep 17 00:00:00 2001 From: michaelzoub Date: Thu, 17 Oct 2024 18:13:53 -0400 Subject: [PATCH] add addMyItemsByName function --- lib/classes/TradeOffer.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/lib/classes/TradeOffer.js b/lib/classes/TradeOffer.js index 99c8377..e5325ec 100644 --- a/lib/classes/TradeOffer.js +++ b/lib/classes/TradeOffer.js @@ -174,6 +174,28 @@ TradeOffer.prototype.addMyItems = function(items) { return added; }; +TradeOffer.prototype.addMyItemsByName = function(items) { + return new Promise((resolve, reject) => { + // Find the item by its name in the user's inventory + this.returnedItem.manager.getUserInventoryContents(this.returnedItem.partner, 730, 2, true, (err, items) => { + if (err) { + console.error("Error fetching inventory: ", err); + reject(false); + } + + // Find the item by name + const item = items.find((i) => i.name === itemName); + + if (item) { + const result = this.returnedItem.addMyItem(item); + resolve(result); + } else { + resolve(false); // Item not found + } + }); + }); +}; + TradeOffer.prototype.removeMyItem = function(item) { if (this.id) { throw new Error("Cannot remove items from an already-sent offer");