Working on #9
- Can join and leave from voice channels - Will check to make sure that the bot is in a given system or no system before joining - Cleaned up the socket client with wrappers - Added a new module to handle subprocesses for the client - Beginning workings on OP25 handler - Added OP25 config object generator with config exporter
This commit is contained in:
66
client/modules/subprocessHandler.mjs
Normal file
66
client/modules/subprocessHandler.mjs
Normal file
@@ -0,0 +1,66 @@
|
||||
import { spawn } from "child_process";
|
||||
|
||||
/**
|
||||
* Object to store references to spawned processes.
|
||||
* @type {Object.<string, import('child_process').ChildProcess>}
|
||||
*/
|
||||
const runningProcesses = {};
|
||||
|
||||
/**
|
||||
* Launches a new process if it's not already running.
|
||||
* @param {string} processName - The name of the process to launch.
|
||||
* @param {string[]} args - The arguments to pass to the process.
|
||||
*/
|
||||
export const launchProcess = (processName, args) => {
|
||||
if (!runningProcesses[processName]) {
|
||||
const childProcess = spawn(processName, args);
|
||||
|
||||
// Store reference to the spawned process
|
||||
runningProcesses[processName] = childProcess;
|
||||
|
||||
childProcess.on('exit', (code, signal) => {
|
||||
// Remove reference to the process when it exits
|
||||
delete runningProcesses[processName];
|
||||
console.log(`${processName} process exited with code ${code} and signal ${signal}`);
|
||||
});
|
||||
|
||||
console.log(`${processName} process started.`);
|
||||
} else {
|
||||
console.log(`${processName} process is already running.`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks the status of a process.
|
||||
* @param {string} processName - The name of the process to check.
|
||||
* @returns {string} A message indicating whether the process is running or not.
|
||||
*/
|
||||
export const checkProcessStatus = (processName) => {
|
||||
const childProcess = runningProcesses[processName];
|
||||
if (childProcess) {
|
||||
// Check if the process is running
|
||||
if (!childProcess.killed) {
|
||||
return `${processName} process is running.`;
|
||||
} else {
|
||||
return `${processName} process is not running.`;
|
||||
}
|
||||
} else {
|
||||
return `${processName} process is not running.`;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kills a running process.
|
||||
* @param {string} processName - The name of the process to kill.
|
||||
*/
|
||||
export const killProcess = (processName) => {
|
||||
const childProcess = runningProcesses[processName];
|
||||
if (childProcess) {
|
||||
childProcess.kill();
|
||||
console.log(`${processName} process killed.`);
|
||||
} else {
|
||||
console.log(`${processName} process is not running.`);
|
||||
}
|
||||
}
|
||||
|
||||
export const getRunningProcesses = () => runningProcesses;
|
||||
Reference in New Issue
Block a user