local completion = require "cc.shell.completion" local webhooksite = "https://n8n.toondev.net/webhook/TDevCCExportFiles821" local function printUsage() local programName = arg[0] or fs.getName(shell.getRunningProgram()) print("Usage:") print(programName .. " ex ") print(programName .. " in ") print(programName .. " inandrun ") end local function completePastebinPut(shell, text, previous) if previous[2] == "put " then return fs.complete(text, shell.dir(), true, false) end end shell.setCompletionFunction("port", completion.build( { completion.choice, { "ex ", "in ", "inandrun " } }, completePastebinPut )) local tArgs = { ... } if #tArgs < 2 then printUsage() return end if not http then printError("this requires the http API, but it is not enabled") printError("Set http.enabled to true in CC: Tweaked's server config") return end local function get(url) local paste = tArgs[2] write("Connecting to toondev.net... ") local response, err = http.get( "https://ccexport.toondev.net/Files/" .. textutils.urlEncode(paste) ) if response then print("Success.") local sResponse = response.readAll() response.close() return sResponse else io.stderr:write("Failed.\n") print(err) end end local sCommand = tArgs[1] if sCommand == "ex" then -- Upload a file to pastebin.com -- Determine file to upload local sFile = tArgs[2] local sPath = shell.resolve(sFile) if not fs.exists(sPath) then print("No such file") return elseif fs.isDir(sPath) and tArgs[2] ~= "/" then if fs.exists("bbModPack") then shell.run("bbModPack put "..sFile.."") return elseif not fs.exists("bbModPack") then print("bbModPack not found, dowloading") shell.run("wget https://a.toondev.net/bbModPack bbModPack") sleep(1) shell.run("bbModPack put "..sFile.."") return end elseif fs.isDir(sPath) and tArgs[2] == "/" then if fs.exists("bbModPack") then shell.run("bbModPack put") return elseif not fs.exists("bbModPack") then print("bbModPack not found, dowloading") shell.run("wget https://a.toondev.net/bbModPack bbModPack") sleep(1) shell.run("bbModPack put") return end end -- Read in the file local sName = fs.getName(sPath) local file = fs.open(sPath, "r") local sText = file.readAll() file.close() -- POST the contents to pastebin write("Connecting to https... ") local response = http.post( ""..webhooksite.."", "name=" ..textutils.urlEncode(sName).."&".. "code=" ..textutils.urlEncode(sText) ) if response then print("Success.") local sResponse = response.readAll() response.close() local sCode = string.match(sResponse, "[^/]+$") print("Uploaded as " .. sResponse) print("Run \"port in " .. sCode .. "\" to download anywhere") else print("Failed.") end elseif sCommand == "in" then -- Download a file from pastebin.com if #tArgs < 2 then printUsage() return end -- Determine file to download local sCode = tArgs[2] local sFile if not tArgs[3] then sFile = string.match(tArgs[2], "-(.*)") else sFile = tArgs[3] end local sPath = shell.resolve(sFile) if fs.exists(sPath) then print("File already exists") return end -- GET the contents from pastebin local res = get(sCode) if res then local file = fs.open(sPath, "w") file.write(res) file.close() print("Downloaded as " .. sFile) end elseif sCommand == "inandrun" then local sCode = tArgs[2] local res = get(sCode) if res then local func, err = load(res, sCode, "t", _ENV) if not func then printError(err) return end local success, msg = pcall(func, select(3, ...)) if not success then printError(msg) end end else printUsage() return end