Falax

PastebinConnect ComputerCraft - FTB Infinity evolved 1.7.10

Nov 5th, 2020 (edited)
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.17 KB | None | 0 0
  1. -- Original file from IMGOODISHER : https://pastebin.com/aZheqT4C
  2. -- Updated by Falax for FTB Infinity 1.7.10
  3.  
  4. local function printUsage()
  5. print( "Usages:" )
  6. print( "pastebin2 put <filename>" )
  7. print( "pastebin2 get <code> <filename>" )
  8. end
  9. local tArgs = { ... }
  10. if #tArgs < 2 then
  11. printUsage()
  12. return
  13. end
  14. local sCommand = tArgs[1]
  15. if sCommand == "put" then
  16. -- Upload a file to pastebin.com
  17. -- Determine file to upload
  18. local sFile = tArgs[2]
  19. local sPath = shell.resolve( sFile )
  20. if not fs.exists( sPath ) or fs.isDir( sPath ) then
  21. print( "No such file" )
  22. return
  23. end
  24. write("Enter paste name: ")
  25. sName = read()
  26.  
  27. -- Read in the file
  28. if sName == "" then local sName = fs.getName( sPath ) end
  29. local file = fs.open( sPath, "r" )
  30. local sText = file.readAll()
  31. file.close()
  32. -- Log in
  33. print("Log in? y/n")
  34. while true do
  35. login = read()
  36. if login == "y" or login == "n" then break end
  37. end
  38. if login == "y" then
  39. write("Username: ")
  40. username = textutils.urlEncode(read())
  41. write("Password: ")
  42. password = textutils.urlEncode(read("*"))
  43. end
  44. write( "Connecting to pastebin.com... " )
  45. local key = "0ec2eb25b6166c0c27a394ae118ad829"
  46. if login == "y" then
  47. local userraw = http.post(
  48. "https://pastebin.com/api/api_login.php",
  49. "api_dev_key="..key.."&"..
  50. "api_user_name="..username.."&"..
  51. "api_user_password="..password
  52. )
  53. -- get user code in annoying roundabout way
  54. -- error/bug/?: userraw[1]() doesn't work
  55. for i,v in pairs(userraw) do
  56. user = v()
  57. break
  58. end
  59. -- check for errors with pastebin
  60. if string.sub(user, 1, 3) == "Bad" then print("\n"..user) error("") end
  61. local response = http.post(
  62. "https://pastebin.com/api/api_post.php",
  63. "api_option=paste&"..
  64. "api_dev_key="..key.."&"..
  65. "api_user_key="..user.."&"..
  66. "api_paste_format=lua&"..
  67. "api_paste_name="..textutils.urlEncode(sName).."&"..
  68. "api_paste_code="..textutils.urlEncode(sText)
  69. )
  70.  
  71. print("Done")
  72. print("Check your pastes for find your file")
  73. else
  74. local response = http.post(
  75. "https://pastebin.com/api/api_post.php",
  76. "api_option=paste&"..
  77. "api_dev_key="..key.."&"..
  78. "api_paste_format=lua&"..
  79. "api_paste_name="..textutils.urlEncode(sName).."&"..
  80. "api_paste_code="..textutils.urlEncode(sText)
  81. )
  82. if response then
  83. print( "Success." )
  84.  
  85. local sResponse = response.readAll()
  86. response.close()
  87. local sCode = string.match( sResponse, "[^/]+$" )
  88. print( "Uploaded as "..sResponse )
  89. print( "Run \"pastebin get "..sCode.."\" to download anywhere" )
  90. else
  91. print( "Failed." )
  92. end
  93. end
  94.  
  95. elseif sCommand == "get" then
  96. -- Download a file from pastebin.com
  97. if #tArgs < 3 then
  98. printUsage()
  99. return
  100. end
  101. -- Determine file to download
  102. local sCode = tArgs[2]
  103. local sFile = tArgs[3]
  104. local sPath = shell.resolve( sFile )
  105. if fs.exists( sPath ) then
  106. print( "File already exists" )
  107. return
  108. end
  109.  
  110. -- GET the contents from pastebin
  111. write( "Connecting to pastebin.com... " )
  112. local response = http.get(
  113. "https://pastebin.com/raw.php?i="..textutils.urlEncode( sCode )
  114. )
  115.  
  116. if response then
  117. print( "Success." )
  118.  
  119. local sResponse = response.readAll()
  120. response.close()
  121.  
  122. local file = fs.open( sPath, "w" )
  123. file.write( sResponse )
  124. file.close()
  125.  
  126. print( "Downloaded as "..sFile )
  127.  
  128. else
  129. print( "Failed." )
  130. end
  131. else
  132. printUsage()
  133. return
  134. end
Add Comment
Please, Sign In to add comment