View difference between Paste ID: wCCkxzPR and umRxH7wN
SHOW: | | - or go back to the newest paste.
1
local msg = ""
2
local allow = true
3
local messages = {}
4-
  local event, key, is_held = os.pullEvent("key")
4+
5-
  term.clear()
5+
	local event, key, is_held = os.pullEvent("key")
6-
  term.setCursorPos(1,#messages+1)
6+
	term.clear()
7-
  term.write(msg)
7+
	for i=1,#messages do
8-
  if not is_held then
8+
		ms = messages[i]
9-
        if key == 257 then
9+
		role = ms["role"]
10-
			--something cool
10+
        content = ms["content"]
11-
        elseif key == 259 then
11+
		term.setCursorPos(1,i)
12-
            msg = string.sub(print(key.." | "..keys.getName(key)),1,-2)
12+
        if role == "user" then
13-
		else
13+
        	term.write("[YOU]"..content)
14-
            msg = msg..keys.getName(key)
14+
        else
15
        	term.write("[BOT]"..content)
16-
  end
16+
17
	end
18
	term.setCursorPos(1,#messages+1)
19
	term.write(msg)
20
	if not is_held then
21
		if key == 257 then
22
			local request = http.get("https://keyexternalentropy.kirkashow.repl.co/"..os.computerID().."/ask?text="..msg)
23
            messages = textutils.unserializeJSON(request.readAll())
24
            request.close()
25
		elseif key == 259 then
26
			msg = string.sub(msg,1,-2)
27
		elseif #keys.getName(key) == 1 then
28
			msg = msg..keys.getName(key)
29
		end
30
	end
31
end