SHOW:
|
|
- or go back to the newest paste.
1 | local component = require("component") | |
2 | local colors = require("colors") | |
3 | local sides = require("sides") | |
4 | local event = require("event") | |
5 | ||
6 | local rs = component.redstone | |
7 | local cb = component.chat_box | |
8 | local cl = component.colorful_lamp | |
9 | local de = component.draconic_storage | |
10 | - | ["off"] = {rs.setBundledOutput, sides.back, colors.cyan, 0} |
10 | + | local ni = component.notification_interface -- TODO: Correct component name |
11 | local db = component.debug | |
12 | local ws = component.world_sensor -- TODO: Correct this one too | |
13 | ||
14 | ||
15 | ||
16 | - | } |
16 | + | -- ChatBox init |
17 | cb.setName("Dave") | |
18 | ||
19 | if cb.getDistance() < 32768 then | |
20 | - | if msg:find(i) then |
20 | + | cb.setDistance(32768) |
21 | - | if type(j) == "table" then |
21 | + | |
22 | - | if j[1] and type(j[1]) ~= "table" then |
22 | + | |
23 | - | return j |
23 | + | local function rgbto15(r,g,b) |
24 | - | end |
24 | + | return (b%32)+((g%32)*32)+((r%32)*1024) |
25 | end | |
26 | ||
27 | local function round(num, idp) | |
28 | local mult = 10^(idp or 0) | |
29 | return math.floor(num * mult + 0.5) / mult | |
30 | end | |
31 | ||
32 | - | return pcall(table.unpack(getFunction(messages, msg))) |
32 | + | |
33 | ||
34 | ["lights"] = { | |
35 | - | local testmsg = "Please turn the lights on" |
35 | + | |
36 | - | local result, response = parseMessage(testmsg) |
36 | + | |
37 | -- ["on"] = {rs.setBundledOutput, sides.back, colors.orange, 15}, | |
38 | - | print(response) |
38 | + | ["off"] = {rs.setBundledOutput, sides.back, colors.cyan, 0}, |
39 | -- ["off"] = {rs.setBundledOutput, sides.back, colors.orange, 0} | |
40 | }, | |
41 | ||
42 | ["door"] = { | |
43 | ["open"] = {rs.setBundledOutput, sides.back, colors.magenta, 15}, | |
44 | ["close"] = {rs.setBundledOutput, sides.back, colors.magenta, 0} | |
45 | }, | |
46 | ||
47 | ["all machines"] = { | |
48 | ["on"] = {cl.setLampColor, rgbto15(0,255,0)}, | |
49 | ["off"] = {cl.setLampColor, rgbto15(255,0,0)} | |
50 | }, | |
51 | ||
52 | ["core"] = { | |
53 | ["current"] = {cb.say, tostring(de.getEnergyStored())}, | |
54 | ["max"] = {cb.say, tostring(de.getMaxEnergyStored())} | |
55 | } | |
56 | ||
57 | ["reactor"] = { | |
58 | ["fuel"] = {} | |
59 | } | |
60 | ||
61 | } | |
62 | ||
63 | ||
64 | local function getFunction(tbl, msg) | |
65 | if tbl[1] then | |
66 | return tbl | |
67 | end | |
68 | for i,j in pairs(tbl) do | |
69 | if type(i) == "string" then | |
70 | print(i) | |
71 | if msg:find(i) and type(j) == "table" then | |
72 | return getFunction(j, msg) | |
73 | end | |
74 | end | |
75 | end | |
76 | end | |
77 | ||
78 | local function parseMessage(msg) | |
79 | local fnc = getFunction(messages, msg) | |
80 | if not fnc then return false, "no command found" end | |
81 | return pcall(table.unpack(fnc)) | |
82 | end | |
83 | ||
84 | while true do | |
85 | local _, _, user, message = event.pull("chat_message") | |
86 | local result, response = parseMessage(message:lower()) | |
87 | print(result) | |
88 | print(response) | |
89 | end |