Init Commit

Server
- Working init discord bot
    - Modular events and commands
    - Has access to the socket server
- Working init socket server
    - Need to work on getting access to discord bot
- Working init web server

Currently working on breaking out the init of the socket server

Client
- Working init socket client

Currently working on the discord bot to join voice channels
This commit is contained in:
Logan Cusano
2024-01-08 00:12:47 -05:00
parent 86dd058d2a
commit 4a0b1004d2
16 changed files with 2599 additions and 0 deletions

View File

@@ -0,0 +1,49 @@
import { networkInterfaces } from 'os';
import { createHash, randomBytes } from 'crypto';
/**
* Check to see if the input is a valid JSON string
*
* @param {*} str The string to check for valud JSON
* @returns {true|false}
*/
export function isJsonString (str) {
try {
JSON.parse(str);
} catch (e) {
return false;
}
return true;
}
/**
* Generate a unique ID for a given device, this will also be unique on the same device at a different time.
* @returns {string} A generated unique ID
*/
export function generateUniqueID () {
const netInterfaces = networkInterfaces();
let macAddress = '';
// Find the first non-internal MAC address
for (const key in netInterfaces) {
const iface = netInterfaces[key][0];
if (!iface.internal) {
macAddress = iface.mac;
break;
}
}
// If no non-internal MAC address is found, fallback to a random value
if (!macAddress) {
macAddress = randomBytes(6).toString('hex').toUpperCase();
}
// Use MAC address and current timestamp to create a unique ID
const timestamp = Date.now();
const uniqueID = createHash('sha256')
.update(macAddress + timestamp)
.digest('hex');
return uniqueID;
}