-- send_webhook.lua (OpenComputers/OpenOS)
local internet = require("internet")
local component = require("component")
local computer = require("computer")
local io = require("io")
-- Replace with your webhook URL (keep this secret)
local webhook_url = "https://discord.com/api/webhooks/1431962412113727633/Vg0dWkp6Y94tmyXZAo_P_1LiLMuOJNWSbOcYQzwuyhA-fZps7BXdPtZGefSU2bIp1Oer"
-- Simple JSON escaper (handles quotes, backslashes and control chars)
local function json_escape(s)
s = tostring(s)
s = s:gsub("\\", "\\\\")
s = s:gsub('"', '\\"')
s = s:gsub("\b", "\\b")
s = s:gsub("\f", "\\f")
s = s:gsub("\n", "\\n")
s = s:gsub("\r", "\\r")
s = s:gsub("\t", "\\t")
-- other control chars -> \u00XX
s = s:gsub("([%z\1-\31])", function(c)
return string.format("\\u%04x", string.byte(c))
end)
return s
end
-- Builds a minimal JSON payload for Discord webhook: { "username": "...", "content": "..." }
local function build_payload(username, content)
username = username or "OC Bot"
content = content or ""
return string.format('{"username":"%s","content":"%s"}', json_escape(username), json_escape(content))
end
-- Post to webhook and return response body (or nil + error)
local function post_webhook(url, username, content)
if not url then return nil, "no url provided" end
local body = build_payload(username, content)
local headers = {
["Content-Type"] = "application/json",
["Content-Length"] = tostring(#body),
["User-Agent"] = "OpenComputers-Webhook/1.0"
}
local ok, handle_or_err = pcall(internet.request, url, body, headers)
if not ok or not handle_or_err then
return nil, "request failed to start: " .. tostring(handle_or_err)
end
local handle = handle_or_err
local resp = ""
-- read the iterator returned by internet.request synchronously
for chunk in handle do
resp = resp .. tostring(chunk)
end
return resp
end
local f = io.open("/home/auth", "r")
local content = f:read("a")
f:close()
local resp, err = post_webhook(webhook_url, "OC server-1", "Login program started successfully. Boot auth status: ".. content)
if content == "False" then
computer.shutdown("True")
end