#5 replace all console.logs with debugger
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
All checks were successful
DRB Tests / drb_mocha_tests (pull_request) Successful in 32s
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "addonManager");
|
||||
import { fileURLToPath } from 'url';
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
@@ -20,9 +22,9 @@ export const loadAddons = async (nodeIo) => {
|
||||
if (addonConfig.enabled) {
|
||||
const addonIndexPath = path.join(addonsDir, addonDir.name, 'index.js');
|
||||
import(`file://${addonIndexPath}`).then(addonModule => {
|
||||
console.log("Loading addon: ", addonModule);
|
||||
log.DEBUG("Loading addon: ", addonModule);
|
||||
addonModule.initialize(nodeIo, addonConfig);
|
||||
console.log(`Addon ${addonConfig.name} loaded.`);
|
||||
log.DEBUG(`Addon ${addonConfig.name} loaded.`);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "mongoDiscordIDWrappers");
|
||||
import { insertDocument, getDocuments, connectToDatabase } from "./mongoHandler.mjs";
|
||||
|
||||
const collectionName = 'discord-ids';
|
||||
@@ -8,7 +10,7 @@ export const createDiscordID = async (discordID) => {
|
||||
const insertedId = await insertDocument(collectionName, discordID);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
console.error('Error creating Discord ID:', error);
|
||||
log.ERROR('Error creating Discord ID:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -19,7 +21,7 @@ export const getAllDiscordIDs = async () => {
|
||||
const discordIDs = await getDocuments(collectionName);
|
||||
return discordIDs;
|
||||
} catch (error) {
|
||||
console.error('Error getting all Discord IDs:', error);
|
||||
log.ERROR('Error getting all Discord IDs:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -37,7 +39,7 @@ export const getDiscordID = async (identifier) => {
|
||||
});
|
||||
return discordID;
|
||||
} catch (error) {
|
||||
console.error('Error getting Discord ID:', error);
|
||||
log.ERROR('Error getting Discord ID:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -56,10 +58,10 @@ export const updateDiscordID = async (identifier, updatedFields) => {
|
||||
{ discord_id: identifier }
|
||||
]
|
||||
}, { $set: updatedFields });
|
||||
console.log('Discord ID updated:', result.modifiedCount);
|
||||
log.INFO('Discord ID updated:', result.modifiedCount);
|
||||
return result.modifiedCount;
|
||||
} catch (error) {
|
||||
console.error('Error updating Discord ID:', error);
|
||||
log.ERROR('Error updating Discord ID:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -78,10 +80,10 @@ export const deleteDiscordID = async (identifier) => {
|
||||
{ discord_id: identifier }
|
||||
]
|
||||
});
|
||||
console.log('Discord ID deleted:', result.deletedCount);
|
||||
log.INFO('Discord ID deleted:', result.deletedCount);
|
||||
return result.deletedCount;
|
||||
} catch (error) {
|
||||
console.error('Error deleting Discord ID:', error);
|
||||
log.ERROR('Error deleting Discord ID:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "mongoFeedsWrappers");
|
||||
import {
|
||||
insertDocument,
|
||||
getDocuments,
|
||||
@@ -15,7 +17,7 @@ import {
|
||||
const insertedId = await insertDocument(feedCollectionName, feed);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
console.error('Error creating feed:', error);
|
||||
log.ERROR('Error creating feed:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -26,7 +28,7 @@ import {
|
||||
const feeds = await getDocuments(feedCollectionName);
|
||||
return feeds;
|
||||
} catch (error) {
|
||||
console.error('Error getting all feeds:', error);
|
||||
log.ERROR('Error getting all feeds:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -37,7 +39,7 @@ import {
|
||||
const feed = await getDocumentByField(feedCollectionName, 'link', link);
|
||||
return feed;
|
||||
} catch (error) {
|
||||
console.error('Error getting feed by link:', error);
|
||||
log.ERROR('Error getting feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -48,7 +50,7 @@ import {
|
||||
const modifiedCount = await updateDocumentByField(feedCollectionName, 'link', link, updatedFields);
|
||||
return modifiedCount;
|
||||
} catch (error) {
|
||||
console.error('Error updating feed by link:', error);
|
||||
log.ERROR('Error updating feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -59,7 +61,7 @@ import {
|
||||
const deletedCount = await deleteDocumentByField(feedCollectionName, 'link', link);
|
||||
return deletedCount;
|
||||
} catch (error) {
|
||||
console.error('Error deleting feed by link:', error);
|
||||
log.ERROR('Error deleting feed by link:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -70,7 +72,7 @@ import {
|
||||
const insertedId = await insertDocument(postCollectionName, post);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
console.error('Error creating post:', error);
|
||||
log.ERROR('Error creating post:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -81,7 +83,7 @@ import {
|
||||
const post = await getDocumentByField(postCollectionName, 'postId', postId);
|
||||
return post;
|
||||
} catch (error) {
|
||||
console.error('Error getting post by postId:', error);
|
||||
log.ERROR('Error getting post by postId:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "mongoNodesWrappers");
|
||||
import { insertDocument, getDocuments, connectToDatabase } from "./mongoHandler.mjs";
|
||||
|
||||
const collectionName = 'nodes';
|
||||
@@ -8,7 +10,7 @@ export const createNode = async (node) => {
|
||||
const insertedId = await insertDocument(collectionName, node);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
console.error('Error creating node:', error);
|
||||
log.ERROR('Error creating node:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -19,7 +21,7 @@ export const getAllNodes = async () => {
|
||||
const nodes = await getDocuments(collectionName);
|
||||
return nodes;
|
||||
} catch (error) {
|
||||
console.error('Error getting all nodes:', error);
|
||||
log.ERROR('Error getting all nodes:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -32,7 +34,7 @@ export const getNodeByNuid = async (nuid) => {
|
||||
const node = await collection.findOne({ nuid });
|
||||
return node;
|
||||
} catch (error) {
|
||||
console.error('Error getting node by NUID:', error);
|
||||
log.ERROR('Error getting node by NUID:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -46,10 +48,10 @@ export const updateNodeByNuid = async (nuid, updatedFields) => {
|
||||
try {
|
||||
const collection = db.db().collection(collectionName);
|
||||
const result = await collection.updateOne({ nuid }, { $set: updatedFields });
|
||||
console.log('Node updated:', result.modifiedCount);
|
||||
log.INFO('Node updated:', result.modifiedCount);
|
||||
return result.modifiedCount;
|
||||
} catch (error) {
|
||||
console.error('Error updating node by NUID:', error);
|
||||
log.ERROR('Error updating node by NUID:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -63,10 +65,10 @@ export const deleteNodeByNuid = async (nuid) => {
|
||||
try {
|
||||
const collection = db.db().collection(collectionName);
|
||||
const result = await collection.deleteOne({ nuid });
|
||||
console.log('Node deleted:', result.deletedCount);
|
||||
log.INFO('Node deleted:', result.deletedCount);
|
||||
return result.deletedCount;
|
||||
} catch (error) {
|
||||
console.error('Error deleting node by NUID:', error);
|
||||
log.ERROR('Error deleting node by NUID:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "mongoSystemsWrappers");
|
||||
import { insertDocument, getDocuments, connectToDatabase } from "./mongoHandler.mjs";
|
||||
|
||||
const collectionName = 'radio-systems';
|
||||
@@ -21,7 +23,7 @@ export const createSystem = async (name, system, nuid) => {
|
||||
const insertedId = await insertDocument(collectionName, system);
|
||||
return insertedId;
|
||||
} catch (error) {
|
||||
console.error('Error creating system:', error);
|
||||
log.ERROR('Error creating system:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -32,7 +34,7 @@ export const getAllSystems = async () => {
|
||||
const systems = await getDocuments(collectionName);
|
||||
return systems;
|
||||
} catch (error) {
|
||||
console.error('Error getting all systems:', error);
|
||||
log.ERROR('Error getting all systems:', error);
|
||||
throw error;
|
||||
}
|
||||
};
|
||||
@@ -45,7 +47,7 @@ export const getSystemByName = async (name) => {
|
||||
const system = await collection.findOne({ name });
|
||||
return system;
|
||||
} catch (error) {
|
||||
console.error('Error getting system by name:', error);
|
||||
log.ERROR('Error getting system by name:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -65,7 +67,7 @@ export const getSystemsByNuid = async (nuid) => {
|
||||
|
||||
return systems;
|
||||
} catch (error) {
|
||||
console.error('Error finding entries:', error);
|
||||
log.ERROR('Error finding entries:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -82,10 +84,10 @@ export const updateSystemByName = async (name, updatedSystem) => {
|
||||
try {
|
||||
const collection = db.db().collection(collectionName);
|
||||
const result = await collection.updateOne({ name }, { $set: updatedSystem });
|
||||
console.log('System updated:', result.modifiedCount);
|
||||
log.INFO('System updated:', result.modifiedCount);
|
||||
return result.modifiedCount;
|
||||
} catch (error) {
|
||||
console.error('Error updating system by name:', error);
|
||||
log.ERROR('Error updating system by name:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
@@ -99,10 +101,10 @@ export const deleteSystemByName = async (name) => {
|
||||
try {
|
||||
const collection = db.db().collection(collectionName);
|
||||
const result = await collection.deleteOne({ name });
|
||||
console.log('System deleted:', result.deletedCount);
|
||||
log.INFO('System deleted:', result.deletedCount);
|
||||
return result.deletedCount;
|
||||
} catch (error) {
|
||||
console.error('Error deleting system by name:', error);
|
||||
log.ERROR('Error deleting system by name:', error);
|
||||
throw error;
|
||||
} finally {
|
||||
// Close the connection
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "socketServer");
|
||||
import express from 'express';
|
||||
import { createServer } from 'node:http';
|
||||
import { Server } from 'socket.io';
|
||||
@@ -15,7 +17,7 @@ app.get('/', (req, res) => {
|
||||
});
|
||||
|
||||
nodeIo.on('connection', (socket) => {
|
||||
console.log('a user connected', socket.id);
|
||||
log.INFO('a user connected', socket.id);
|
||||
|
||||
socket.on('node-login', async (data) => {
|
||||
await nodeLoginWrapper(data, socket);
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { DebugBuilder } from "../modules/debugger.mjs";
|
||||
const log = new DebugBuilder("server", "socketServerWrappers");
|
||||
import { createNode, getNodeByNuid, updateNodeByNuid } from "./mongo-wrappers/mongoNodesWrappers.mjs"
|
||||
import { createSystem, getSystemByName, updateSystemByName, getSystemsByNuid, deleteSystemByName } from "./mongo-wrappers/mongoSystemsWrappers.mjs"
|
||||
|
||||
@@ -22,17 +24,16 @@ const sendNodeCommand = async (socket, command, data) => {
|
||||
* @returns {any}
|
||||
*/
|
||||
export const nodeLoginWrapper = async (data, socket) => {
|
||||
console.log(`Login requested from node: ${data.nuid}`, data);
|
||||
log.INFO(`Login requested from node: ${data.nuid}`, data);
|
||||
// Check to see if node exists
|
||||
var node = await getNodeByNuid(data.nuid);
|
||||
console.log("After grabbing", node);
|
||||
var node = await getNodeByNuid(data.nuid);
|
||||
if (!node) {
|
||||
const insertedId = await createNode(data);
|
||||
console.log("Added new node to the database:", insertedId);
|
||||
log.DEBUG("Added new node to the database:", insertedId);
|
||||
} else {
|
||||
// Check for updates
|
||||
const updatedNode = await updateNodeByNuid(data.nuid, data)
|
||||
console.log("Updated node:", updatedNode);
|
||||
log.DEBUG("Updated node:", updatedNode);
|
||||
}
|
||||
|
||||
node = await getNodeByNuid(data.nuid);
|
||||
@@ -59,7 +60,7 @@ export const nodeDisconnectWrapper = async (socketId) => {
|
||||
* @returns {any}
|
||||
*/
|
||||
export const nodeUpdateWrapper = async (nodeData) => {
|
||||
console.log("Data update sent by node: ", nodeData);
|
||||
log.DEBUG("Data update sent by node: ", nodeData);
|
||||
const updateResults = await updateNodeByNuid(nodeData.nuid, nodeData);
|
||||
return;
|
||||
}
|
||||
@@ -70,10 +71,10 @@ export const nodeUpdateWrapper = async (nodeData) => {
|
||||
* @param {object} nearbySystems The nearby systems object passed from the node to be updated
|
||||
*/
|
||||
export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
|
||||
console.log("System updates sent by node: ", nuid, nearbySystems);
|
||||
log.DEBUG("System updates sent by node: ", nuid, nearbySystems);
|
||||
// Check to see if the node removed any systems
|
||||
const existingSystems = await getSystemsByNuid(nuid);
|
||||
console.log("Existing systems:", existingSystems);
|
||||
log.DEBUG("Existing systems:", existingSystems);
|
||||
if (existingSystems !== nearbySystems) {
|
||||
for (const existingSystem of existingSystems) {
|
||||
if (existingSystem.name in nearbySystems) {
|
||||
@@ -81,17 +82,17 @@ export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
|
||||
continue;
|
||||
}
|
||||
|
||||
console.log("System exists that was not given by node", existingSystem);
|
||||
log.DEBUG("System exists that was not given by node", existingSystem);
|
||||
// Check if this node was the only node on this system
|
||||
if (existingSystem.nodes.filter(node => node !== nuid).length === 0) {
|
||||
// Remove the system if so
|
||||
console.log("Given node was the only node on this system, removing the system...");
|
||||
log.INFO("Given node was the only node on this system, removing the system...");
|
||||
await deleteSystemByName(existingSystem.name);
|
||||
} else {
|
||||
// Remove the node from the array if there are other nodes with this system
|
||||
console.log("Other nodes found on this system, removing the given NUID");
|
||||
log.INFO("Other nodes found on this system, removing the given NUID");
|
||||
existingSystem.nodes = existingSystem.nodes.filter(node => node !== nuid);
|
||||
console.log(existingSystem);
|
||||
log.DEBUG(existingSystem);
|
||||
await updateSystemByName(existingSystem.name, existingSystem);
|
||||
}
|
||||
}
|
||||
@@ -111,7 +112,7 @@ export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
|
||||
existingSystem.nodes.push(nuid);
|
||||
// Update the system with the added node
|
||||
const updateResults = await updateSystemByName(nearbySystem, existingSystem);
|
||||
if (updateResults) console.log("System updated", nearbySystem);
|
||||
if (updateResults) log.INFO("System updated", nearbySystem);
|
||||
}
|
||||
} else {
|
||||
// The systems are not the same
|
||||
@@ -125,13 +126,13 @@ export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
|
||||
|
||||
// Update the system with the added node
|
||||
const updateResults = await updateSystemByName(nearbySystem, nearbySystems[nearbySystem]);
|
||||
if (updateResults) console.log("System updated", nearbySystem);
|
||||
if (updateResults) log.INFO("System updated", nearbySystem);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// Create a new system
|
||||
const newSystem = await createSystem(nearbySystem, nearbySystems[nearbySystem], nuid);
|
||||
console.log("New system created", nearbySystem, newSystem);
|
||||
log.INFO("New system created", nearbySystem, newSystem);
|
||||
}
|
||||
}
|
||||
return;
|
||||
@@ -146,7 +147,7 @@ export const nearbySystemsUpdateWraper = async (nuid, nearbySystems) => {
|
||||
export const getSocketIdByNuid = async (nodeIo, nuid) => {
|
||||
const openSockets = await nodeIo.allSockets();
|
||||
for (const openSocketId of openSockets) {
|
||||
console.log(openSockets)
|
||||
log.DEBUG(openSockets)
|
||||
const openSocket = await nodeIo.sockets.sockets.get(openSocketId);
|
||||
if (openSocket.node.nuid == nuid)
|
||||
return openSocket;
|
||||
@@ -171,10 +172,10 @@ export const getAllSocketsConnectedToVC = async (nodeIo, guildId) => {
|
||||
await new Promise((res) => {
|
||||
openSocket.emit('node-check-connected-status', guildId, (status) => {
|
||||
if (status) {
|
||||
console.log("Socket is connected to VC:", openSocket.node.name, status);
|
||||
log.INFO("Socket is connected to VC:", openSocket.node.name, status);
|
||||
socketsConnectedToVC.push(openSocket);
|
||||
} else {
|
||||
console.log("Socket is NOT connected to VC:", openSocket.node.name);
|
||||
log.INFO("Socket is NOT connected to VC:", openSocket.node.name);
|
||||
}
|
||||
res();
|
||||
})
|
||||
@@ -196,10 +197,10 @@ export const checkIfNodeHasOpenDiscordClient = async (openSocket) => {
|
||||
await new Promise((res) => {
|
||||
openSocket.emit('node-check-discord-open-client', (status) => {
|
||||
if (status) {
|
||||
console.log("Socket has an open discord client:", openSocket.node.name, status);
|
||||
log.INFO("Socket has an open discord client:", openSocket.node.name, status);
|
||||
hasOpenDiscordClient = true;
|
||||
} else {
|
||||
console.log("Socket does NOT have an open discord client:", openSocket.node.name);
|
||||
log.INFO("Socket does NOT have an open discord client:", openSocket.node.name);
|
||||
}
|
||||
res();
|
||||
})
|
||||
@@ -217,10 +218,10 @@ export const getNodeCurrentListeningSystem = async (openSocket) => {
|
||||
await new Promise((res) => {
|
||||
openSocket.emit('node-check-current-system', (system) => {
|
||||
if (system) {
|
||||
console.log("Socket is listening to system:", openSocket.node.name, system);
|
||||
log.INFO("Socket is listening to system:", openSocket.node.name, system);
|
||||
currentSystem = system;
|
||||
} else {
|
||||
console.log("Socket is not currently listening to a system:", openSocket.node.name);
|
||||
log.INFO("Socket is not currently listening to a system:", openSocket.node.name);
|
||||
}
|
||||
res();
|
||||
})
|
||||
@@ -307,9 +308,9 @@ export const requestBotLeaveServer = async (socket, guildId) => {
|
||||
export const requestNodeUpdate = async (socket) => {
|
||||
await sendNodeCommand(socket, 'node-update', (status) => {
|
||||
if (status) {
|
||||
console.log("Node is out of date, updating now", socket.node.name);
|
||||
log.INFO("Node is out of date, updating now", socket.node.name);
|
||||
} else {
|
||||
console.log("Node is up to date", socket.node.name);
|
||||
log.INFO("Node is up to date", socket.node.name);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user