Guest User

redstonenotifier.lua

a guest
Nov 28th, 2024
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.43 KB | None | 0 0
  1. -- IFTTT Redstone Alert Script for ComputerCraft
  2.  
  3. -- Replace 'your_key' with your IFTTT Webhooks key
  4. local ifttt_key = "clyIwla8kLX2m7ACadUXM_" -- Replace with your actual key
  5. local event_name = "redstone_alert" -- The event name you used in IFTTT
  6.  
  7. -- The URL to send the request to
  8. local url = "https://maker.ifttt.com/trigger/" .. event_name .. "/with/key/" .. ifttt_key
  9.  
  10. local url = "https://maker.ifttt.com/trigger/redstone_alert/with/key/clyIwla8kLX2m7ACadUXM_"
  11.  
  12. -- Function to send the HTTP request to IFTTT
  13. local function send_alert()
  14.     local response = http.post(url, "")
  15.     if response then
  16.         print("Alert sent successfully.")
  17.         response.close()
  18.     else
  19.         print("Failed to send alert.")
  20.     end
  21. end
  22.  
  23. -- Main loop
  24. print("Monitoring redstone input...")
  25.  
  26. while true do
  27.     -- Sleep until there is a redstone event
  28.     os.pullEvent("redstone")
  29.    
  30.     -- Check if there is a redstone signal on any side
  31.     for _, side in ipairs(rs.getSides()) do
  32.         if redstone.getInput(side) then
  33.             print("Redstone signal detected on side: " .. side)
  34.             send_alert()
  35.             -- Wait until the signal is removed to prevent multiple alerts
  36.             repeat
  37.                 sleep(1)
  38.             until not redstone.getInput(side)
  39.             print("Signal removed. Resuming monitoring...")
  40.         end
  41.     end
  42.  
  43.     -- Sleep briefly to prevent excessive CPU usage
  44.     sleep(0.1)
  45. end
  46.  
Advertisement
Add Comment
Please, Sign In to add comment