Advertisement
bryceio

Computercraft JarvOS

Oct 20th, 2018
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.43 KB | None | 0 0
  1. --Normally requires Peripherals Plus One, but can be heavily modified for console usage.
  2. --Made by bryceio
  3. local chat = peripheral.wrap("left")
  4. local playerdetector = peripheral.wrap("right")
  5. local commands = {}
  6. local newcommand = {}
  7. local blacklist = {}
  8. local admins = {"bryceio"}
  9. local responsetable = {}
  10. local event, player, input = os.pullEvent("chat")
  11. local i = 1
  12. local x = 1
  13. local y = 1
  14. local admin = false
  15. rednet.open("back")
  16.  
  17. for i = 1,#blacklist do
  18.     if blacklist[i] == player and player ~= "bryceio" then
  19.         sleep(0.5)
  20.         chat.say("Access Denied")
  21.             console = fs.open("log", "a")
  22.               console.writeLine(player.." tried to access Jarvis")
  23.               console.close()
  24.         shell.run("JarvOS")
  25.     end
  26. end
  27.  
  28. i = 1
  29.  
  30. for i = 1,#input do
  31.     temp = input:sub(i, i)
  32.     if temp == " " then
  33.         commands[x] = table.concat(newcommand)
  34.         newcommand = {}
  35.         x = x + 1
  36.         y = 1
  37.     else
  38.         newcommand[y] = temp
  39.         y = y + 1
  40.     end
  41. end
  42.  
  43. commands[x] = table.concat(newcommand)
  44. newcommand = {}
  45. i = 1
  46. x = 1
  47. y = 1
  48. sleep(0.5)
  49.  
  50.  
  51. if commands[1] == "Jarvis" or commands[1] == "jarvis" or commands[1] == "Jarvis," or commands[1] == "jarvis," then
  52.     console = fs.open("log", "a")
  53.     console.writeLine(player..": "..table.concat(commands, " "))
  54.     console.close()
  55.     admins[#admins+1] = "bryceio"
  56.     if commands[2] == "Say" or commands[2] == "say" then
  57.         x = 1
  58.         for i = 3,#commands do
  59.             responsetable[x] = commands[i]
  60.             x = x + 1
  61.         end    
  62.         response = table.concat(responsetable, " ")
  63.         chat.say(response)
  64.     elseif commands[2] == "Play" or commands[2] == "play" then
  65.         if fs.exists("playdisc") then
  66.             shell.run("playdisc "..commands[3])
  67.             chat.say("Playing "..commands[3])
  68.         end
  69.     elseif commands[2] == "Stop" or commands[2] == "stop" then
  70.         if commands[3] == "Music" or commands[3] == "music" then
  71.             rednet.broadcast("cease", "JarvOS Music Stop")
  72.             chat.say("Stopping music.")
  73.         elseif commands[3] == "Shuffle" or commands[3] == "shuffle" then
  74.             rednet.broadcast("cease", "JarvOS Shuffle Stop")
  75.             chat.say("Stopping shuffle.")
  76.         end
  77.     elseif commands[2] == "Shuffle" or commands[2] == "shuffle" then
  78.             rednet.broadcast("shuffle", "JarvOS Music Shuffle")
  79.             chat.say("Shuffling music.")      
  80.     elseif commands[2] == "What" or commands[2] == "what" then
  81.         if commands[3] == "Time" or commands[3] == "time" then
  82.             if os.time() <= 12 then
  83.                 chat.say(tostring(os.time())..":00 AM")
  84.             else
  85.                 chat.say(tostring(os.time()-12)..":00 PM")
  86.             end
  87.         end
  88.     elseif commands[2] == "Who" or commands[2] == "who" then
  89.         if commands[3] == "Is" or commands[3] == "is" then
  90.             if commands[4] == "Nearby" or commands[4] == "nearby" or commands[4] == "Near" or commands[4] == "near" then
  91.                 players = playerdetector.getNearbyPlayers(64)
  92.                 for i = 1,#players do
  93.                     players[i] = players[i].player
  94.                 end
  95.                 chat.say(table.concat(players, ", "))
  96.             end
  97.         end
  98.     elseif commands[2] == "Take" or commands[2] == "take" then
  99.         if commands[3] == "A" or commands[3] == "a" then
  100.             if commands[4] == "Note" or "note" then
  101.                 if fs.exists("takenotes") then
  102.                     shell.openTab("takenotes "..player)
  103.                 end
  104.             end
  105.         end
  106.     elseif commands[2] == "Admin" or commands[2] == "admin" then
  107.         for i = 1,#admins do
  108.             if admins[i] == player then
  109.                 admin = true
  110.             end
  111.         end
  112.         if admin == true then
  113.             chat.say("Access granted.")
  114.             if commands[3] == "Reboot" or commands[3] == "reboot" then
  115.                 sleep(1.5)
  116.                 chat.say("Rebooting")
  117.                 os.reboot()
  118.             elseif commands[3] == "Terminate" or commands[3] == "terminate" then
  119.                 sleep(1.5)
  120.                 chat.say("Shutting down JarvOS.")
  121.                 error()
  122.             elseif commands[3] == "Lockdown" or commands[3] == "lockdown" then
  123.                 sleep(1.5)
  124.                 chat.say('Are you sure? Type "Yes" to confirm or "No" to cancel.')
  125.                 admin = false
  126.                 repeat
  127.                     event, player, message = os.pullEvent("chat")
  128.                     if message == "Yes" or message == "yes" or message == "No" or message == "no" then
  129.                         for i = 1,#admins do
  130.                             if admins[i] == player then
  131.                                 admin = true
  132.                             end
  133.                         end
  134.                     end
  135.                 until admin == true
  136.                 if message == "Yes" or message == "yes" then
  137.                     sleep(1)
  138.                     chat.say("Going into system lockdown.")
  139.                     if fs.exists("lockdown") then
  140.                         shell.run("lockdown")
  141.                     end
  142.                 elseif message == "No" or message == "no" then
  143.                     sleep(1)
  144.                     chat.say("Lockdown cancelled.")
  145.                 end
  146.             end
  147.         else
  148.             chat.say("Access denied.")
  149.         end
  150.     end
  151.     shell.run("JarvOS")
  152. else
  153.     shell.run("JarvOS")
  154. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement