Add random string to messages to help with debug!
Some checks are pending
ptero-push / build (push) Waiting to run
Some checks are pending
ptero-push / build (push) Waiting to run
This commit is contained in:
parent
6c9465eb50
commit
5ab763cde8
20
index.js
20
index.js
|
@ -15,7 +15,7 @@ const colors = require("colors");
|
|||
const sqlite3 = require("sqlite3").verbose();
|
||||
const WebSocket = require('ws');
|
||||
const events = require("./data/events.json");
|
||||
|
||||
const path = require("path");
|
||||
satMessages = {};
|
||||
|
||||
// Setup Discord
|
||||
|
@ -357,7 +357,7 @@ Image and product text are optional, but if they exist, they will be in the data
|
|||
|
||||
var sent = {}
|
||||
|
||||
const handleDiscord = function (data) {
|
||||
const handleDiscord = function (data, randStr) {
|
||||
const rawBody = data.data.body;
|
||||
const text = data.data.productText;
|
||||
const product_id_raw = data.data.raw
|
||||
|
@ -374,7 +374,7 @@ const handleDiscord = function (data) {
|
|||
color: parseInt(config.priorityColors[evt.priority].replace("#", ""), 16) || 0x000000,
|
||||
timestamp: product_id.timestamp,
|
||||
footer: {
|
||||
text: `Station: ${product_id.station} PID: ${product_id_raw} Channel: ${fromChannel}`
|
||||
text: `${randStr} Station: ${product_id.station} PID: ${product_id_raw} Channel: ${fromChannel}`
|
||||
}
|
||||
}
|
||||
if (data.data.image) {
|
||||
|
@ -593,11 +593,22 @@ function connectWebSocket() {
|
|||
});
|
||||
|
||||
ws.on('message', (rawData) => {
|
||||
// Save copy of rawData for debugging to event-logs/year/month/dat/random6charstring-unixtimestamp.json
|
||||
const timestamp = new Date().toISOString().replace(/:/g, '-');
|
||||
const randomString = generateRandomString({ lower: true, upper: true, number: true }, 6);
|
||||
const logDir = path.join(__dirname, "event-logs", timestamp.substring(0, 4), timestamp.substring(5, 7), timestamp.substring(8, 10));
|
||||
if (!fs.existsSync(logDir)) {
|
||||
fs.mkdirSync(logDir, { recursive: true });
|
||||
}
|
||||
const logFile = path.join(logDir, `${randomString}-${Date.now()}.json`);
|
||||
fs.writeFileSync(logFile, rawData);
|
||||
|
||||
try {
|
||||
const data = JSON.parse(rawData);
|
||||
|
||||
switch (data.type) {
|
||||
case "iem-message":
|
||||
handleDiscord(data);
|
||||
handleDiscord(data, randomString);
|
||||
break;
|
||||
|
||||
case "internal-response":
|
||||
|
@ -656,6 +667,7 @@ discord.on('ready', async () => {
|
|||
|
||||
// Do slash command stuff
|
||||
commands = require("./data/commands.json");
|
||||
|
||||
// Add dynamic commands (based on datas files)
|
||||
satCommand = {
|
||||
"name": "satellite",
|
||||
|
|
Loading…
Reference in a new issue