Advertisement
Loneranger419

listItems

Feb 1st, 2025 (edited)
11
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. local logFile = "/.me_items_log_tmp"
  2. local filterKeyword = "drawer" -- Change this keyword if needed
  3.  
  4. local device = peripheral.find("meBridge")
  5.  
  6. if not device then
  7. print("No ME Bridge found!")
  8. return
  9. end
  10.  
  11. local success, items = pcall(device.listItems)
  12.  
  13. if not success or type(items) ~= "table" then
  14. print("Error: Unable to retrieve listItems()")
  15. return
  16. end
  17.  
  18. local file = fs.open(logFile, "w")
  19. file.writeLine("ME Bridge - listItems() Filtered Output (Keyword: " .. filterKeyword .. ")\n")
  20.  
  21. local foundItems = false
  22.  
  23. for slot, data in pairs(items) do
  24. -- Check if any field (name, displayName, tags, etc.) contains "drawer"
  25. local matchFound = false
  26. for key, value in pairs(data) do
  27. if type(value) == "string" and value:lower():match(filterKeyword) then
  28. matchFound = true
  29. break
  30. end
  31. end
  32.  
  33. if matchFound then
  34. foundItems = true
  35. file.writeLine("Slot: " .. tostring(slot))
  36.  
  37. for key, value in pairs(data) do
  38. if type(value) == "table" then
  39. local success, serialized = pcall(textutils.serialize, value)
  40. if success then
  41. file.writeLine(" " .. key .. " = " .. serialized)
  42. else
  43. file.writeLine(" " .. key .. " = [Unserializable Data]")
  44. end
  45. else
  46. file.writeLine(" " .. key .. " = " .. tostring(value))
  47. end
  48. end
  49.  
  50. file.writeLine("-------------------")
  51. end
  52. end
  53.  
  54. file.close()
  55.  
  56. if not foundItems then
  57. print("\nNo items matching keyword '" .. filterKeyword .. "' found.")
  58. fs.delete(logFile)
  59. return
  60. end
  61.  
  62. print("\nUploading to Pastebin...")
  63. local pastebinSuccess = shell.run("pastebin", "put", logFile)
  64.  
  65. if pastebinSuccess then
  66. print("\nPastebin upload successful!")
  67. end
  68.  
  69. fs.delete(logFile)
  70. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement