Tomodachi94

quarrynotifier

Jun 20th, 2026 (edited)
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.86 KB | Source Code | 0 0
  1. -- SPDX-FileCopyrightText: 2026 Tomodachi94
  2. -- SPDX-License-Identifier: MIT
  3. -- Send a notification using ntfy.sh when a BuildCraft Quarry is no longer active.
  4. -- To install: Run "pastebin get n2PRwW0E startup", then restart the computer
  5.  
  6. if not fs.exists("hook") then
  7.     print("Welcome to the quarrynotifier first-time setup!")
  8.     print("To start: visit https://ntfy.sh")
  9.     print("Either install the mobile app, and/or")
  10.     print("visit https://ntfy.sh/app.")
  11.     print("Make sure to enable or allow notifications!")
  12.     print("Then, create a new topic. https://ntfy.sh/app can generate you one if you click Subscribe.")
  13.     print("Then, subscribe to that link on your phone or computer.")
  14.     print("And finally, give me the link that I should send notifications to:")
  15.     write("> ")
  16.     local ntfyTopic = read()
  17.     local f = fs.open("hook", "w")
  18.     f.write(ntfyTopic)
  19.     f.close()
  20.     print("If you ever lose the ntfy link, type 'edit hook'")
  21.     if not os.computerLabel() then
  22.         os.setComputerLabel("quarrynotifier")
  23.     end
  24.     print("This computer will now remember your link when broken.")
  25.  
  26. end
  27.  
  28. local f = fs.open("hook", "r")
  29. local ntfyTopic = f.readLine()
  30. f.close()
  31.  
  32. print("quarrynotifier is finding the quarry...")
  33.  
  34. local quarry
  35. for _,p in pairs(peripheral.getNames()) do
  36.     local attempt = peripheral.wrap(p)
  37.     if type(attempt.isActive) == "function" then
  38.         quarry = attempt
  39.         print("quarrynotifier found a quarry!")
  40.         break
  41.     end
  42. end
  43.  
  44. if not quarry then
  45.     error("quarrynotifier could not find a quarry. The quarry should be placed next to the computer on any side.")
  46. end
  47.  
  48. print("quarrynotifier is waiting for the quarry...")
  49.  
  50. while true do
  51.   os.sleep(5)
  52.   if quarry.isActive() == false then
  53.     print("quarrynotifier detected that the quarry is done!")
  54.     local res = http.post(ntfyTopic, "Your quarry is done!")
  55.     print("quarrynotifier sent a message, exiting...")
  56.     break
  57.   end
  58. end
  59.  
Advertisement
Add Comment
Please, Sign In to add comment