Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get zvV7Le0F ourchat
- -- std pb zvV7Le0F ourchat
- getChatURL = "http://minechat.x10host.com/index.php?true=true"
- postChatURL = "http://minechat.x10host.com/index.php?words="
- tMess = {}
- tDisplay = {}
- tArg = {...}
- scr_x, scr_y = term.getSize()
- if tArg[1] then
- playername = table.concat(tArg, " ")
- else
- term.clear()
- term.setCursorPos(2,scr_y-2)
- print("Enter your name:")
- repeat
- term.setCursorPos(2,scr_y-1)
- term.clearLine()
- write(">>")
- playername = read()
- until playername ~= ""
- -- print(fs.getName(shell.getRunningProgram()) .. " <username>")
- -- return false
- end
- function send(data)
- local a = http.post(postChatURL..textutils.urlEncode(data))
- return a
- end
- commands = {
- ["me"] = function()
- if string.len(arg1) > 0 then
- send( "* "..playername.." "..arg1 )
- else
- putInDisplay("/me <whatever>")
- end
- end,
- ["nick"] = function()
- if string.len(arg1) > 0 then
- local sOldName = playername
- playername = arg1
- send( "* "..sOldName.." is now known as "..playername )
- else
- putInDisplay("/nick <newname>")
- end
- end,
- ["help"] = function()
- putInDisplay("Available commands:")
- local sCommands = "*"
- for sCommand, fnCommand in pairs( commands ) do
- sCommands = sCommands .. " /" .. sCommand
- end
- putInDisplay( sCommands.." /logout" )
- end,
- ["insult"] = function()
- insults = {
- "USERNAME can go eat a bag of shiza.",
- "USERNAME is fat and ugly and really, really stupid.",
- "USERNAME is a fat sack o' crap.",
- "If USERNAME was admin...eh, I don't want to think of such things...",
- "No one is more pathetic than USERNAME.",
- "USERNAME is known to suck more than Kirby.",
- "USERNAME was the inspiration of Bubsy 3D.",
- "USERNAME's IQ is his age...times two!",
- "USERNAME's programming skills rival that of the Software Toolworks.",
- "Down with USERNAME, the killer of kings!",
- "USERNAME can go suck it!",
- "Stop being so adversarial, USERNAME!",
- "USERNAME cannot beat Air Man!",
- "USERNAME likes Daikatana and Bubsy.",
- "USERNAME is like King Midas, except with coagulated blood rather than gold.",
- "USERNAME's mother was a hampster, and his father smells of elderberry!",
- "Ni!",
- "USERNAME is a dishonorable Ferrengi p'tach!",
- "Pepperoni is too spicy for USERNAME.",
- }
- send(string.gsub(insults[math.random(1,#insults)],"USERNAME",arg1))
- end,
- ["kill"] = function()
- if #arg1 < 1 then
- send(playername.." was killed.")
- else
- send(arg1.." was killed.")
- end
- end,
- ["id"] = function()
- send(playername.."'s computer ID is "..os.getComputerID()..".")
- end,
- ["clear"] = function()
- send(string.rep(" ",(51*19))..playername.." cleared the screen.")
- end,
- ["exit"] = function()
- send(playername.." has left the chat")
- return true
- end,
- ["logout"] = function()
- send(playername.." has left the chat")
- return true
- end,
- }
- local function scrollClear(speed)
- scr_x, scr_y = term.getSize()
- for a = 1, scr_y/speed do
- term.scroll(speed*speed)
- sleep(0)
- end
- end
- function putInDisplay(text)
- tDisplay[#tDisplay+1] = tostring(text)
- redraw = true
- return tostring(text)
- end
- function seperateMethods(input)
- output={}
- for key,value in pairs(input) do
- table.insert(output, {key,value})
- end
- return output
- end
- local function b()
- send(playername.." joined the chat!")
- while true do
- term.setCursorPos(1,scr_y)
- term.clearLine()
- write(":")
- mess = io.read()
- term.setCursorPos(1,scr_y-1)
- term.clearLine()
- local sCommand = string.match( mess, "^/([a-z]+)" )
- if sCommand then
- local fnCommand = commands[sCommand]
- if fnCommand then
- if string.find(mess," ") then
- arg1 = string.sub(mess,string.find(mess," ")+1)
- a = fnCommand(arg1)
- else
- arg1 = ""
- a = fnCommand()
- end
- if a == true then
- return true
- end
- else
- print("Bad command!")
- end
- else
- send( "<"..playername.."> "..mess )
- end
- end
- end
- local function clearLines(top, bottom)
- for a = top, bottom do
- term.setCursorPos(1,a)
- term.clearLine()
- end
- end
- function chatPrint(log)
- if not type(log) == "table" then log = {log} end
- local prevX, prevY = term.getCursorPos()
- clearLines(1,scr_y-1)
- indent = 0 --in case any line is greater than the length of the screen
- indentIn = 0 --in the same case, mid writing
- for a = 1, #log do
- indent = indent + math.floor(#log[a]/scr_x)
- end
- for a = 1, #log do
- for b = 0, math.floor(#log[a]/scr_x) do
- if b > 0 then indentIn = indentIn + 1 end
- term.setCursorPos(1,((((scr_y-1)+a-#log))-indent)+indentIn)
- write(string.sub(log[a],(b*scr_x),((b*scr_x)+scr_x)-1))
- end
- end
- term.setCursorPos(prevX,scr_y)
- end
- function a()
- while true do
- for a = 1, 5 do
- get = http.post(getChatURL)
- if get then break else
- print("Cannot connect to server...retrying...")
- sleep(1)
- end
- end
- if not get then error("Failed to reach server. Try again later.") end
- get = get.readAll()
- if (tMess[#tMess] ~= get) and (redraw ~= true) then putInDisplay(get) end
- if get ~= tMess[#tMess] or redraw == true then
- if redraw == true then tMess[#tMess+1] = get end
- chatPrint(tDisplay)
- redraw = false
- end
- end
- end
- term.clear()
- parallel.waitForAny(a, b)
- scrollClear(2)
- term.setCursorPos(1,1)
- print("Thank you for using OurChat!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement