You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

25 lines
821 B

1 year ago
local chat = peripheral.find("chatBox")
local socket = http.websocket(settings.get("bridge_url"), { ["X-Token"] = settings.get("bridge_token") })
while true do
local eventData = os.pullEvent()
local event = eventData[1]
if event == "websocket_message" then
local data = textutils.unserializeJSON(eventData[3])
chat.sendMessage(data.message, data.user)
elseif event == "chat" then
if not eventData[5] then
local username = eventData[2]
local message = eventData[3]
local uuid = eventData[4]
local serialized = textutils.serialiseJSON({
user = username,
message = message,
user_id = string.gsub(uuid, "-", "")
})
socket.send(serialized)
end
end
end