Advertisement
forsakenmaiden

Untitled

Jan 3rd, 2024
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.68 KB | None | 0 0
  1. function syncSwitches()
  2.     os.execute("cls")
  3.     local ios = getRedstoneAddresses()
  4.     print("Starting to sync. This may take a while.")
  5.     for line in io.lines("addresses.txt") do
  6.         if (pcall(function()
  7.             for chunk in internet.request(apiUrl, {
  8.                 key = apiKey,
  9.                 token = apiToken,
  10.                 action = "sync",
  11.                 address = line,
  12.                 type = "switch"
  13.             }) do
  14.             end
  15.         end)) then
  16.             print("Synced '" .. line .. "'.")
  17.         else
  18.             print("Failed to sync '" .. line .. "'. It's already there or something's wrong with the web-server.")
  19.         end
  20.     end
  21.     print("Switches synced!")
  22.     os.sleep(2)
  23.     handleUserInput()
  24. end
  25.  
  26. function syncSwitches()
  27.     os.execute("cls")
  28.     local ios = getRedstoneAddresses()
  29.     print("Starting to sync. This may take a while.")
  30.     for line in io.lines("addresses.txt") do
  31.         local success, response = pcall(function()
  32.             return internet.request(apiUrl, {
  33.                 key = apiKey,
  34.                 token = apiToken,
  35.                 action = "sync",
  36.                 address = line,
  37.                 type = "switch"
  38.             })
  39.         end)
  40.  
  41.         if success then
  42.             if response then
  43.                 print("Synced '" .. line .. "'.")
  44.                 -- Process the response if needed
  45.             else
  46.                 print("Failed to get a response for '" .. line .. "'.")
  47.             end
  48.         else
  49.             print("Failed to sync '" .. line .. "'. Error: " .. tostring(response))
  50.         end
  51.     end
  52.     print("Switches synced!")
  53.     os.sleep(2)
  54.     handleUserInput()
  55. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement