Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local api = { LoadOrder = 0 }
- function api.Build()
- local Pastebin = { DevKey = "ByTl7aSZ0CDz83Qqzgqr8-LzuUPy1sUG", Base = "https://pastebin.com/api/", UserKey = false }
- Pastebin.__index = Pastebin
- function Pastebin:__call(u,p)
- local r=request:post(self.Base.."api_login.php",{api_dev_key=self.DevKey,api_user_name=u,api_user_password=p})
- if not r then return false,"Failed to login." end
- local inst=setmetatable({UserKey=r.readAll()},self)
- r.close()
- function inst:delete(c)
- local r=request:post(self.Base.."api_post.php",{api_dev_key=self.DevKey,api_user_key=self.UserKey,api_option="delete",api_paste_key=c})
- if not r then return false,"Failed." end
- r.close()
- return true
- end
- function inst:list(c)
- local r=request:post(self.Base.."api_post.php",{api_dev_key=self.DevKey,api_user_key=self.UserKey,api_option="list",api_results_limit=c})
- if not r then return false,"Failed." end
- local l=r.readLine()
- local d,p={},{}
- while l do
- if l =="<paste>" then p = {}
- elseif l == "</paste>" then d[#d+1]=p
- else
- local k,v=string.match(l,"^.+<(.+)>(.+)</.+>$")
- p[k]=v
- end
- l=r.readLine()
- end
- r.close()
- return d
- end
- return inst
- end
- function Pastebin:getPaste(c)
- local r=not self.UserKey and request:get("https://pastebin.com/raw.php",{i=c}) or request:post(self.Base.."api_raw.php",{api_dev_key=self.DevKey,api_user_key=self.UserKey,api_option="show_paste",api_paste_key=c})
- if not r then return false, "Failed to get paste." end
- local d=r.readAll()
- r.close()
- return d
- end
- function Pastebin:get(c,p,f)
- p=p or c
- if f then fs.delete(p) elseif fs.exists(p) then return false,"File already exists." end
- local d,e=self:getPaste(c)
- if not d then return false,e end
- local a=fs.open(p,"w")
- a.write(d)
- a.close()
- return true
- end
- function Pastebin:run(c,...)
- local d,e=self:getPaste(c)
- if not d then return false,e end
- local f,e=loadstring(d)
- if not f then return false,e end
- setfenv(f,getfenv())
- local s,e=pcall(f,...)
- if not s then return false,e end
- return true
- end
- function Pastebin:put(p,n)
- if not fs.exists(p) or fs.isDir(p) then return false,"No such file." end
- local f=fs.open(p,"r")
- local r=request:post(self.Base.."api_post.php",{api_dev_key=self.DevKey,api_option="paste",api_paste_format="lua",api_paste_name=n or fs.getName(p),api_paste_code=f.readAll(),api_user_key=self.UserKey or nil})
- f.close()
- if not r then return false, "Failed." end
- local c=string.match(r.readAll(),"[^/]+$")
- r.close()
- return c
- end
- return setmetatable(Pastebin, Pastebin)
- end
- return api
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement