devomaa

imgrab

May 7th, 2020
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.32 KB | None | 0 0
  1. --now with autoupdate!----
  2. ----IMGRAB-------//
  3. --------------/
  4. args = {...}
  5. local function getAPI(api)
  6.   if api == "bigfont" then
  7.     fs.makeDir("apis")
  8.     local pbHandle = http.get("https://pastebin.com/raw/3LfWxRWh")
  9.     local pbContents = pbHandle.readAll()
  10.     local fileHandle = fs.open("/apis/bigfont", "w")
  11.     fileHandle.write(pbContents)
  12.     fileHandle.close()
  13.   end
  14. end
  15. if not fs.exists("/apis/bigfont") then
  16.   getAPI("bigfont")
  17. end
  18. local function loadAPI(file)
  19.   local env = {}
  20.   setmetatable(env, {__index = _G})
  21.   local fn, err = loadfile(file, nil, env)
  22.   if not fn then error(err) end
  23.   fn()
  24.   local api = {}
  25.   for k, v in pairs(env) do
  26.     if k ~= "_ENV" then
  27.       api[k] = v
  28.     end
  29.   end
  30.   return api
  31. end
  32. local function update()
  33.     local fileR = fs.open("imgrab","r")
  34.     local pbHandle = http.get("https://pastebin.com/raw/bvebq8PK")
  35.     local pbContents = pbHandle.readAll()
  36.     if fileR.readAll() ~= pbContents then
  37.         fileR.close()
  38.         fs.delete("imgrab")
  39.         local file = fs.open("imgrab","w")
  40.         file.write(pbContents)
  41.         pbHandle.close()
  42.         file.close()
  43.     end
  44. end
  45. update()
  46. local function useAPI(filename)
  47.   print("Use API?")
  48.   input = read()
  49.   if  string.lower(input) == "y" or string.lower(input) == "yes" then
  50.     local api = loadAPI(filename)
  51.     print("Device ID, (term for terminal")
  52.     input = read()
  53.     if input == "term" then
  54.       api.draw(term)
  55.     else
  56.     print("Is this a device with .setTextScale? (monitors, etc)")  
  57.     inputQuestion = read()
  58.     if string.lower(inputQuestion) == "yes" or string.lower(inputQuestion) == "y" or string.lower(inputQuestion) == "yea"
  59.         local inputDev = peripheral.wrap(input)
  60.         inputDev.setTextScale(0.5)
  61.         api.draw(peripheral.wrap(input))
  62.     else
  63.         api.draw(peripheral.wrap(input))
  64.     end
  65.   else
  66.     error("Done!")
  67.   end
  68. end
  69.  
  70.  
  71. if args[1] == "disk" then
  72.   print("Where is your disk located? (directory-wise)")
  73.   input = read()
  74.   local diskMode = input
  75. end
  76. print("Enter URL")
  77. input = read()
  78. url = "https://tojuroku.switchcraft.pw/?url="..textutils.urlEncode(input)
  79. urlHandle = http.get(url)
  80. local function getContents()
  81.   urlContents = urlHandle.readAll()
  82. end
  83. print("Save or use from web?")
  84. input = read()
  85. if string.lower(input) == "web" or string.lower(input) == "yes" or string.lower(input) == "y" or string.lower(input) == "use" then
  86.   getContents()
  87.   if type(diskMode) == "string" then
  88.     fs.makeDir("/"..diskMode.."/temp")
  89.     fs.makeDir("/"..diskMode.."/temp/imgrab")
  90.     fs.makeDir("/"..diskMode.."/temp/imgrab/XX667700/")
  91.     filename = "/"..diskMode.."/temp/imgrab/XX667700/temp1.lua"
  92.     local file = fs.open(filename, "w")
  93.     file.write(urlContents)
  94.     file.close()
  95.     useAPI(filename)
  96.     fs.delete(filename)
  97.   else
  98.     filename = "/temp/imgrab/XX667700/temp1.lua"
  99.     local file = fs.open(filename, "w")
  100.     file.write(urlContents)
  101.     file.close()
  102.     useAPI(filename)
  103.     fs.delete(filename)
  104.   end
  105. else
  106.   print("Enter Filename")
  107.   input = read()
  108.   if fs.exists(input) then
  109.     printError("File Exists")
  110.     print("Overwrite?")
  111.     input = read()
  112.     input = filename
  113.     if string.lower(input) == "y" or string.lower(input) == "yes" then
  114.       fs.delete(input)
  115.     else
  116.       error("User said no")
  117.     end
  118.   end
  119.   local file = fs.open(input, "w")
  120.   getContents()
  121.   file.write(urlContents)
  122.   useAPI(filename)
  123. end
Add Comment
Please, Sign In to add comment