Guest User

mainProg

a guest
Jul 4th, 2013
36
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.02 KB | None | 0 0
  1. chat= peripheral.wrap("bottom")
  2. while true do
  3.  e,sender,input = os.pullEvent("chat")
  4.  word = {}
  5.  jarvCheck = false
  6.  sendCheck
  7.  --converts input into an array and checks the
  8.  --message to make sure it was adressed to jarvis
  9.  for match in string.gmatch(input,"[^%s]+") do
  10.   table.insert(word,match)
  11.  end
  12.  --checking sender is a kalmocorps employee
  13.  for match in string.gmatch(input,"[^%s]+") do
  14.   if string.lower(match) == "jarvis" or "jarv" then
  15.      jarvCheck =  true
  16.      break
  17.   end
  18.  end  
  19.  if jarvCheck == true then
  20.   file = io.open("perms")
  21.   for line in file:lines() do
  22.    if sender == line then
  23.     sendCheck = true
  24.     break
  25.    end
  26.   end
  27.  end
  28.  if sendCheck == true then
  29.   reply =" "
  30.   print("valid message recieved ".. sender ..":".. input)
  31.   --add replies here, using the word[] array, and reply var  
  32.   if reply == " " then reply = "sorry i didnt understand" end
  33.   chat.say("Jarvis: "..reply)
  34.   else
  35.    chat.say("Jarvis: sorry ".. sender .. " you are not permitted to talk to me")
  36.   end
  37.  end
Advertisement
Add Comment
Please, Sign In to add comment