Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --CCSnippets v0.1
- --Allows you to run snippets by MineRobber9000
- if not http then error("HTTP required.") end
- local function getsetting(sSetting)
- local setting = settings.get(sSetting)
- if sSetting == "ccsnippet.autorun" and setting==nil then setting = true end
- return setting
- end
- local jsonPath = "/"
- local jsonLocation = fs.combine(jsonPath,"json")
- if not fs.exists(jsonLocation) then
- local w = http.get("http://pastebin.com/raw/4nRg9CHU")
- local file = fs.open(jsonLocation,"w")
- if not w then error("Unable to get json API: download it manually at https://pastebin.com/4nRg9CHU; place it at "..jsonLocation) end
- file.write(w.readAll())
- file.close()
- w.close()
- end
- os.loadAPI(jsonLocation)
- local function exit()
- fs.delete(jsonLocation)
- _G.json = nil
- return
- end
- local function usage()
- printError("Argument must be a snippet.")
- printError("Special snippets:")
- printError("list - list snippets")
- exit()
- end
- local tArgs = {...}
- if #tArgs ~= 1 then usage() else
- local web = http.get("http://tilde.town/~minerobber/ccsnippets/snippets.json")
- local obj = json.decode(web.readAll())
- web.close()
- if tArgs[1]=="list" then
- local tSnippets = {}
- for k,v in pairs(obj) do table.insert(tSnippets,k) end
- print("Snippets:")
- if #tSnippets == 0 then print("None.") exit() end
- write(tSnippets[1])
- if #tSnippets > 1 then
- for i=2,#tSnippets do
- write(", "..tSnippets[i])
- end
- end
- print()
- exit()
- else
- for k,v in pairs(obj) do
- if tArgs[1]==k then
- if getsetting("ccsnippet.autorun") then
- local h = fs.open("/.tempsnippet","w")
- h.write(v)
- h.close()
- shell.run("/.tempsnippet")
- fs.delete("/.tempsnippet")
- else
- local h = fs.open(k..".lua","w")
- h.write(v)
- h.close()
- print("Downloaded "..k.."!")
- exit()
- end
- end
- end
- if not snippet == "list" then error("Invalid snippet "..tArgs[1].."!",0) end
- exit()
- end
- end
Add Comment
Please, Sign In to add comment