LDDestroier

STD-GUI Discover List

Nov 13th, 2016
969
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.99 KB | None | 0 0
  1. local tArg = {...}
  2. local scr_x,scr_y = term.getSize()
  3. local cprint = function(txt,y)
  4.     local cX,cY = term.getCursorPos()
  5.     term.setCursorPos(math.ceil(scr_x/2)-math.floor(#txt/2),y or cY)
  6.     print(txt)
  7. end
  8. --[[
  9. if tArg[1] == "storelengthcheck" then
  10.     return false, 0
  11. end
  12. if term.isColor() then
  13.     term.setBackgroundColor(colors.gray)
  14.     term.setTextColor(colors.white)
  15. end
  16. term.clear()
  17. cprint("Sorry, but the Discover list is",3)
  18. cprint("down for maintainance.",4)
  19. cprint("Please check later.",6)
  20. sleep(0)
  21. os.pullEvent("char")
  22. if true then
  23.     return false, 0
  24. end
  25. --]]
  26. if not std then std = {} end
  27. local getTableNum = function(tbl,str)
  28.     for a = 1, #tbl do
  29.         if tbl[a] == str then
  30.             return a
  31.         end
  32.     end
  33.     return false
  34. end
  35. local Headers = {["User-Agent"] = "DiscoverAPI",["User-Net"] = "DiscoverNetwork"}
  36. local url, query = "https://discoverapi.xyz/api/store", "cmd=list_categories"
  37. local req = http.post(url, query, Headers)
  38. if not req then
  39.     return false
  40. end
  41. req = textutils.unserialize(req.readAll())
  42. std.storeCatagoryNames = req.data
  43.  
  44. query = "cmd=list_apps"
  45. req = http.post(url, query, Headers)
  46. if not req then
  47.     return false
  48. end
  49. req = textutils.unserialize(req.readAll()).data
  50. std.storeURLs = {}
  51. if tArg[1] == "storelengthcheck" then
  52.     return true, #req
  53. end
  54. local buffer,r
  55. for a = 1, #req do
  56.     r = req[a]
  57.     buffer = {
  58.         title = r.name,
  59.         url = {r.id}, --gotta interpret that differently than string URLs
  60.         creator = r.creator,
  61.         description = r.description,
  62.         catagory = getTableNum(std.storeCatagoryNames,r.category),
  63.         forumPost = "N/A ",
  64.         keywords = {tostring(r.id)},
  65.     }
  66.     std.storeURLs[r.id] = buffer
  67. end
  68.  
  69. std.contextualGet = function(appid)
  70.     local url = "https://discoverapi.xyz/api/store"
  71.     local query = "cmd=download&appid="..tostring(appid)
  72.     local Headers = {["User-Agent"] = "DiscoverAPI",["User-Net"] = "DiscoverNetwork"}
  73.     local contents = http.post(url, query, Headers)
  74.     return contents
  75. end
  76. return true
Add Comment
Please, Sign In to add comment