Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local key = "0ec2eb25b6166c0c27a394ae118ad829"
- local x, y = term.getSize()
- local loginTab = {
- ".------------------------------------------------.",
- "| |",
- "| |",
- "| |",
- "| |",
- "| .-------------------------. |",
- "| | Please login | |",
- "| | | |",
- "| | User> | |",
- "| | Pass> | |",
- "| | | |",
- "| '-------------------------' |",
- "| |",
- "| |",
- "| |",
- "| |",
- "| |",
- "|________________________________________________|",
- }
- --menu functions
- local function newmenu(tList,x,y,height,menu)
- local function maxlen(t)
- local len=0
- for i=1,#t do
- local curlen=string.len(type(t[i])=='table' and t[i][1] or t[i])
- if curlen>len then len=curlen end
- end
- return len
- end
- local max=maxlen(tList)
- x=x or 1
- y=y or 1
- y=y-1
- height=height or #tList
- height=height+1
- local selected=1
- local scrolled=0
- local function render()
- for num,item in ipairs(tList) do
- if num>scrolled and num<scrolled+height then
- term.setCursorPos(x,y+num-scrolled)
- local current=(type(item)=='table' and item[1] or item)
- if num == selected then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("[")
- term.setTextColor(colors.blue)
- term.setBackgroundColor(colors.white)
- write(current)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- write("]"..(max-#current>0 and string.rep(' ',max-#current) or ''))
- else
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..current..(max-#current>0 and string.rep(' ',max-#current + 1) or ''))
- end
- end
- end
- end
- while true do
- render()
- local events = {os.pullEvent()}
- if events[1] == "key" and events[2] == 200 and selected > 1 then
- if selected - 1 <= scrolled then scrolled = scrolled - 1 end
- selected = selected - 1
- elseif events[1] == "key" and events[2] == 208 and selected < #tList then
- selected = selected + 1
- if selected >= height + scrolled then scrolled = scrolled + 1 end
- elseif events[1] == "key" and events[2] == 28 or events[2] == 156 then
- return (type(tList[selected]) == 'table' and tList[selected][2](tList[selected][1]) or tList[selected])
- elseif events[1] == "mouse_click" and events[2] == 1 then
- local tX, tY = term.getSize()
- if events[3] >= 7 and events[3] <= 3 and events[4] == tY - 7 then
- print("Success")
- sleep(5)
- elseif events[3] == 48 and events[4] == 2 then
- term.setCursorPos(events[3], events[4])
- term.setBackgroundColor(colors.gray)
- term.setTextColor(colors.red)
- write("X")
- return "Exit SmartPaste"
- end
- elseif events[1] == "mouse_scroll" and events[2] == - 1 and selected > 1 then
- if selected - 1 <= scrolled then scrolled = scrolled - 1 end
- selected = selected - 1
- elseif events[1] == "mouse_scroll" and events[2] == 1 and selected < #tList then
- selected = selected + 1
- if selected >= height + scrolled then scrolled = scrolled + 1 end
- end
- end
- end
- local function mainMenu(logged)
- local menu = {(logged == true and "Logout" or "Login"), "Create post", "Delete post", "Retrieve post", "Exit SmartPaste"}
- local n = 1
- local old = 1
- while true do
- term.setBackgroundColor(colors.black)
- for i = 1, #menu do
- term.setCursorPos(3,y - 7 + i)
- term.setTextColor(colors.red)
- write(menu[i])
- end
- term.setCursorPos(2, y - 7 + old)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..menu[old].." ")
- term.setCursorPos(2, y - 7 + n)
- term.setTextColor(colors.yellow)
- write("[")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- write(menu[n])
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("]")
- term.setTextColor(colors.red)
- local events = {os.pullEvent()}
- if events[1] == "key" and events[2] == 200 or events[1] == "mouse_scroll" and events[2] == - 1 then
- if n > 1 then
- old = n
- n = n - 1
- else
- old = n
- n = 1
- end
- elseif events[1] == "key" and events[2] == 208 or events[1] == "mouse_scroll" and events[2] == 1 then
- if n < #menu then
- old = n
- n = n + 1
- else
- old = n
- n = #menu
- end
- elseif events[1] == "key" and events[2] == 28 or events[2] == 156 then
- return menu[n]
- elseif events[1] == "mouse_click" and events[2] == 1 then
- if events[3] >= 3 and events[3] <= 7 and events[4] == y - 6 then
- old = n
- term.setCursorPos(2, y - 7 + old)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..menu[old].." ")
- n = 1
- term.setCursorPos(2, y - 7 + n)
- term.setTextColor(colors.yellow)
- write("[")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- write(menu[n])
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("]")
- sleep(.5)
- return menu[n]
- elseif events[3] >= 3 and events[3] <= 13 and events[4] == y - 5 then
- old = n
- term.setCursorPos(2, y - 7 + old)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..menu[old].." ")
- n = 2
- term.setCursorPos(2, y - 7 + n)
- term.setTextColor(colors.yellow)
- write("[")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- write(menu[n])
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("]")
- sleep(.5)
- return menu[n]
- elseif events[3] >= 3 and events[3] <= 13 and events[4] == y - 4 then
- old = n
- term.setCursorPos(2, y - 7 + old)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..menu[old].." ")
- n = 3
- term.setCursorPos(2, y - 7 + n)
- term.setTextColor(colors.yellow)
- write("[")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- write(menu[n])
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("]")
- sleep(.5)
- return menu[n]
- elseif events[3] >= 3 and events[3] <= 15 and events[4] == y - 3 then
- old = n
- term.setCursorPos(2, y - 7 + old)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..menu[old].." ")
- n = 4
- term.setCursorPos(2, y - 7 + n)
- term.setTextColor(colors.yellow)
- write("[")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- write(menu[n])
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("]")
- sleep(.5)
- return menu[n]
- elseif events[3] >= 3 and events[3] <= 17 and events[4] == y - 2 then
- old = n
- term.setCursorPos(2, y - 7 + old)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- write(" "..menu[old].." ")
- n = 5
- term.setCursorPos(2, y - 7 + n)
- term.setTextColor(colors.yellow)
- write("[")
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.blue)
- write(menu[n])
- term.setTextColor(colors.yellow)
- term.setBackgroundColor(colors.black)
- write("]")
- sleep(.5)
- return menu[n]
- elseif events[2] == 1 and events[3] == 48 and events[4] == 2 then
- term.setCursorPos(events[3], events[4])
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.red)
- write("X")
- return "Exit SmartPaste"
- end
- end
- end
- end
- -- limit read function
- local function limitRead(limX, rChar)
- term.setCursorBlink(true)
- local origX, origY = term.getCursorPos()
- local returnString = ""
- while true do
- local xPos, yPos = term.getCursorPos()
- local event, p1, p2 = os.pullEvent()
- if event == "char" then
- returnString = returnString..p1
- if not rChar then
- if not limX then
- term.setTextColor(colors.blue)
- write(p1)
- else
- if string.len(returnString) >= limX then
- term.setTextColor(colors.blue)
- term.setCursorPos(origX, origY)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- elseif string.len(returnString) < limX then
- term.setTextColor(colors.blue)
- write(p1)
- end
- end
- else
- if not limX then
- term.setTextColor(colors.blue)
- write(rChar)
- else
- if string.len(returnString) >= limX then
- term.setTextColor(colors.blue)
- term.setCursorPos(origX, origY)
- write(string.rep(rChar, limX))
- elseif string.len(returnString) < limX then
- term.setTextColor(colors.blue)
- write(rChar)
- end
- end
- end
- elseif event == "key" and p1 == 14 then --backspace
- returnString = string.sub(returnString, 1, (string.len(returnString))-1)
- term.setCursorPos(xPos-1,yPos)
- term.setTextColor(colors.blue)
- write(" ")
- term.setCursorPos(origX, origY)
- if string.len(returnString) >= limX then
- if not rChar then
- term.setTextColor(colors.blue)
- write(string.sub(returnString, (string.len(returnString)-limX)+1))
- else
- term.setTextColor(colors.blue)
- write(string.rep(rChar,limX))
- end
- else
- if not rChar then
- term.setTextColor(colors.blue)
- write(returnString)
- else
- term.setTextColor(colors.blue)
- write(string.rep(rChar, string.len(returnString)))
- end
- end
- elseif event == "key" and p1 == 28 then --enter
- break
- end
- end
- term.setCursorBlink(false)
- return returnString
- end
- --login
- local function login()
- local x, y = term.getSize()
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- write("."..string.rep("-", x - 3)..".")
- for i = 2, y - 1 do
- term.setCursorPos(1,i)
- write("|")
- term.setCursorPos(x - 1, i)
- write("|")
- end
- write("'"..string.rep("-", x - 3).."'")
- term.setTextColor(colors.white)
- term.setCursorPos(12,6)
- write(".-------------------------.")
- term.setCursorPos(12,7)
- write("| ")
- term.setTextColor(colors.red)
- write("Please login")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(12,8)
- write("| |")
- term.setCursorPos(12,9)
- write("| ")
- term.setTextColor(colors.red)
- write("User")
- term.setTextColor(colors.yellow)
- write(">")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(12,10)
- write("| ")
- term.setTextColor(colors.red)
- write("Pass")
- term.setTextColor(colors.yellow)
- write(">")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(12,11)
- write("| |")
- term.setCursorPos(12,12)
- write("'-------------------------'")
- term.setCursorPos(20,9)
- local inputUser = limitRead(17)
- term.setCursorPos(20,10)
- local inputPass = limitRead(17, "*")
- return inputUser, inputPass
- end
- --gui
- local function frame()
- term.setCursorPos(3,2)
- term.setTextColor(colors.blue)
- write("SmartPaste")
- term.setCursorPos(x - 6,2)
- term.setTextColor(colors.white)
- write("_")
- term.setTextColor(colors.yellow)
- write("[]")
- term.setTextColor(colors.red)
- write("X ")
- term.setCursorPos(1,1)
- term.setTextColor(colors.orange)
- write("."..string.rep("-", x - 3)..".")
- for i = 2, y - 1 do
- term.setCursorPos(1,i)
- write("|")
- term.setCursorPos(x - 1,i)
- write("|")
- end
- term.setCursorPos(1,y)
- write("+"..string.rep("-", x - 3).."+")
- term.setCursorPos(1,3)
- write("+"..string.rep("-", x - 3).."+")
- end
- --file system
- local function fList(dir)
- dir=shell.resolve(dir)
- term.clear()
- frame()
- local _list = fs.list(dir)
- table.sort(_list)
- local selected=newmenu(_list,3,5,({term.getSize()})[2]-6)
- local fReturn = dir..'/'..selected
- if fs.isDir(shell.resolve(fReturn)) then
- return fList(fReturn)
- else
- return fReturn,selected
- end
- end
- local function confirm(menu)
- local menu = menu or ""
- while true do
- local events = {os.pullEvent()}
- if events[1] == "key" and events[2] == 28 then
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(23,11)
- write(" OK ")
- sleep(.25)
- term.setBackgroundColor(colors.black)
- return menu
- elseif events[1] == "mouse_click" and events[2] == 1 and events[3] >= 23 and events[3] <= 27 and events[4] == 11 then
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(23,11)
- write(" OK ")
- sleep(.25)
- term.setBackgroundColor(colors.black)
- return menu
- elseif events[1] == "mouse_click" and events[2] == 1 and events[3] == 48 and events[4] == 2 then
- return "Exit SmartPaste"
- end
- end
- end
- --messages
- local function failConnect()
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("|")
- term.setTextColor(colors.yellow)
- write(" Unable to connect! ")
- term.setTextColor(colors.white)
- write("|")
- term.setCursorPos(9,9)
- write("|")
- term.setTextColor(colors.yellow)
- write(" Please try again later ")
- term.setTextColor(colors.white)
- write("|")
- term.setCursorPos(9,10)
- write("| |")
- term.setCursorPos(9,11)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,12)
- write("'------------------------------'")
- confirm()
- end
- -- application code
- local logged = false
- local userKey = ""
- while true do
- term.clear()
- frame()
- local fMenu = mainMenu(logged)
- if fMenu == "Login" then
- local user,pass = login()
- local response = http.post(
- "http://pastebin.com/api/api_login.php",
- "api_dev_key="..key.."&"..
- "api_user_name="..textutils.urlEncode(user).."&"..
- "api_user_password="..textutils.urlEncode(pass)
- )
- local badRequests = {
- "Bad API request, invalid login",
- "Bad API request, account not active"
- }
- if response then
- local sResponse = response.readAll()
- response.close()
- if sResponse == badRequests[1] then
- term.setCursorPos(19,11)
- term.setTextColor(colors.yellow)
- write("Invalid Login")
- sleep(2)
- logged = false
- elseif sResponse == badRequests[2] then
- term.setCursorPos(17,11)
- term.setTextColor(colors.yellow)
- write("Account inactive")
- sleep(2)
- logged = false
- else
- userKey = sResponse
- logged = true
- end
- else
- failConnect()
- end
- elseif fMenu == "Logout" then
- logged = false
- userKey = ""
- elseif fMenu == "Create post" then --create post
- local postItem = fList("/")
- if postItem ~= "Exit SmartPaste" then
- local file = fs.open(postItem, "r")
- local postText = file.readAll()
- file.close()
- while true do
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Save as:")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.yellow)
- write(">")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("'------------------------------'")
- term.setCursorPos(15,9)
- local postName = limitRead(22)
- if postName ~= "" then
- --add options for making private/unlisted/public
- --add options for expiry date
- --add options for format highlighting
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_option=paste&"..
- "api_dev_key="..key.."&"..
- "api_paste_format=lua&"..
- "api_user_key="..userKey.."&"..
- "api_paste_name="..textutils.urlEncode(postName).."&"..
- "api_paste_code="..textutils.urlEncode(postText)
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("File saved as:")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("|")
- term.setCursorPos(10,9)
- term.setTextColor(colors.yellow)
- write(" "..sResponse.." ")
- term.setTextColor(colors.white)
- write("|")
- term.setCursorPos(9,10)
- write("| |")
- term.setCursorPos(9,11)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,12)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- break
- else
- failConnect()
- break
- end
- else
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Invalid filename")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.yellow)
- write("Please re-enter name")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("| |")
- term.setCursorPos(9,11)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,12)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- end
- end
- else
- local fMenu = "Exit SmartPaste"
- end
- elseif fMenu == "Delete post" and logged == false then --delete if not logged in
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("You must be logged in")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.red)
- write("To use that feature")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("| |")
- term.setCursorPos(9,11)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,12)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- elseif fMenu == "Delete post" and logged == true then --delete if logged in
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_dev_key="..key.."&"..
- "api_user_key="..userKey.."&"..
- "api_option=list"
- )
- if response then
- term.clear()
- frame()
- term.setTextColor(colors.blue)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Retreiving posts from")
- term.setTextColor(colors.blue)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.red)
- write("Pastebin.com")
- term.setTextColor(colors.blue)
- write(" |")
- term.setCursorPos(9,10)
- write("'------------------------------'")
- sleep(1)
- local codeTable = {}
- local titleTable = {}
- local sResponse = response.readAll()
- response.close()
- for code in string.gmatch(sResponse, "<paste_key>(%w-)</paste_key>") do
- table.insert(codeTable, code)
- end
- for title in string.gmatch(sResponse, "<paste_title>(.-)</paste_title>") do
- table.insert(titleTable, title)
- end
- term.clear()
- frame()
- local delOpt = newmenu(titleTable, 3, 5, 13)
- for i = 1, # codeTable do
- if delOpt == titleTable[i] then
- postCode = codeTable[i]
- end
- end
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_dev_key="..key.."&"..
- "api_user_key="..userKey.."&"..
- "api_option=delete&"..
- "api_paste_key="..postCode
- )
- if response then
- local sResponse = response.readAll()
- if sResponse == "Paste Removed" then
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Paste deleted successfully")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- end
- else
- failConnect()
- end
- else
- failConnect()
- end
- elseif fMenu == "Retrieve post" then --download paste
- if logged == false then
- term.clear()
- frame()
- term.setTextColor(colors.white)
- term.setCursorPos(9,7)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Pastebin code:")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.yellow)
- write(">")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("'------------------------------'")
- term.setCursorPos(15,9)
- local postCode = limitRead(22)
- if postCode ~= nil and string.len(postCode) == 8 then
- local response = http.get("http://pastebin.com/raw.php?i="..postCode)
- if response then
- local sResponse = response.readAll()
- response.close()
- term.clear()
- frame()
- term.setCursorPos(9,7)
- term.setTextColor(colors.white)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("New filename:")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.yellow)
- write(">")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("'------------------------------'")
- term.setCursorPos(15,9)
- while true do
- local fileName = limitRead(22)
- if fileName ~= "" then
- local file = fs.open(fileName, "w")
- file.write(sResponse)
- file.close()
- break
- else
- term.clear()
- frame()
- term.setCursorPos(9,7)
- term.setTextColor(colors.white)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Invalid filename")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.red)
- write("Please re-enter name")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,11)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- end
- end
- else
- failConnect()
- end
- else
- term.clear()
- frame()
- term.setCursorPos(9,7)
- term.setTextColor(colors.white)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Invalid code")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.red)
- write("Please re-enter code")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("| |")
- term.setCursorPos(9,11)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,12)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- end
- elseif logged == true then
- local response = http.post(
- "http://pastebin.com/api/api_post.php",
- "api_dev_key="..key.."&"..
- "api_user_key="..userKey.."&"..
- "api_option=list"
- )
- if response then
- local sResponse = response.readAll()
- response.close()
- local codeTable = {}
- local titleTable = {}
- for code in string.gmatch(sResponse, "<paste_key>(%w-)</paste_key>") do
- table.insert(codeTable, code)
- end
- for title in string.gmatch(sResponse, "<paste_title>(.-)</paste_title>") do
- table.insert(titleTable, title)
- end
- term.clear()
- frame()
- local downOpt = newmenu(titleTable, 3, 5, 13)
- if downOpt ~= "Exit SmartPaste" then
- for i = 1, # codeTable do
- if downOpt == titleTable[i] then
- postCode = codeTable[i]
- end
- end
- local response = http.get("http://pastebin.com/raw.php?i="..postCode)
- if response then
- local sResponse = response.readAll()
- term.clear()
- frame()
- term.setCursorPos(9,7)
- term.setTextColor(colors.white)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("New filename:")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.yellow)
- write(">")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("'------------------------------'")
- term.setCursorPos(15,9)
- while true do
- local fileName = limitRead(22)
- if fileName ~= "" then
- local file = fs.open(fileName, "w")
- file.write(sResponse)
- file.close()
- break
- else
- term.clear()
- frame()
- term.setCursorPos(9,7)
- term.setTextColor(colors.white)
- write(".------------------------------.")
- term.setCursorPos(9,8)
- write("| ")
- term.setTextColor(colors.red)
- write("Invalid filename")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,9)
- write("| ")
- term.setTextColor(colors.red)
- write("Please re-enter name")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,10)
- write("| ")
- term.setTextColor(colors.blue)
- write("[ OK ]")
- term.setTextColor(colors.white)
- write(" |")
- term.setCursorPos(9,11)
- write("'------------------------------'")
- local fMenu = confirm(fMenu)
- end
- end
- else
- fMenu = downOpt
- end
- else
- failConnect()
- end
- else
- failConnect()
- end
- end
- end
- if fMenu == "Exit SmartPaste" then --exit program
- sleep(.25)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.yellow)
- term.clear()
- term.setCursorPos(1,1)
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement