Advertisement
FFGFlash

pastebin.lua

Sep 27th, 2021
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.53 KB | None | 0 0
  1. local args = {...}
  2. local cmd = table.remove(args,1)
  3. local config = data.load(".pb")
  4. local pb = pastebin
  5.  
  6. local function requestLogin()
  7.     if config.username then
  8.         pb,err = pastebin.login(config.username,read("*"))
  9.         if not pb then
  10.             pb = pastebin
  11.             print(err)
  12.         end
  13.     end
  14. end
  15.  
  16. local function help()
  17.     print("Usage:")
  18.     print("pastebin put <filename>")
  19.     print("pastebin get <code> <filename> <force>")
  20.     print("pastebin run <code> <arguments>")
  21.     print("pastebin login <username>")
  22.     if not pb.UserKey then return end
  23.     print("pastebin logout")
  24.     print("pastebin delete <code>")
  25.     print("pastebin list")
  26. end
  27.  
  28. local function get(code,path,force)
  29.     force = force == "true"
  30.     print("Connecting to pastebin.com...")
  31.     local path,err = pb.get(code,path,force)
  32.     if not path then return print(err) end
  33.     print("Success.")
  34.     print("Downloaded as "..path)
  35. end
  36.  
  37. local function put(path)
  38.     print("Connecting to pastebin.com...")
  39.     local code,err = pb.put(path)
  40.     if not code then return print(err) end
  41.     print("Success.")
  42.     print("Run \"pastebin get "..code.."\" to download anywhere")
  43. end
  44.  
  45. local function run(code,...)
  46.     print("Connecting to pastebin.com...")
  47.     local success,err = pb.run(code,...)
  48.     if not success then return print(err) end
  49. end
  50.  
  51. local function delete(code)
  52.     print("Connecting to pastebin.com...")
  53.     local success,err = pb.delete(code)
  54.     if not success then return print(err) end
  55.     print("Success.")
  56. end
  57.  
  58. local function list()
  59.     print("Connecting to pastebin.com...")
  60.     local list,err = pb.list()
  61.     if not list then return print(err) end
  62.     for i,p in ipairs(list) do
  63.         print(p.paste_key..": "..p.paste_title.." ("..p.paste_size..")")
  64.     end
  65. end
  66.  
  67. local function login(username)
  68.     if not username then return end
  69.     config.username = username
  70.     data.save(".pb", config)
  71. end
  72.  
  73. local function logout()
  74.     if not login.username then return end
  75.     config.username = nil
  76.     data.save(".pb", config)
  77. end
  78.  
  79. if cmd == "logout" then logout()
  80. elseif cmd == "login" then login(table.unpack(args))
  81. else
  82.     requestLogin()
  83.     if cmd == "get" then get(table.unpack(args))
  84.     elseif cmd == "put" then put(table.unpack(args))
  85.     elseif cmd == "run" then run(table.unpack(args))
  86.     elseif pb.UserKey then
  87.         if cmd == "list" then list()
  88.         elseif cmd == "delete" then delete(table.unpack(args))
  89.         else
  90.             help()
  91.         end
  92.     else
  93.         help()
  94.     end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement