mirror of
https://github.com/SquidDev-CC/CC-Tweaked
synced 2025-10-28 04:17:38 +00:00
Merge branch 'master' into mc-1.14.x
This commit is contained in:
@@ -5,3 +5,4 @@ ex:
|
||||
"wget http://pastebin.com/raw/CxaWmPrX test" will download the file from the URL http://pastebin.com/raw/CxaWmPrX, and save it as "test".
|
||||
"wget http://example.org/test.lua/?foo=bar#qzu" will download the file from the URL http://example.org/test.lua/?foo=bar#qzu and save it as "test.lua"
|
||||
"wget http://example.org/" will download the file from the URL http://example.org and save it as "example.org"
|
||||
"wget run http://pastebin.com/raw/CxaWmPrX" will download the file from the URL http://pastebin.com/raw/CxaWmPrX and run it immediately.
|
||||
|
||||
15
src/main/resources/data/computercraft/lua/rom/motd.txt
Normal file
15
src/main/resources/data/computercraft/lua/rom/motd.txt
Normal file
@@ -0,0 +1,15 @@
|
||||
View the source code at https://github.com/SquidDev-CC/CC-Tweaked
|
||||
View the documentation at https://wiki.computercraft.cc
|
||||
Visit the forum at https://forums.computercraft.cc
|
||||
You can disable these messages by running "set motd.enable false"
|
||||
You can create directories with "mkdir".
|
||||
Want to see hidden files? Run "set list.show_hidden true".
|
||||
Run "list" or "ls" to see all files in a directory.
|
||||
You can delete files and directories with "delete" or "rm".
|
||||
Use "pastebin put" to upload a program to pastebin.
|
||||
Use "pastebin get" to download a program from pastebin.
|
||||
Use "pastebin run" to run a program from pastebin.
|
||||
Use the "edit" program to create and edit your programs.
|
||||
You can copy files with "copy" or "cp".
|
||||
You can use "wget run <url>" to run a program from the internet.
|
||||
You can use "wget" to download a file from the internet.
|
||||
@@ -15,6 +15,10 @@ if #tFiles > 0 then
|
||||
elseif #tFiles == 1 then
|
||||
if fs.exists( sDest ) then
|
||||
printError( "Destination exists" )
|
||||
elseif fs.isReadOnly( sDest ) then
|
||||
printError( "Destination is read-only" )
|
||||
elseif fs.getFreeSpace( sDest ) < fs.getSize( sFile ) then
|
||||
printError( "Not enough space" )
|
||||
else
|
||||
fs.copy( sFile, sDest )
|
||||
end
|
||||
|
||||
@@ -2,14 +2,24 @@
|
||||
local function printUsage()
|
||||
print( "Usage:" )
|
||||
print( "wget <url> [filename]" )
|
||||
print( "wget run <url>" )
|
||||
end
|
||||
|
||||
local tArgs = { ... }
|
||||
|
||||
local run = false
|
||||
if tArgs[1] == "run" then
|
||||
table.remove( tArgs, 1 )
|
||||
run = true
|
||||
end
|
||||
|
||||
if #tArgs < 1 then
|
||||
printUsage()
|
||||
return
|
||||
end
|
||||
|
||||
local url = table.remove( tArgs, 1 )
|
||||
|
||||
if not http then
|
||||
printError( "wget requires http API" )
|
||||
printError( "Set http_enable to true in ComputerCraft.cfg" )
|
||||
@@ -22,6 +32,13 @@ local function getFilename( sUrl )
|
||||
end
|
||||
|
||||
local function get( sUrl )
|
||||
-- Check if the URL is valid
|
||||
local ok, err = http.checkURL( url )
|
||||
if not ok then
|
||||
printError( err or "Invalid URL." )
|
||||
return
|
||||
end
|
||||
|
||||
write( "Connecting to " .. sUrl .. "... " )
|
||||
|
||||
local response = http.get( sUrl , nil , true )
|
||||
@@ -37,29 +54,34 @@ local function get( sUrl )
|
||||
return sResponse
|
||||
end
|
||||
|
||||
-- Determine file to download
|
||||
local sUrl = tArgs[1]
|
||||
if run then
|
||||
local res = get(url)
|
||||
if not res then return end
|
||||
|
||||
--Check if the URL is valid
|
||||
local ok, err = http.checkURL( sUrl )
|
||||
if not ok then
|
||||
printError( err or "Invalid URL." )
|
||||
return
|
||||
end
|
||||
local func, err = load(res, getFilename(url), "t", _ENV)
|
||||
if not func then
|
||||
printError(err)
|
||||
return
|
||||
end
|
||||
|
||||
local sFile = tArgs[2] or getFilename( sUrl )
|
||||
local sPath = shell.resolve( sFile )
|
||||
if fs.exists( sPath ) then
|
||||
print( "File already exists" )
|
||||
return
|
||||
end
|
||||
local ok, err = pcall(func, table.unpack(tArgs))
|
||||
if not ok then
|
||||
printError( err )
|
||||
end
|
||||
else
|
||||
local sFile = tArgs[1] or getFilename( url )
|
||||
local sPath = shell.resolve( sFile )
|
||||
if fs.exists( sPath ) then
|
||||
print( "File already exists" )
|
||||
return
|
||||
end
|
||||
|
||||
local res = get(url)
|
||||
if not res then return end
|
||||
|
||||
-- Do the get
|
||||
local res = get( sUrl )
|
||||
if res then
|
||||
local file = fs.open( sPath, "wb" )
|
||||
file.write( res )
|
||||
file.close()
|
||||
|
||||
print( "Downloaded as "..sFile )
|
||||
print( "Downloaded as " .. sFile )
|
||||
end
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
local tMotd = {}
|
||||
|
||||
for sPath in string.gmatch(settings.get( "motd.path" ), "[^:]+") do
|
||||
if fs.exists(sPath) then
|
||||
for sLine in io.lines(sPath) do
|
||||
table.insert(tMotd,sLine)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if #tMotd == 0 then
|
||||
print("missingno")
|
||||
else
|
||||
print(tMotd[math.random(1,#tMotd)])
|
||||
end
|
||||
@@ -7,8 +7,15 @@ end
|
||||
local sSource = shell.resolve( tArgs[1] )
|
||||
local sDest = shell.resolve( tArgs[2] )
|
||||
|
||||
if fs.exists( sDest ) then
|
||||
if not fs.exists( sSource ) then
|
||||
printError( "No matching files" )
|
||||
return
|
||||
elseif fs.exists( sDest ) then
|
||||
printError( "Destination exists" )
|
||||
return
|
||||
elseif fs.isReadOnly( sDest ) then
|
||||
printError( "Destination is read-only" )
|
||||
return
|
||||
end
|
||||
|
||||
fs.move( sSource, sDest )
|
||||
|
||||
@@ -183,6 +183,12 @@ local function completeExec( shell, nIndex, sText, tPreviousText )
|
||||
return completeMultipleChoice( sText, tCommands, true )
|
||||
end
|
||||
end
|
||||
local tWgetOptions = { "run" }
|
||||
local function completeWget( shell, nIndex, sText, tPreviousText )
|
||||
if nIndex == 1 then
|
||||
return completeMultipleChoice( sText, tWgetOptions, true )
|
||||
end
|
||||
end
|
||||
shell.setCompletionFunction( "rom/programs/alias.lua", completeAlias )
|
||||
shell.setCompletionFunction( "rom/programs/cd.lua", completeDir )
|
||||
shell.setCompletionFunction( "rom/programs/copy.lua", completeEitherEither )
|
||||
@@ -210,6 +216,7 @@ shell.setCompletionFunction( "rom/programs/fun/advanced/paint.lua", completeFile
|
||||
shell.setCompletionFunction( "rom/programs/http/pastebin.lua", completePastebin )
|
||||
shell.setCompletionFunction( "rom/programs/rednet/chat.lua", completeChat )
|
||||
shell.setCompletionFunction( "rom/programs/command/exec.lua", completeExec )
|
||||
shell.setCompletionFunction( "rom/programs/http/wget.lua", completeWget )
|
||||
|
||||
if turtle then
|
||||
local tGoOptions = { "left", "right", "forward", "back", "down", "up" }
|
||||
|
||||
Reference in New Issue
Block a user