Advertisement
mtlballer

HAL9000 v1.10

Dec 6th, 2015
279
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.98 KB | None | 0 0
  1. --Big thank you to PixelDepth and his aerial interface code found here: http://pastebin.com/xusGgxtp
  2. --And to mattijv for the cleverbot API http://pastebin.com/Dv9x1ppc
  3.  
  4. os.loadAPI("cleverbot")
  5. bot = cleverbot.Cleverbot.new()
  6. local bridge = peripheral.wrap("top")
  7. local chatbox = peripheral.wrap("back")
  8. local speaker = peripheral.wrap("left")
  9. local giveDirection = "south"
  10. local redstoneColor = nil
  11. local range = 100000
  12. local name = "HAL9000"
  13. local names = {"mtlballer","voxelgamer","ov104","asilentcrow"}
  14. amount = 64
  15. itemID = 1
  16. item = ""
  17. meta = 0
  18. lang = "en"
  19. response = ""
  20. local cleverness = true
  21. displayNameTable = {}
  22. nameTable = {}
  23. amountTable = {}
  24. metaTable = {}
  25. craftTable = {}
  26. howMany = 1
  27. canCraft = false
  28.  
  29. --listAll goes 1:amoutn 2:meta 3:dpName 4:fullname
  30.  
  31. local function getCraft()
  32.  
  33. for j,k in pairs(bridge.listCraft()) do
  34.     if r == "displayName" then
  35.         table.insert(craftTable, k)
  36.     end
  37. end
  38. end
  39.  
  40. local function getItems()
  41.  
  42. for k,v in pairs(bridge.listAll()) do
  43.     for r,w in pairs(v) do
  44.         if r == "displayName" then
  45.             table.insert(displayNameTable, w)
  46.         end
  47.         if r == "name" then
  48.             table.insert(nameTable, w)
  49.         end
  50.         if r == "amount" then
  51.             table.insert(amountTable, w)
  52.         end
  53.         if r == "meta" then
  54.             table.insert(metaTable, w)
  55.         end
  56.     end
  57. end
  58.  
  59. end
  60.  
  61. local function parseCommand(command, player, message, num)
  62.  
  63.         --print(command[1].."!")
  64.        
  65.         if (string.lower(player) == names[1]) then
  66.             redstoneColor = "colors.blue"
  67.             giveDirection = "south"
  68.         elseif (string.lower(player) == names[2]) then
  69.             redstoneColor = "colors.red"
  70.             giveDirection = "north"
  71.         elseif (string.lower(player) == names[3]) then
  72.             redstoneColor = "colors.yellow"
  73.             giveDirection = "east"
  74.         elseif (string.lower(player) == names[4]) then
  75.             redstoneColor = "colors.green"
  76.             giveDirection = "west"
  77.         end
  78.    
  79.         if (string.lower(command[1]) == "give") then
  80.             getItems()
  81.             getCraft()
  82.             if tonumber(num[1]) ~= nil then
  83.                 amount = tonumber(num[1])
  84.             else amount = 64
  85.             end
  86.             if num[2] ~= nil then
  87.                 meta = num[2]
  88.             else meta = 0
  89.             end
  90.             for e,d in pairs(displayNameTable) do
  91.                 if string.lower(command[2]) == string.lower(d) then
  92.                     itemID = e
  93.                 end
  94.             end
  95.             for f,g in pairs(craftTable) do
  96.                 if string.lower(command[2]) == string.lower(g) then
  97.                     canCraft = true
  98.                 end
  99.             end
  100.             item = nameTable[itemID]
  101.             meta = metaTable[itemID]
  102.             if amount > tonumber(amountTable[itemID]) and canCraft == true then
  103.                 chatbox.say("There is currently only "..amountTable[itemID].." in the system, would you like me to craft the amount missing?", range, false, name)
  104.                 ev, pl, m = os.pullEvent("chat")
  105.                 if m == string.lower("yes") then
  106.                    
  107.                     bridge.craft(item.." "..meta,(amount-tonumber(amountTable[itemID]) + 1))
  108.                     os.pullEvent("craftingComplete")
  109.                     print("done craft")
  110.                 end
  111.             end
  112.             --print(amount,item,meta,player)
  113.             bridge.retrieve(item.." "..meta, amount, giveDirection)
  114.             chatbox.say("Giving "..amount.." of "..command[2].." to "..player..".", range, false , name)
  115.             --speaker.speak("Giving "..command[2].." of "..command[1].." to "..player..".", range, lang)
  116.             --[[for k,v in pairs(nameTable) do
  117.                 nameTable[k] = nil
  118.                 displayNameTable[k] = nil
  119.                 metaTable[k] = nil
  120.                 amountTable[k] = nil
  121.             end ]]
  122.             canCraft = false
  123.         elseif (string.lower(command[1]) == "amount" ) then
  124.             getItems()
  125.             for e,d in pairs(displayNameTable) do
  126.                 if string.lower(command[2]) == string.lower(d) then
  127.                     itemID = e
  128.                 end
  129.             end
  130.             item = nameTable[itemID]
  131.             meta = metaTable[itemID]
  132.             howMany = amountTable[itemID]
  133.             chatbox.say("There is currently "..howMany.." of "..command[2].." currently in the system", range, false , name)
  134.            
  135.         elseif (string.lower(command[1]) == "craft" ) then
  136.             getItems()
  137.             if tonumber(num[1]) ~= nil then
  138.                 amount = tonumber(num[1])
  139.             else amount = 64
  140.             end
  141.             if num[2] ~= nil then
  142.                 meta = num[2]
  143.             else meta = 0
  144.             end
  145.             for e,d in pairs(displayNameTable) do
  146.                 if string.lower(command[2]) == string.lower(d) then
  147.                     itemID = e
  148.                 end
  149.             end
  150.             item = nameTable[itemID]
  151.             meta = metaTable[itemID]
  152.             --print(amount,item,meta,player)
  153.             bridge.craft(item.." "..meta, amount)
  154.             chatbox.say("I am crafting "..command[2], range, false , name)
  155.             --speaker.speak("Giving "..command[2].." of "..command[1].." to "..player..".", range, lang)
  156.             --[[for k,v in pairs(nameTable) do
  157.                 nameTable[k] = nil
  158.                 displayNameTable[k] = nil
  159.                 metaTable[k] = nil
  160.                 amountTable[k] = nil
  161.             end ]]
  162.        
  163.         elseif string.lower(command[1]) == "open" and string.lower(command[2]) == "the" and string.lower(command[3]) == "pod" and string.lower(command[4]) == "bay" and string.lower(command[5]) == "doors" then
  164.             chatbox.say("I'm sorry "..player..", I'm afraid I can't do that")
  165.        
  166.         elseif (string.lower(command[1]) == "christmas") then
  167.             giveDirection = "east"
  168.             if (string.lower(command[2]) == "mtlballer") then
  169.                 redstoneColor = "colors.blue"
  170.                 giveDirection = "north"
  171.             elseif (string.lower(command[2]) == "voxelgamer") then
  172.                 redstoneColor = "colors.red"
  173.                 giveDirection = "north"
  174.             elseif (string.lower(command[2]) == "ov104") then
  175.                 redstoneColor = "colors.yellow"
  176.                 giveDirection = "east"
  177.             elseif (string.lower(command[2]) == "asilentcrow") then
  178.                 redstoneColor = "colors.green"
  179.                 giveDirection = "west"
  180.             end
  181.             bridge.retrieve("minecraft:coal",5000,giveDirection)
  182.         elseif (string.lower(command[1]) == "clever") then
  183.             if command[2] == nil then
  184.                 cleverness = not cleverness
  185.                 if cleverness == true then
  186.                     chatbox.say("Powering Up!", range, false, name)
  187.                 else
  188.                     chatbox.say("I'll be back", range, false, name)
  189.                 end
  190.             elseif (string.lower(command[2]) == "on" ) then
  191.                 cleverness = true
  192.                 chatbox.say("Powering Up!", range, false, name)
  193.             elseif (string.lower(command[2]) == "off") then
  194.                 cleverness = false
  195.                 chatbox.say("I'll be back", range, false, name)
  196.             end
  197.         else
  198.             if cleverness == true then
  199.                 if message ~= nil then
  200.                     response = bot:send(message)
  201.                     if response ~= nil then
  202.                     chatbox.say(response, range, false, name)
  203.                     end
  204.                 end
  205.             end
  206.         end
  207.        
  208. end
  209.  
  210.  
  211. local function monitor()
  212.     while true do
  213.         local event, player, message = os.pullEvent("chat")
  214.         local command = {}
  215.         local counter = 1
  216.         local num = {}
  217.         local numC = 1
  218.        
  219.         for part in message:gmatch("%S+") do
  220.             command[counter] = part
  221.             counter = counter + 1
  222.         end
  223.        
  224.         if string.lower(command[1]) == "give" then
  225.            
  226.             if string.find(message, "%d") == nil then
  227.                 message = message.." 64"
  228.             end
  229.            
  230.             lastSpace = string.find(message, "%s%d")
  231.             lastSpace = lastSpace -1
  232.             item = string.sub(message, 6, lastSpace)
  233.             command[2] = item
  234.             rMessage = string.reverse(message)
  235.             lastSpacenum = string.find(rMessage, "%d%s")
  236.             lastSpacenum = lastSpacenum
  237.             test = string.reverse(string.sub(rMessage, 0, lastSpacenum))
  238.             num[1] = tonumber(test)
  239.            
  240.         elseif string.lower(command[1]) == "craft" then
  241.             if string.find(message, "%d") == nil then
  242.                 message = message.." 64"
  243.             end
  244.            
  245.             lastSpace = string.find(message, "%s%d")
  246.             lastSpace = lastSpace -1
  247.             item = string.sub(message, 7, lastSpace)
  248.             command[2] = item
  249.             rMessage = string.reverse(message)
  250.             lastSpacenum = string.find(rMessage, "%d%s")
  251.             lastSpacenum = lastSpacenum
  252.             test = string.reverse(string.sub(rMessage, 0, lastSpacenum))
  253.             num[1] = tonumber(test)
  254.        
  255.        
  256.         elseif string.lower(command[1]) == "amount" then
  257.             if string.find(message, "%d") == nil then
  258.                 message = message.." 64"
  259.             end
  260.            
  261.             lastSpace = string.find(message, "%s%d")
  262.             lastSpace = lastSpace -1
  263.             item = string.sub(message, 8, lastSpace)
  264.             command[2] = item
  265.             rMessage = string.reverse(message)
  266.             lastSpacenum = string.find(rMessage, "%d%s")
  267.             lastSpacenum = lastSpacenum
  268.             test = string.reverse(string.sub(rMessage, 0, lastSpacenum))
  269.             num[1] = tonumber(test)
  270.         end
  271.        
  272.         parseCommand(command, player, message, num)
  273.        
  274.     end
  275. end
  276.  
  277.  
  278.  
  279. monitor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement