Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local username, password
- local width, height = term.getSize()
- term.setCursorBlink(false)
- term.setBgColor = term.setBackgroundColor
- local oldPullEvent = os.pullEventRaw
- function os.pullEvent(filter)
- local event, p1, p2, p3, p4, p5 = oldPullEvent(filter)
- if event == "terminate" then
- term.setCursorPos(1, 1)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.black)
- term.clear()
- os.pullEvent = oldPullEvent
- error("Terminated", 0)
- end
- return event, p1, p2, p3, p4, p5
- end
- function message(str, sleept)
- sleept = sleept or 3
- term.clear()
- term.setCursorPos(math.ceil((width - #str)*.5), math.floor(height*.5))
- print(str)
- if sleept > 0 and sleept < 10 then
- sleep(sleept)
- elseif sleept == -1 then
- local contStr = "Press any key to continue..."
- term.setCursorPos(math.ceil((width - #str)*.5), math.floor(height - 1))
- print(contStr)
- os.pullEvent("key")
- term.clear()
- end
- if sleept >= 3 then
- term.clear()
- end
- end
- -- Load the Social Net API
- function loadapi()
- message("Loading Social Net API...", 0)
- if fs.exists("snet") then
- shell.run("snet")
- return true
- end
- aa = aa or {}
- local a2 = http.get("https://vault.dannysmc.com/lua/api/socialnetapi.lua")
- a = tostring(a2.readAll())
- a2.close()
- if a == "nil" then
- error("There was a problem when retrieving the Social Net API.", 0)
- end
- local env = {}
- a = loadstring(a)
- if not a then error() end
- local env = getfenv()
- setfenv(a,env)
- local status, err = pcall(a, unpack(aa))
- if (not status) and err then
- printError("Error loading api")
- return false
- end
- local returned = err
- env = env
- _G["snet"] = env
- end
- loadapi()
- messages = {}
- local optionsel = 1
- local headercolor = colors.white
- local headertextcolor = colors.black
- local imagebgcolor = colors.lightGray
- local bgcolor = colors.gray
- local highlightcolor = colors.blue
- local hitextcolor = colors.white
- local textcolor = colors.white
- if not term.isColor() then
- if not _CC_VERSION then -- Old version, use black and white ONLY
- imagebgcolor = colors.black
- bgcolor = colors.black
- highlightcolor = colors.black
- hitextcolor = colors.white
- else -- New version, use black and white along with lightGray and darkGray.
- hitextcolor = colors.white
- highlightcolor = colors.black
- end
- end
- message("Please Wait...", 0)
- function LoadMessages()
- showingUserMessages = false
- local rawmessages = social.post.getall(username, password)
- messages = {}
- for k, v in ipairs(rawmessages) do
- table.insert(messages, 1, v)
- end
- messages[#messages + 1] = "Exit"
- end
- function LoadFriends()
- showingThisUsersFriends = true
- friends = social.friends.get(username, password, username)
- friends[#friends + 1] = "Add New"
- friends[#friends + 1] = "Exit"
- end
- function LoadUsers()
- users = user.list(username, password)
- users[#users + 1] = "Exit"
- end
- -- My Friends Menu --
- function drawFriendsList(optionsel)
- term.clear()
- local options = friends
- if type(options) ~= "table" then
- LoadFriends()
- end
- term.setBgColor(colors.black)
- for k, v in ipairs(options) do
- term.setCursorPos(1, 2 + k - math.max(optionsel - height*.5, 0))
- if k == optionsel then
- term.setBgColor(highlightcolor)
- term.setTextColor(colors.white)
- else
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- end
- term.clearLine()
- if type(v) == "table" then
- if v[2] == "tweet" then
- term.write(v[3].." said "..v[5])
- else
- term.write(v[4].." by ".. v[3])
- end
- else
- term.write(v)
- end
- end
- term.setBgColor(bgcolor)
- term.setCursorPos(1, 3 + #options - math.max(optionsel - height*.5, 0))
- term.clearLine()
- if math.max(optionsel - height*.5, 0) == 0 then
- term.setCursorPos(1, 2)
- term.clearLine()
- end
- term.setCursorPos(1, 1)
- term.clearLine()
- print("Friends")
- end
- function MyFriends(showOtherUserFriends)
- if not showOtherUserFriends and not showingThisUsersFriends then
- message("Reloading your friends...", 0)
- LoadFriends()
- end
- local options = friends
- local optionsel = 1
- if type(friends) ~= "table" then
- friends = {}
- friends[#friends + 1] = "Add New"
- friends[#friends + 1] = "Exit"
- options = friends
- end
- while true do
- drawFriendsList(optionsel)
- local event, key = os.pullEvent("key")
- if key == keys.up then
- optionsel = math.max(optionsel - 1, 1)
- elseif key == keys.down then
- optionsel = math.min(optionsel + 1, #options)
- elseif key == keys.pageUp then
- optionsel = math.max(optionsel - (height - 1), 1)
- elseif key == keys.pageDown then
- optionsel = math.min(optionsel + (height - 1), #options)
- elseif key == keys.home then
- optionsel = 1
- elseif key == keys["end"] then
- optionsel = #options
- elseif(key == keys.tab) then
- term.setCursorBlink(false)
- return false
- elseif key == 28 then
- if optionsel > #options - 1 then
- term.clear()
- return
- elseif optionsel > #options - 2 and not showOtherUserFriends then
- addFriend()
- else
- viewProfile(friends[optionsel])
- end
- end
- end
- end
- -- Chat Menu --
- function drawChat(chatMessages, msgString, curPos, scrollPos, chatScroll, group)
- -- Draw Header
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.clear()
- term.setCursorPos(1, 1)
- if type(group) == "string" then -- Use Group Chat
- print(group.." Chat")
- elseif type(group) == "table" then -- Use Personal Message Chat
- print("Chat with "..group[1])
- else -- Use Global Chat
- print("Global Chat")
- end
- term.setTextColor(textcolor)
- term.setBgColor(bgcolor)
- -- Draw Currently shown messages
- local drawY, msgLine = 2, 1
- for k=chatScroll, chatScroll + height do
- if chatMessages[k] then
- local showString = chatMessages[k][2].."> "..chatMessages[k][3]
- if not (k - chatScroll <= 0) and chatMessages[k - 1] then
- drawY = drawY + math.floor((#chatMessages[k - 1][3]/width) + 1)
- end
- msgLine = -1
- for tx=1, #showString, width do
- term.setCursorPos(1, drawY + tx + msgLine)
- msgLine = msgLine + 1
- term.write(string.sub(showString, tx, tx + width))
- end
- end
- end
- -- Draw Text currently being input
- term.setCursorPos(1 - scrollPos, height - 1)
- term.setBgColor(imagebgcolor)
- term.clearLine()
- term.write(msgString)
- term.setBgColor(bgcolor)
- term.setCursorPos(1, height)
- term.write("Enter to send, F5 to refresh, or tab to return.")
- term.setCursorPos(curPos - scrollPos + 1, height - 1)
- term.setCursorBlink(true)
- end
- function Chat(group)
- local getMessages, sendMessage
- local msgString, curPos, scrollPos, chatScroll = "", 0, 0, 0
- local ok
- if type(group) == "string" then
- if #group == 0 then group = nil end
- end
- if type(group) == "string" then -- Use Group Chat
- getMessages = function (group) return social.chat_group.get(username, password, group) end
- sendMessage = function (message, group) return social.chat_group.new(username, password, group, message) end
- elseif type(group) == "table" then -- Use Personal Message Chat
- getMessages = function (group) return social.chat_pm.get(username, password, group[1]) end
- sendMessage = function (message, group) return social.chat_pm.new(username, password, group[1], message) end
- else -- Use Global Chat
- getMessages = function () return social.chat_global.get(username, password) end
- sendMessage = function (message) return social.chat_global.new(username, password, message) end
- end
- chatrunning = true
- ok, chatMessages = pcall(getMessages, username, password, group)
- if not ok then
- message(chatMessages)
- chatMessages = {}
- end
- while chatrunning do
- drawChat(chatMessages, msgString, curPos, scrollPos, chatScroll, group)
- local event, key, p2, p3, p4, p5 = os.pullEvent()
- if event == "key" then
- if key == keys.tab then
- term.setCursorBlink(false)
- return
- elseif(key == keys.up) then
- chatScroll = chatScroll - 1
- elseif(key == keys.down) then
- chatScroll = chatScroll + 1
- elseif(key == keys.left) then
- curPos = math.min(math.max(curPos - 1, 0), #msgString)
- if curPos - scrollPos < 1 then scrollPos = scrollPos - 1 end
- elseif(key == keys.right) then
- curPos = math.min(curPos + 1, #msgString)
- if curPos - scrollPos > width then scrollPos = scrollPos + 1 end
- elseif(key == keys.enter) then
- if #msgString > 0 then
- term.setCursorBlink(false)
- local ok, response = pcall(sendMessage, username, password, msgString, group)
- if response == true then
- msgString = ""
- -- Refresh messages.
- term.setCursorBlink(false)
- message("Refreshing Chat...", 0)
- ok, chatMessages = pcall(getMessages, username, password, group)
- if not ok then
- message(chatMessages)
- chatMessages = {}
- end
- else
- message(tostring(response))
- end
- end
- elseif(key == keys.f5) then
- term.setCursorBlink(false)
- message("Refreshing Chat...", 0)
- ok, chatMessages = pcall(getMessages, username, password, group)
- if not ok then
- message(chatMessages)
- chatMessages = {}
- end
- elseif(key == keys.f3) then
- Chat(read())
- elseif(key == keys.f4) then
- Chat({username})
- elseif(key == keys.backspace) then
- if curPos > 0 then
- msgString = string.sub(msgString, 1, curPos - 1) .. string.sub(msgString, curPos + 1, -1)
- curPos = curPos - 1
- end
- elseif(key == keys.delete) then
- if curPos < #msgString then
- msgString = string.sub(msgString, 1, curPos) .. string.sub(msgString, curPos + 2, -1)
- end
- end
- elseif(event == "char") and #msgString < 255 then
- local event, character = event, key
- msgString = string.sub(msgString, 1, curPos) .. character .. string.sub(msgString, curPos + 1, -1)
- curPos = curPos + 1
- if curPos - scrollPos > width then scrollPos = scrollPos + 1 end
- end
- end
- end
- -- Edit Profile Menu --
- local profilefieldsdefault = {
- {"Full Name", ""},
- {"Age", ""},
- {"Forums Username", ""},
- {"Image Location", ""},
- {"Bio", ""},
- }
- local profilefields = {}
- function sendProfileUpdate(name, age, bio, forums, image)
- local str
- if image ~= "" then
- local strx = paintutils.loadImage(image)
- str = textutils.serialize(strx)
- else
- str = ""
- end
- return social.profile.edit(username, password, name, tonumber(age), bio, forums)
- end
- function drawProfilePrompt(cursorpos, currow, curfield)
- term.setCursorBlink(false)
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.setCursorPos(1, height - 1)
- term.write("Enter your profile then press Enter to send.")
- term.setCursorPos(1, height)
- term.write("Up or down switches row. Press Tab to cancel.")
- for k, v in ipairs(profilefields) do
- term.setCursorPos(1, 2 + k)
- if v[1] ~= "Bio" then
- print(v[1]..": "..v[2].." ")
- else
- term.clearLine()
- term.write("Bio")
- term.setCursorPos(1, 3 + k)
- print(v[2] .. " ")
- end
- end
- if profilefields[currow][1] == "Bio" then
- term.setCursorPos(cursorpos + 1, 3 + currow)
- else
- term.setCursorPos(cursorpos + #profilefields[currow][1] + 3, 2 + currow)
- end
- term.setCursorBlink(true)
- end
- function resetFields2()
- for k, v in ipairs(profilefieldsdefault) do
- profilefields[k] = profilefieldsdefault[k]
- end
- end
- function updateProfilePrompt()
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Update Profile")
- resetFields2()
- local cursorpos, currow = 0, 1
- local curfield = profilefields[currow]
- local e, p1, p2, p3, p4
- while true do
- drawProfilePrompt(cursorpos, currow, curfield)
- e, p1, p2, p3, p4 = os.pullEvent()
- if(e == "key") then
- if(p1 == keys.up) then
- currow = math.max(currow - 1, 1)
- curfield = profilefields[currow]
- elseif(p1 == keys.down) then
- currow = math.min(currow + 1, #profilefields)
- curfield = profilefields[currow]
- elseif(p1 == keys.left) then
- cursorpos = math.max(cursorpos - 1, 0)
- elseif(p1 == keys.right) then
- cursorpos = math.min(cursorpos + 1, #curfield[2])
- elseif(p1 == keys.enter) then
- term.setCursorBlink(false)
- message("Sending Message...", 0)
- local success = sendProfileUpdate(profilefields[1][2], profilefields[2][2], profilefields[5][2], profilefields[3][2], profilefields[4][2])
- if success then
- term.setCursorBlink(false)
- message("Profile Updated!")
- return
- else
- term.setCursorBlink(false)
- message(success)
- end
- elseif(p1 == keys.backspace) then
- if cursorpos > 0 then
- curfield[2] = string.sub(profilefields[currow][2], 1, cursorpos - 1) .. string.sub(profilefields[currow][2], cursorpos + 1, -1)
- cursorpos = cursorpos - 1
- end
- elseif(p1 == keys.tab) then
- term.setCursorBlink(false)
- return false
- else
- local event, character = os.pullEvent("char")
- profilefields[currow][2] = string.sub(profilefields[currow][2], 1, cursorpos) .. character .. string.sub(profilefields[currow][2], cursorpos + 1, -1)
- cursorpos = cursorpos + 1
- end
- elseif(e == "char") then
- local event, character = e, p1
- profilefields[currow][2] = string.sub(profilefields[currow][2], 1, cursorpos) .. character .. string.sub(profilefields[currow][2], cursorpos + 1, -1)
- cursorpos = cursorpos + 1
- end
- sleep()
- end
- end
- -- Send Message Menu --
- local msgfieldsdefault = {
- {"Header", ""},
- {"Body", ""},
- }
- local msgfields = {
- {"Header", ""},
- {"Body", ""},
- }
- function sendMessage(header, message)
- if header == "" and #message <= 255 then
- return social.post.tweet(username, password, message)
- else
- if header == "" then header = string.sub(message, 0, 30) .. "..." end
- return social.post.new(username, password, header, message)
- end
- end
- function drawMessagePrompt(cursorpos, currow, curfield)
- term.setCursorBlink(false)
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- for k, v in ipairs(msgfields) do
- term.setCursorPos(1, 2 + k)
- if v[1] ~= "Body" then
- print(v[1]..": "..v[2].." ")
- else
- term.clearLine()
- term.write("Message Body")
- term.setCursorPos(1, 3 + k)
- print(string.rep(" ", #v[2]))
- term.setCursorPos(1, 3 + k)
- print(v[2] .. " ")
- end
- end
- if msgfields[currow][1] == "Body" then
- term.setCursorPos((cursorpos%width) + 1, 3 + currow + math.floor(cursorpos/width))
- else
- term.setCursorPos(cursorpos + #msgfields[currow][1] + 3, 2 + currow)
- end
- term.setCursorBlink(true)
- end
- function resetFields()
- for k, v in ipairs(msgfieldsdefault) do
- msgfields[k] = msgfieldsdefault[k]
- end
- end
- function sendMessagePrompt()
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.clear()
- term.setCursorPos(1, 1)
- term.write("Write Message")
- resetFields()
- local cursorpos, currow = 0, 1
- local curfield = msgfields[currow]
- local e, p1, p2, p3, p4
- while true do
- term.setCursorPos(1, 1)
- term.write("Write Message")
- term.setCursorPos(1, height - 1)
- term.write("Type in a message then press Enter to send.")
- term.setCursorPos(1, height)
- term.write("Up or down switches row. Press Tab to cancel.")
- drawMessagePrompt(cursorpos, currow, curfield)
- e, p1, p2, p3, p4 = os.pullEvent()
- if(e == "key") then
- if(p1 == keys.up) then
- currow = math.max(currow - 1, 1)
- curfield = msgfields[currow]
- cursorpos = math.min(cursorpos, #curfield[2])
- elseif(p1 == keys.down) then
- currow = math.min(currow + 1, #msgfields)
- curfield = msgfields[currow]
- cursorpos = math.min(cursorpos, #curfield[2])
- elseif(p1 == keys.left) then
- cursorpos = math.max(cursorpos - 1, 0)
- elseif(p1 == keys.right) then
- cursorpos = math.min(cursorpos + 1, #curfield[2])
- elseif(p1 == keys.enter) then
- term.setCursorBlink(false)
- if #msgfields[2][2] > 0 then
- message("Sending Message...", 0)
- local success = sendMessage(msgfields[1][2], msgfields[2][2])
- if success then
- term.setCursorBlink(false)
- message("Message Sent!")
- return
- else
- term.setCursorBlink(false)
- message(success)
- end
- else
- message("You must type in a message.")
- end
- elseif(p1 == keys.backspace) then
- if cursorpos > 0 then
- curfield[2] = string.sub(msgfields[currow][2], 1, cursorpos - 1) .. string.sub(msgfields[currow][2], cursorpos + 1, -1)
- cursorpos = cursorpos - 1
- end
- elseif(p1 == keys.delete) then
- if cursorpos < #msgfields[currow][2] then
- curfield[2] = string.sub(msgfields[currow][2], 1, cursorpos) .. string.sub(msgfields[currow][2], cursorpos + 2, -1)
- end
- elseif(p1 == keys.tab) then
- term.setCursorBlink(false)
- return false
- else
- local event, character = os.pullEvent("char")
- msgfields[currow][2] = string.sub(msgfields[currow][2], 1, cursorpos) .. character .. string.sub(msgfields[currow][2], cursorpos + 1, -1)
- cursorpos = cursorpos + 1
- end
- elseif(e == "char") then
- local event, character = e, p1
- msgfields[currow][2] = string.sub(msgfields[currow][2], 1, cursorpos) .. character .. string.sub(msgfields[currow][2], cursorpos + 1, -1)
- cursorpos = cursorpos + 1
- end
- sleep()
- end
- end
- -- Messages menu --
- function drawMessage(Author, Header, Body, Time)
- term.setCursorPos(1, 1)
- term.clearLine()
- term.write(Header.." by "..Author)
- term.setCursorPos(1, 2)
- term.write("Message Body")
- term.setCursorPos(1, 3)
- print(Body)
- term.setCursorPos(1, height)
- term.clearLine()
- term.write("Press Enter to return, or Space to view profile.")
- end
- function viewMessage(msgID)
- term.setBgColor(bgcolor)
- term.clear()
- local MessageType = messages[msgID][2]
- local Author, Header, Body
- if MessageType == "tweet" then
- Author, Header, Body = messages[msgID][3], "Tweet", messages[msgID][5]
- else
- Author, Header, Body = messages[msgID][3], messages[msgID][4], messages[msgID][5]
- end
- while true do
- drawMessage(Author, Header or "Message", Body)
- local event, key = os.pullEvent("key")
- if key == 28 or key == keys.tab then
- return
- elseif key == keys.space then
- term.clear()
- message("Loading Profile", 0)
- viewProfile(Author)
- term.clear()
- elseif key == keys.delete then
- local ok, response = pcall(social.post.delete, username, password, msgID)
- if ok and response == true then
- message("Message deleted.")
- return
- elseif not response == "You do not have permission to delete this." then
- message(response)
- end
- end
- end
- end
- function drawMessageList(optionsel, list, showUsers)
- term.setBgColor(bgcolor)
- term.clear()
- local options = list or messages
- for k, v in ipairs(options) do
- term.setCursorPos(1, 2 + k - math.max(math.min(optionsel - height*.5, #options - (height - 2)), 0))
- if k == optionsel then
- term.setBgColor(highlightcolor)
- term.setTextColor(hitextcolor)
- else
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- end
- term.clearLine()
- if type(v) == "table" then
- if v[2] == "tweet" then
- term.write(v[3].." said "..v[5])
- else
- term.write(v[4].." by ".. v[3])
- end
- else
- term.write(v)
- end
- end
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.setCursorPos(1, 3 + #options - math.min(optionsel - height*.5, 0))
- term.clearLine()
- if math.max(optionsel - height*.5, 0) == 0 then
- term.setCursorPos(1, 2)
- term.clearLine()
- end
- -- draw header
- term.setCursorPos(1, 1)
- term.clearLine()
- print((showUsers and "Users") or "Messages")
- -- draw scroll bar
- if #options > height - 2 then
- local scrollBarHeight = math.max((1 - (#options/height))*(height - 1), 1)
- local scrollBarPos = ((optionsel/#options)*(height - 1 - scrollBarHeight)) + 2
- term.setBgColor(headercolor)
- for y=scrollBarPos, scrollBarPos + scrollBarHeight - 1 do
- term.setCursorPos(width, scrollBarPos)
- term.write(" ")
- end
- end
- term.setBgColor(bgcolor)
- end
- function viewMessageList(showUserMessages, list)
- if showingUserMessages and not showUserMessages then
- message("Reloading all messages...", 0)
- LoadMessages()
- end
- local options = list or messages
- local optionsel = 1
- local width, height = term.getSize()
- while true do
- drawMessageList(optionsel)
- local event, key = os.pullEvent("key")
- if key == keys.up then
- optionsel = math.max(optionsel - 1, 1)
- elseif key == keys.down then
- optionsel = math.min(optionsel + 1, #options)
- elseif key == (keys.pageUp) then
- optionsel = math.max(optionsel - (height - 1), 1)
- elseif key == (keys.pageDown) then
- optionsel = math.min(optionsel + (height - 1), #options)
- elseif key == keys.home then
- optionsel = 1
- elseif key == keys["end"] then
- optionsel = #options
- elseif key == keys.f5 then
- message("Reloading all messages...", 0)
- LoadMessages()
- elseif(key == keys.tab) then
- term.setCursorBlink(false)
- return false
- elseif key == 28 then
- if optionsel > #options - 1 then
- term.clear()
- return
- else
- viewMessage(optionsel)
- end
- end
- end
- end
- -- Show User List Menu --
- function viewUserList()
- local options = users
- local optionsel = 1
- while true do
- drawMessageList(optionsel, users, true)
- local event, key = os.pullEvent("key")
- if key == keys.up then
- optionsel = math.max(optionsel - 1, 1)
- elseif key == keys.down then
- optionsel = math.min(optionsel + 1, #options)
- elseif key == keys.pageUp then
- optionsel = math.max(optionsel - (height - 1), 1)
- elseif key == keys.pageDown then
- optionsel = math.min(optionsel + (height - 1), #options)
- elseif key == keys.home then
- optionsel = 1
- elseif key == keys["end"] then
- optionsel = #options
- elseif(key == keys.tab) then
- term.setCursorBlink(false)
- return false
- elseif key == 28 then
- if optionsel > #options - 1 then
- term.clear()
- return
- else
- viewProfile(users[optionsel] or "Tag360")
- end
- end
- end
- end
- -- View Profile Menu --
- function drawProfileImageBG()
- local str1, str2 = " ", " "
- str1 = string.rep(str1, 8)
- str2 = string.rep(str2, 6)
- term.setBgColor(imagebgcolor)
- for k=2, 6 do
- term.setCursorPos(1, k)
- term.write(str1)
- end
- term.setBgColor(textcolor)
- for k=3, 5 do
- term.setCursorPos(2, k)
- term.write(str2)
- end
- end
- function drawProfile(profile, image)
- term.setCursorPos(1, 1)
- term.setBgColor(bgcolor)
- term.write("Viewing "..tostring(profile[2]).."'s profile")
- drawProfileImageBG()
- if image then
- paintutils.drawImage(image, 2, 3)
- end
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.setCursorPos(10, 3)
- term.write("Real Name: ".. (profile[3] or "Hidden"))
- term.setCursorPos(10, 4)
- term.write("Age: ".. (profile[4] or "Hidden"))
- term.setCursorPos(10, 5)
- term.write("Forum Name: ".. (profile[6] or "Unknown"))
- term.setCursorPos(1, 7)
- term.setBgColor(imagebgcolor)
- term.clearLine()
- term.write("Infomation")
- term.setBgColor(bgcolor)
- if not profile[5] then profile[5] = "This user has not created a description." end
- local y = 0
- for k=1, #tostring(profile[5]), width do
- y = y + 1
- term.setCursorPos(1, 7 + y)
- term.write(string.sub(tostring(profile[5]), k, k + width))
- end
- term.setCursorPos(1, height)
- term.write("Press f to view friends, or Space to view messages.")
- term.setBgColor(bgcolor)
- end
- function viewProfile(profileID)
- term.clear()
- message("Loading Profile...", 0)
- local profile = social.profile.get(username, password, profileID)
- profile[2] = profileID
- if not type(profile) == "table" then
- message(tostring(profile))
- profile = {"","","","",""}
- end
- local hasIcon, startBio = string.find(tostring(profile[5]), "!image!")
- local image = {}
- if hasIcon then
- image = textutils.unserialize(string.sub(tostring(profile[5]), 0, hasIcon))
- profile[5] = textutils.unserialize(string.sub(tostring(profile[5]), hasIcon, -1))
- end
- term.clear()
- while true do
- drawProfile(profile, image)
- local event, key = os.pullEvent("key")
- if key == 28 or key == keys.tab then
- return
- elseif key == keys.space then
- messages = social.post.getuser(username, password, profileID)
- messages[#messages + 1] = "Exit"
- showingUserMessages = true
- viewMessageList(true)
- elseif key == keys.f then
- ok, friends = pcall(social.friends.get, username, password, profileID)
- showingThisUsersFriends = false
- if ok then
- friends[#friends + 1] = "Exit"
- MyFriends(true)
- else
- message("This user has no friends.", -1)
- end
- end
- end
- end
- function addFriend()
- term.write("Add Friend:")
- local response = social.friends.add(username, password, read())
- if response == true then
- term.setCursorBlink(false)
- message("Friend Added!", -1)
- return LoadFriends()
- else
- term.setCursorBlink(false)
- message(response or "This user does not exist.", -1)
- return
- end
- end
- -- View Your Profile Menu --
- function ViewYourProfile()
- viewProfile(username)
- end
- -- Sign In Menu --
- function AfterSigningIn()
- message("Loading Messages...", 0)
- pcall(LoadMessages)
- message("Loading Friends...", 0)
- pcall(LoadFriends)
- message("Loading Users...", 0)
- pcall(LoadUsers)
- end
- function SignIn()
- term.clear()
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.setCursorPos(1, 1)
- term.clearLine()
- print("Sign In")
- term.write("Username: ")
- username = io.read()
- term.write("Password: ")
- password = read('*')
- local result = user.login(username, password)
- if result == true then
- options = optionsSignedIn
- local file = fs.open("SocialNetworkSignIn", "w")
- file.writeLine(username)
- file.writeLine(password)
- file.close()
- AfterSigningIn()
- elseif result == "Could not verify credentials." then
- message("The username or password you typed in is incorrect.", -1)
- else
- message(result, -1)
- end
- end
- function Register()
- term.clear()
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.setCursorPos(1, 1)
- term.clearLine()
- print("Register")
- term.write("Username: ")
- username = io.read()
- term.write("Password: ")
- password = read('*')
- term.write("Confirm Password: ")
- local matchPassword = read('*')
- if not password == matchPassword then
- return false
- end
- term.write("Email address: ")
- local email = ""
- email = read()
- while email == "" do
- print("Our new forgotten password system uses emails to allow users to change their passwords by sending them an email.")
- print("It is recommended that you type in an email address.")
- email = read()
- end
- local response = user.register(username, password, email)
- if response == true then
- options = optionsSignedIn
- local file = fs.open("SocialNetworkSignIn", "w")
- file.writeLine(username)
- file.writeLine(password)
- file.close()
- message("Account registered.", -1)
- else
- message(result, -1)
- end
- end
- function SignOut()
- if fs.exists("SocialNetworkSignIn") then
- fs.delete("SocialNetworkSignIn")
- end
- username, password = nil, nil
- message("Signed out.", -1)
- options = optionsSignedOut
- end
- function Exit()
- running = false
- end
- optionsSignedOut = {{"Login", SignIn}, {"Register", Register}, {"Exit", Exit}}
- optionsSignedIn = {{"Global Chat", Chat},
- {"All Messages", viewMessageList},
- {"All Users", viewUserList},
- {"Create New Post", sendMessagePrompt},
- {"Update My Profile", updateProfilePrompt},
- {"My Profile", ViewYourProfile},
- {"My Friends", MyFriends},
- {"Sign Out", SignOut},
- {"Exit", Exit}
- }
- -- Attempt to read from file
- local file = fs.open("SocialNetworkSignIn", "r")
- if file then
- username = file.readLine()
- password = file.readLine()
- file.close()
- message("Signing in...", 0)
- if user.login(username, password) then
- options = optionsSignedIn
- AfterSigningIn()
- else
- options = optionsSignedOut
- end
- else
- options = optionsSignedOut
- end
- -- Main menu --
- function drawMainMenu()
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- term.setCursorPos(1, 1)
- term.clear()
- print("Main Menu")
- for k, v in ipairs(options) do
- term.setCursorPos(1, 4 + k)
- if k == optionsel then
- term.setBgColor(highlightcolor)
- term.setTextColor(hitextcolor)
- else
- term.setBgColor(bgcolor)
- term.setTextColor(textcolor)
- end
- term.clearLine()
- term.write(v[1])
- end
- term.setBgColor(bgcolor)
- term.setCursorPos(1, height - 3)
- end
- function mainMenu()
- while running do
- drawMainMenu()
- local event, key = os.pullEvent("key")
- if key == 200 then
- optionsel = math.max(optionsel - 1, 1)
- elseif key == 208 then
- optionsel = math.min(optionsel + 1, #options)
- elseif key == 28 then
- options[optionsel][2]()
- end
- end
- end
- local signedin = false
- running = true
- local ok, err = pcall(mainMenu)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.black)
- term.clear()
- if not ok then
- term.setTextColor(colors.red)
- print(err)
- end
- term.setTextColor(colors.white)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement