Advertisement
Guest User

Untitled

a guest
Apr 6th, 2015
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1. local component = require("component")
  2. local colors = require("colors")
  3. local sides = require("sides")
  4. local event = require("event")
  5. local rs = component.redstone
  6. local cb = component.chat_box
  7.  
  8. local messages = {
  9.   ["lights"] = {
  10.     --Syntax: ["keyword"] = {function, all, other, arguments}
  11.     ["on"] = {rs.setBundledOutput, sides.back, colors.cyan, 15},
  12.     ["off"] = {rs.setBundledOutput, sides.back, colors.cyan, 0}
  13.   },
  14.   ["door"] = {
  15.     ["open"] = {rs.setBundledOutput, sides.back, colors.magenta, 15},
  16.     ["close"] = {rs.setBundledOutput, sides.back, colors.magenta, 0}
  17.   }
  18. }
  19.  
  20. local function getFunction(tbl, msg)
  21.   if tbl[1] and type(tbl[1]) ~= "table" then
  22.     return tbl
  23.   end
  24.   for i,j in pairs(tbl) do
  25.     if type(i) == "string" then
  26.       if msg:find(i) and type(j) == "table" then
  27.         return getFunction(j, msg)
  28.       end
  29.     end
  30.   end
  31. end
  32.  
  33. local function parseMessage(msg)
  34.   local fnc = getFunction(messages, msg)
  35.   if not fnc then return false, "no command found" end
  36.   return pcall(table.unpack(fnc))
  37. end
  38.  
  39. local _, _, user, message = event.pull("chat_message")
  40. local result, response = parseMessage(message)
  41. print(result)
  42. print(response)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement