View difference between Paste ID: NQVPiSWZ and zvV7Le0F
SHOW: | | - or go back to the newest paste.
1-
-- pastebin get zvV7Le0F ourchat
1+
-- pastebin get NQVPiSWZ ourchat-rl
2-
-- std pb zvV7Le0F ourchat
2+
-- std pb NQVPiSWZ ourchat-rl
3
4-
getChatURL = "http://minechat.x10host.com/index.php?true=true"
4+
5-
postChatURL = "http://minechat.x10host.com/index.php?words="
5+
6
scr_x, scr_y = term.getSize()
7
8-
tDisplay = {}
8+
playerNames = {} --list of player names to keep track of nicknames
9
10
chat = peripheral.find("chatbox_admin")
11-
if tArg[1] then
11+
if not chat then
12-
	playername = table.concat(tArg, " ")
12+
	chat = peripheral.find("chatbox")
13-
else
13+
	if not chat then
14-
	term.clear()
14+
		chat = peripheral.find("chat_box")
15-
	term.setCursorPos(2,scr_y-2)
15+
		if not chat then
16-
	print("Enter your name:")
16+
			error("Requires a chatbox.")
17-
	repeat
17+
18-
		term.setCursorPos(2,scr_y-1)
18+
19
end
20-
		write(">>")
20+
21-
		playername = read()
21+
22-
	until playername ~= ""
22+
	local a = http.post("http://minechat.x10host.com/index.php?words="..textutils.urlEncode(data))
23-
--	print(fs.getName(shell.getRunningProgram()) .. " <username>")
23+
24-
--	return false
24+
25
26
commands = {
27
	["me"] = function()
28-
	local a = http.post(postChatURL..textutils.urlEncode(data))
28+
29
			send( "* "..playerNames[playername].." "..arg1 )
30
		else
31
			chat.tell(playername, "/me <whatever>")
32
		end
33
	end,
34
	["nick"] = function()
35-
			send( "* "..playername.." "..arg1 )
35+
		if not playerNames[playername] then
36
			playerNames[playername] = playername
37-
			putInDisplay("/me <whatever>")
37+
38
		if string.len(arg1) > 0 then
39
			playerNames[playername] = "'"..arg1.."'"
40
			send( "* "..playerNames[playername].." is now known as "..arg1 )
41
		else
42-
			local sOldName = playername
42+
			chat.tell(playername, "/nick <newname>")
43-
			playername = arg1
43+
44-
			send( "* "..sOldName.." is now known as "..playername )
44+
45
	["help"] = function()
46-
			putInDisplay("/nick <newname>")
46+
		chat.tell(playername, "Available commands:")
47
		local sCommands = "*"
48
		for sCommand, fnCommand in pairs( commands ) do
49
			sCommands = sCommands .. " ##:" .. sCommand
50-
		putInDisplay("Available commands:")
50+
51
		chat.tell(playername, sCommands)
52
	end,
53-
			sCommands = sCommands .. " /" .. sCommand
53+
	["insult"] = function() --the insult command is a very useful utility in making children cry
54
		insults = {
55-
		putInDisplay( sCommands.." /logout" )
55+
56
			"USERNAME is fat and ugly and really, really stupid.",
57-
	["insult"] = function()
57+
58
			"If USERNAME was admin...eh, I don't want to think of such things...",
59
			"No one is more pathetic than USERNAME.",
60
			"USERNAME is known to suck more than Kirby.",
61
			"USERNAME was the inspiration of Bubsy 3D.",
62
			"USERNAME's IQ is his age...times two!",
63
			"USERNAME's programming skills rival that of the Software Toolworks.",
64
			"Down with USERNAME, the killer of kings!",
65
			"USERNAME can go suck it!",
66
			"Stop being so adversarial, USERNAME!",
67
			"USERNAME cannot beat Air Man!",
68
			"USERNAME likes Daikatana and Bubsy.",
69
			"USERNAME is like King Midas, except with coagulated blood rather than gold.",
70
			"USERNAME's mother was a hampster, and his father smells of elderberry!",
71
			"Ni!",
72
			"USERNAME is a dishonorable Ferrengi p'tach!",
73
			"Pepperoni is too spicy for USERNAME.",
74
		}
75
		send(string.gsub(insults[math.random(1,#insults)],"USERNAME",arg1))
76
	end,
77
	["kill"] = function() --a useless command, I admit. But funny.
78
		if #arg1 < 1 then
79
			send(playerNames[playername].." was killed.")
80
		else
81-
	["kill"] = function()
81+
82
		end
83-
			send(playername.." was killed.")
83+
84
	["whois"] = function()
85
		local names = seperateMethods(playerNames)
86
		for a = 1, #names do
87
			if names[2] == "'"..arg1.."'" then
88
				chat.tell(playername, arg1.." is actually '"..names[2].."'")
89-
		send(playername.."'s computer ID is "..os.getComputerID()..".")
89+
				break
90
			end
91-
	["clear"] = function()
91+
92-
		send(string.rep(" ",(51*19))..playername.." cleared the screen.")
92+
93
	["id"] = function()
94-
	["exit"] = function()
94+
		send(playerNames[playername].." is not a computer.")
95-
		send(playername.." has left the chat")
95+
96-
		return true
96+
97
98-
	["logout"] = function()
98+
local function seperateMethods(input)
99-
		send(playername.." has left the chat")
99+
100-
		return true
100+
101
		table.insert(output, {key,value})
102
	end
103
	return output
104-
local function scrollClear(speed)
104+
105-
	scr_x, scr_y = term.getSize()
105+
106-
	for a = 1, scr_y/speed do
106+
function b()
107-
		term.scroll(speed*speed)
107+
108-
		sleep(0)
108+
		ev, side, playername, mess = os.pullEvent("chat_message")
109
		if not playerNames[playername] then
110
			playerNames[playername] = playername
111
		end
112-
function putInDisplay(text)
112+
		local sCommand = string.match( mess, ":([a-z]+)" )
113-
	tDisplay[#tDisplay+1] = tostring(text)
113+
114-
	redraw = true
114+
115-
	return tostring(text)
115+
116
				if string.find(mess," ") then
117
					arg1 = string.sub(mess,string.find(mess," ")+1)
118-
function seperateMethods(input)
118+
					ab = fnCommand(arg1)
119
				else
120
					arg1 = ""
121
					ab = fnCommand()
122
				end
123
				if ab == true then
124
					return true
125
				end
126-
local function b()
126+
127-
	send(playername.." joined the chat!")
127+
				chat.tell(playername, "Bad command!")
128
			end
129-
		term.setCursorPos(1,scr_y)
129+
130
			fullMess = "<"..playerNames[playername].."> "..mess
131-
		write(":")
131+
			tMess[#tMess+1] = fullMess
132-
		mess = io.read()
132+
			send( fullMess )
133-
		term.setCursorPos(1,scr_y-1)
133+
134
	end
135-
		local sCommand = string.match( mess, "^/([a-z]+)" )
135+
136
137
function clearLines(top, bottom)
138
	for a = top, bottom do
139
		term.setCursorPos(1,a)
140
		term.clearLine()
141-
					a = fnCommand(arg1)
141+
142
end
143
144-
					a = fnCommand()
144+
145
	while true do
146-
				if a == true then
146+
		local b = http.post("http://minechat.x10host.com/index.php?true=true")
147
		if b then
148
			b = b.readAll()
149
		else
150-
				print("Bad command!")
150+
			error("Server not found. :(")
151
		end
152
		if (b ~= tMess[#tMess]) and (b ~= fullMess) then
153-
			send( "<"..playername.."> "..mess )
153+
			tMess[#tMess+1] = b
154
			chat.say(tMess[#tMess])
155
		end
156
	end
157
end
158-
local function clearLines(top, bottom)
158+
159
function showListofAllNames()
160
	while true do
161
		term.clear()
162
		term.setCursorPos(1,1)
163
		for a = 1, #tMess do
164
			print(tMess[a])
165-
function chatPrint(log)
165+
166-
	if not type(log) == "table" then log = {log} end
166+
		repeat
167-
	local prevX, prevY = term.getCursorPos()
167+
			oldPlayerNames = playerNames
168-
	clearLines(1,scr_y-1)
168+
			sleep(0.5)
169-
	indent = 0 --in case any line is greater than the length of the screen
169+
		until oldPlayerNames ~= playerNames
170-
	indentIn = 0 --in the same case, mid writing
170+
171-
	for a = 1, #log do
171+
		
172-
		indent = indent + math.floor(#log[a]/scr_x)
172+
173
174-
	for a = 1, #log do
174+
parallel.waitForAny(a, b, showListofAllNames)
175-
		for b = 0, math.floor(#log[a]/scr_x) do
175+
176-
			if b > 0 then indentIn = indentIn + 1 end
176+
177-
			term.setCursorPos(1,((((scr_y-1)+a-#log))-indent)+indentIn)
177+