Compare commits

..

No commits in common. "4249815c5504d3f4fd1908f6cbd955f9b81b3299" and "26f6e7e9c25b182927094637f58eb1a6cbd19776" have entirely different histories.

View file

@ -59,7 +59,6 @@ global.wsConnections = [];
var roomList = []; var roomList = [];
// IEM WebSocket // IEM WebSocket
app.ws('/iem', (ws, req) => { app.ws('/iem', (ws, req) => {
req.ip = process.env.REALIP ? req.headers[process.env.REALIP.toLowerCase()] : req.ip;
console.log(`connection from ${req.ip}`); console.log(`connection from ${req.ip}`);
const hostname = process.env.HOST_OVERRIDE || os.hostname(); const hostname = process.env.HOST_OVERRIDE || os.hostname();
@ -91,20 +90,7 @@ app.ws('/iem', (ws, req) => {
}); });
try { try {
ws.on('message', (msg) => { ws.on('message', (msg) => {
let data; const data = JSON.parse(msg);
try {
data = JSON.parse(msg);
} catch (error) {
ws.send(JSON.stringify({
"type": "internal-response",
"code": 400,
"data": {
"error": "Invalid JSON format."
}
}));
console.log(`${colors.red("[ERROR]")} Invalid JSON format from ${req.ip}: ${msg}`);
return;
}
if (!data.type) return ws.send(JSON.stringify({ if (!data.type) return ws.send(JSON.stringify({
"type": "internal-response", "type": "internal-response",
"code": 400, "code": 400,
@ -205,15 +191,6 @@ app.ws('/iem', (ws, req) => {
})); }));
} }
break; break;
case "ping":
ws.send(JSON.stringify({
"type": "internal-response",
"code": 200,
"data": {
"message": "pong"
}
}));
break;
default: default:
ws.send(JSON.stringify({ ws.send(JSON.stringify({
"type": "internal-response", "type": "internal-response",
@ -574,6 +551,25 @@ xmpp.reconnect.on("reconnected", () => {
}); });
}) })
const createDiscordEmbed = (data) => {
const embed = {
description: `<t:${Math.floor(data.timestamp / 1000)}:T> <t:${Math.floor(data.timestamp / 1000)}:R> ${data.body}`,
color: parseInt(config.priorityColors[data.event.priority].replace("#", ""), 16) || 0x000000,
timestamp: new Date(data.timestamp).toISOString(),
footer: {
text: `Station: ${data.station} PID: ${data.raw} Channel: ${data.channel}`
}
};
if (data.image) {
embed.image = {
url: data.image
};
}
return embed;
};
xmpp.on("online", async (address) => { xmpp.on("online", async (address) => {