2023-06-15 21:36:05 +01:00
|
|
|
local net = require("@lune/net")
|
2023-06-28 09:38:46 +01:00
|
|
|
local serde = require("@lune/serde")
|
2023-06-15 21:36:05 +01:00
|
|
|
local task = require("@lune/task")
|
|
|
|
|
2023-06-28 09:38:46 +01:00
|
|
|
-- We're going to use Discord's WebSocket gateway server
|
|
|
|
-- for testing wss - it does not require auth, and this test
|
|
|
|
-- only exists to ensure wss (WebSockets with TLS) works correctly
|
2023-06-15 21:36:05 +01:00
|
|
|
local socket = net.socket("wss://gateway.discord.gg/?v=10&encoding=json")
|
|
|
|
|
|
|
|
while not socket.closeCode do
|
2024-10-16 21:00:33 +01:00
|
|
|
local response = socket:next()
|
2023-06-15 21:36:05 +01:00
|
|
|
|
2023-06-28 09:38:46 +01:00
|
|
|
if response then
|
|
|
|
local decodeSuccess, decodeMessage = pcall(serde.decode, "json" :: "json", response)
|
|
|
|
if not decodeSuccess then
|
|
|
|
error(
|
|
|
|
string.format(
|
|
|
|
"Discord API did not respond with valid JSON!\n%s",
|
|
|
|
tostring(decodeMessage)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
end
|
2023-06-15 21:36:05 +01:00
|
|
|
|
2023-06-28 09:38:46 +01:00
|
|
|
-- Close the connection after a second with the success close code
|
|
|
|
task.wait(1)
|
2024-10-16 21:00:33 +01:00
|
|
|
socket:close(1000)
|
2023-06-28 09:38:46 +01:00
|
|
|
end
|
|
|
|
end
|