diff --git a/src/backend.lua b/src/backend.lua index e8be02a..8bae493 100644 --- a/src/backend.lua +++ b/src/backend.lua @@ -88,7 +88,9 @@ speaker:play("error") end end - + elseif data.type == "KRISTLY-ERROR" then + logger:error("Received kristly error: " .. data.error) + return else logger:debug("Ignoring packet: " .. data.type) end @@ -165,8 +167,10 @@ transaction.from .. "` bought " .. amount .. "x " .. product.id .. " (" .. transaction.value .. "kst)" logger:debug("Running webhooks") + for _, webhook in ipairs(config.webhooks) do logger:debug("Webhook: ", webhook.type, webhook.URL) + if webhook.type == "discord" then webhooks.discord(webhook.URL, message) elseif webhook.type == "discord-modern" then diff --git a/src/init.lua b/src/init.lua index 687a72d..62604bc 100644 --- a/src/init.lua +++ b/src/init.lua @@ -50,6 +50,7 @@ end return false end + -- theme local col = { white = 0x1, orange = 0x2, magenta = 0x4, lightBlue = 0x8, yellow = 0x10, lime = 0x20, pink = 0x40, grey = 0x80, lightGrey = 0x100, cyan = 0x200, purple = 0x400, blue = 0x800, brown = 0x1000, green = 0x2000, @@ -57,17 +58,17 @@ local inferiorcol = col; inferiorcol.gray = col.grey; inferiorcol.lightGray = col.lightGrey - local result = loadLuaFile(fs.combine(sPage,"theme.lua"), { colours = col, colors = inferiorcol }) + local result = loadLuaFile(fs.combine(sPage, "theme.lua"), { colours = col, colors = inferiorcol }) if result then ctx.theme = result end -- config - result = loadLuaFile(fs.combine(sData,"config.lua")) + result = loadLuaFile(fs.combine(sData, "config.lua")) if result then ctx.config = result end -- products - result = loadLuaFile(fs.combine(sData,"products.lua")) + result = loadLuaFile(fs.combine(sData, "products.lua")) if result then ctx.products = result end @@ -80,12 +81,12 @@ }) -- Load scripts - ctx.kristly = require(fs.combine("libs","kristly")) + ctx.kristly = require(fs.combine("libs", "kristly")) ctx.utils = require("utils") ctx.logger = require("logger"):new({ debugging = settings.get("kristify.debug") }) ctx.webhooks = require("webhook") ctx.speakerLib = require("speaker") - ctx.storage = require(fs.combine("libs","inv"))(ctx.config.storage) + ctx.storage = require(fs.combine("libs", "inv"))(ctx.config.storage) return ctx end @@ -115,4 +116,6 @@ function() execFile(fs.combine(sSrc, "frontend.lua")) end -) \ No newline at end of file +) + +ctx.logger:debug("Something exited (init.lua)") diff --git a/src/libs/kristly.lua b/src/libs/kristly.lua index 4c6c29a..e685d13 100644 --- a/src/libs/kristly.lua +++ b/src/libs/kristly.lua @@ -402,15 +402,13 @@ -- Use os.queueEvent to send information back. Implement on and once later. while true do - local ok, returned = pcall(self.ws.receive(12)) -- Every 10s there should come a keepalive packet + local ok, returned = pcall(self.ws.receive, 12) -- Every 10s there should come a keepalive packet if not ok then os.queueEvent("kristly", { type = "KRISTLY-ERROR", - error = "DISCONNECTED" + error = "DISCONNECTED. " .. returned }) - - return end if returned == nil then @@ -418,11 +416,9 @@ type = "KRISTLY-ERROR", error = "NO-RESPONSE" }) - - return end - local data = textutils.unserializeJSON(res) + local data = textutils.unserializeJSON(returned) os.queueEvent("kristly", data) end