Advertisement
MiraMiraMira

chatBot

Dec 2nd, 2014
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.11 KB | None | 0 0
  1. rednet.open("top")
  2. term.clear()
  3. local username = ("Anon"..tostring(math.random(1,10000)))
  4. local usernameSet = false
  5. textutils.slowWrite("--------------------------------\n", 50)
  6. textutils.slowWrite("   Welcome to Abu Chat - v0.1   \n", 50)
  7. textutils.slowWrite("--------------------------------\n\n", 50)
  8. print("Press \"t\" to Type\n")
  9.  
  10. function resTerm()
  11.     term.clear()
  12.     term.setCursorPos(1,1)
  13.     print("--------------------------------\n")
  14.     print("   Welcome to Abu Chat - v0.1   \n")
  15.     print("--------------------------------\n\n")
  16.     print("Press \"t\" to Type\n")
  17. end
  18.  
  19. function mainLoop()
  20.     while true do
  21.         event, id, msg = os.pullEvent()
  22.         if event == "char" then
  23.             if id == "t" then
  24.                 msg = read()
  25.                 rednet.broadcast(textutils.formatTime(os.time(), false).." "..username..": "..msg)
  26.             end
  27.         end
  28.     end
  29. end
  30.  
  31. function listen()
  32.     while true do
  33.         event, id, msg = os.pullEvent()
  34.         if event == "rednet_message" then
  35.             print(msg)
  36.         end
  37.     end
  38. end
  39.  
  40. parallel.waitForAll(listen, mainLoop)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement