Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Big thank you to PixelDepth and his aerial interface code found here: http://pastebin.com/xusGgxtp
- --And to mattijv for the cleverbot API http://pastebin.com/Dv9x1ppc
- os.loadAPI("cleverbot")
- bot = cleverbot.Cleverbot.new()
- local bridge = peripheral.wrap("top")
- local chatbox = peripheral.wrap("back")
- local speaker = peripheral.wrap("left")
- local giveDirection = "south"
- local redstoneColor = nil
- local range = 100000
- local name = "HAL9000"
- local names = {"mtlballer","voxelgamer","ov104","asilentcrow"}
- amount = 64
- itemID = 1
- item = ""
- meta = 0
- lang = "en"
- response = ""
- local cleverness = true
- displayNameTable = {}
- nameTable = {}
- amountTable = {}
- metaTable = {}
- craftTable = {}
- howMany = 1
- canCraft = false
- --listAll goes 1:amoutn 2:meta 3:dpName 4:fullname
- local function getCraft()
- for j,k in pairs(bridge.listCraft()) do
- if r == "displayName" then
- table.insert(craftTable, k)
- end
- end
- end
- local function getItems()
- for k,v in pairs(bridge.listAll()) do
- for r,w in pairs(v) do
- if r == "displayName" then
- table.insert(displayNameTable, w)
- end
- if r == "name" then
- table.insert(nameTable, w)
- end
- if r == "amount" then
- table.insert(amountTable, w)
- end
- if r == "meta" then
- table.insert(metaTable, w)
- end
- end
- end
- end
- local function parseCommand(command, player, message, num)
- --print(command[1].."!")
- if (string.lower(player) == names[1]) then
- redstoneColor = "colors.blue"
- giveDirection = "south"
- elseif (string.lower(player) == names[2]) then
- redstoneColor = "colors.red"
- giveDirection = "north"
- elseif (string.lower(player) == names[3]) then
- redstoneColor = "colors.yellow"
- giveDirection = "east"
- elseif (string.lower(player) == names[4]) then
- redstoneColor = "colors.green"
- giveDirection = "west"
- end
- if (string.lower(command[1]) == "give") then
- getItems()
- getCraft()
- if tonumber(num[1]) ~= nil then
- amount = tonumber(num[1])
- else amount = 64
- end
- if num[2] ~= nil then
- meta = num[2]
- else meta = 0
- end
- for e,d in pairs(displayNameTable) do
- if string.lower(command[2]) == string.lower(d) then
- itemID = e
- end
- end
- for f,g in pairs(craftTable) do
- if string.lower(command[2]) == string.lower(g) then
- canCraft = true
- end
- end
- item = nameTable[itemID]
- meta = metaTable[itemID]
- if amount > tonumber(amountTable[itemID]) and canCraft == true then
- chatbox.say("There is currently only "..amountTable[itemID].." in the system, would you like me to craft the amount missing?", range, false, name)
- ev, pl, m = os.pullEvent("chat")
- if m == string.lower("yes") then
- bridge.craft(item.." "..meta,(amount-tonumber(amountTable[itemID]) + 1))
- os.pullEvent("craftingComplete")
- print("done craft")
- end
- end
- --print(amount,item,meta,player)
- bridge.retrieve(item.." "..meta, amount, giveDirection)
- chatbox.say("Giving "..amount.." of "..command[2].." to "..player..".", range, false , name)
- --speaker.speak("Giving "..command[2].." of "..command[1].." to "..player..".", range, lang)
- --[[for k,v in pairs(nameTable) do
- nameTable[k] = nil
- displayNameTable[k] = nil
- metaTable[k] = nil
- amountTable[k] = nil
- end ]]
- canCraft = false
- elseif (string.lower(command[1]) == "amount" ) then
- getItems()
- for e,d in pairs(displayNameTable) do
- if string.lower(command[2]) == string.lower(d) then
- itemID = e
- end
- end
- item = nameTable[itemID]
- meta = metaTable[itemID]
- howMany = amountTable[itemID]
- chatbox.say("There is currently "..howMany.." of "..command[2].." currently in the system", range, false , name)
- elseif (string.lower(command[1]) == "craft" ) then
- getItems()
- if tonumber(num[1]) ~= nil then
- amount = tonumber(num[1])
- else amount = 64
- end
- if num[2] ~= nil then
- meta = num[2]
- else meta = 0
- end
- for e,d in pairs(displayNameTable) do
- if string.lower(command[2]) == string.lower(d) then
- itemID = e
- end
- end
- item = nameTable[itemID]
- meta = metaTable[itemID]
- --print(amount,item,meta,player)
- bridge.craft(item.." "..meta, amount)
- chatbox.say("I am crafting "..command[2], range, false , name)
- --speaker.speak("Giving "..command[2].." of "..command[1].." to "..player..".", range, lang)
- --[[for k,v in pairs(nameTable) do
- nameTable[k] = nil
- displayNameTable[k] = nil
- metaTable[k] = nil
- amountTable[k] = nil
- end ]]
- 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
- chatbox.say("I'm sorry "..player..", I'm afraid I can't do that")
- elseif (string.lower(command[1]) == "christmas") then
- giveDirection = "east"
- if (string.lower(command[2]) == "mtlballer") then
- redstoneColor = "colors.blue"
- giveDirection = "north"
- elseif (string.lower(command[2]) == "voxelgamer") then
- redstoneColor = "colors.red"
- giveDirection = "north"
- elseif (string.lower(command[2]) == "ov104") then
- redstoneColor = "colors.yellow"
- giveDirection = "east"
- elseif (string.lower(command[2]) == "asilentcrow") then
- redstoneColor = "colors.green"
- giveDirection = "west"
- end
- bridge.retrieve("minecraft:coal",5000,giveDirection)
- elseif (string.lower(command[1]) == "clever") then
- if command[2] == nil then
- cleverness = not cleverness
- if cleverness == true then
- chatbox.say("Powering Up!", range, false, name)
- else
- chatbox.say("I'll be back", range, false, name)
- end
- elseif (string.lower(command[2]) == "on" ) then
- cleverness = true
- chatbox.say("Powering Up!", range, false, name)
- elseif (string.lower(command[2]) == "off") then
- cleverness = false
- chatbox.say("I'll be back", range, false, name)
- end
- else
- if cleverness == true then
- if message ~= nil then
- response = bot:send(message)
- if response ~= nil then
- chatbox.say(response, range, false, name)
- end
- end
- end
- end
- end
- local function monitor()
- while true do
- local event, player, message = os.pullEvent("chat")
- local command = {}
- local counter = 1
- local num = {}
- local numC = 1
- for part in message:gmatch("%S+") do
- command[counter] = part
- counter = counter + 1
- end
- if string.lower(command[1]) == "give" then
- if string.find(message, "%d") == nil then
- message = message.." 64"
- end
- lastSpace = string.find(message, "%s%d")
- lastSpace = lastSpace -1
- item = string.sub(message, 6, lastSpace)
- command[2] = item
- rMessage = string.reverse(message)
- lastSpacenum = string.find(rMessage, "%d%s")
- lastSpacenum = lastSpacenum
- test = string.reverse(string.sub(rMessage, 0, lastSpacenum))
- num[1] = tonumber(test)
- elseif string.lower(command[1]) == "craft" then
- if string.find(message, "%d") == nil then
- message = message.." 64"
- end
- lastSpace = string.find(message, "%s%d")
- lastSpace = lastSpace -1
- item = string.sub(message, 7, lastSpace)
- command[2] = item
- rMessage = string.reverse(message)
- lastSpacenum = string.find(rMessage, "%d%s")
- lastSpacenum = lastSpacenum
- test = string.reverse(string.sub(rMessage, 0, lastSpacenum))
- num[1] = tonumber(test)
- elseif string.lower(command[1]) == "amount" then
- if string.find(message, "%d") == nil then
- message = message.." 64"
- end
- lastSpace = string.find(message, "%s%d")
- lastSpace = lastSpace -1
- item = string.sub(message, 8, lastSpace)
- command[2] = item
- rMessage = string.reverse(message)
- lastSpacenum = string.find(rMessage, "%d%s")
- lastSpacenum = lastSpacenum
- test = string.reverse(string.sub(rMessage, 0, lastSpacenum))
- num[1] = tonumber(test)
- end
- parseCommand(command, player, message, num)
- end
- end
- monitor()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement