Compare commits
3 Commits
d0a75dc557
...
7efd0cd4f3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7efd0cd4f3 | ||
|
|
36c0ec8b13 | ||
|
|
79574e188d |
@@ -17,7 +17,8 @@ import { Client, Events, ActivityType } from 'discord.js';
|
|||||||
import prism_media from 'prism-media';
|
import prism_media from 'prism-media';
|
||||||
const { FFmpeg } = prism_media;
|
const { FFmpeg } = prism_media;
|
||||||
|
|
||||||
const device = "VoiceMeeter VAIO3 Output (VB-Audio VoiceMeeter VAIO3)", maxTransmissionGap = 500, type = "dshow";
|
// Import the DAB settings from the dynamic settings file
|
||||||
|
import {device, maxTransmissionGap, type} from './dabSettings.mjs'
|
||||||
|
|
||||||
const player = createAudioPlayer({
|
const player = createAudioPlayer({
|
||||||
behaviors: {
|
behaviors: {
|
||||||
|
|||||||
18
client/discordAudioBot/dabSettings.mjs
Normal file
18
client/discordAudioBot/dabSettings.mjs
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { executeCommand } from '../modules/cliHandler.mjs';
|
||||||
|
import { extractValue } from '../modules/baseUtils.mjs';
|
||||||
|
import os from 'os';
|
||||||
|
|
||||||
|
// Defaults to Windows values for testing
|
||||||
|
let device = "VoiceMeeter VAIO3 Output (VB-Audio VoiceMeeter VAIO3)";
|
||||||
|
let maxTransmissionGap = 500;
|
||||||
|
let type = "dshow";
|
||||||
|
|
||||||
|
// Set Linux values for use in production
|
||||||
|
if (os.platform() === 'linux') {
|
||||||
|
await executeCommand("pactl", ['list', 'short', 'sources']).then(cliOutput => {
|
||||||
|
device = extractValue(cliOutput, '(?:\d[ ]{4,12}(.+?)[ ]{4,12}(?:.+?[ ]{4,12}){2,4}RUNNING)')
|
||||||
|
});
|
||||||
|
type = "pulse"; // Replace with appropriate type for Linux
|
||||||
|
}
|
||||||
|
|
||||||
|
export { device, maxTransmissionGap, type };
|
||||||
@@ -61,4 +61,17 @@ export const generateUniqueID = () => {
|
|||||||
.digest('hex');
|
.digest('hex');
|
||||||
|
|
||||||
return uniqueID;
|
return uniqueID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extracts the value after a specific pattern from a string using regular expressions.
|
||||||
|
* @param {string} input - The input string.
|
||||||
|
* @param {string} pattern - The pattern to match.
|
||||||
|
* @returns {string|null} The value found after the pattern, or null if not found.
|
||||||
|
*/
|
||||||
|
export const extractValue = (input, pattern) => {
|
||||||
|
const regex = new RegExp(`${pattern}\\s+(\\S+)`);
|
||||||
|
const match = input.match(regex);
|
||||||
|
return match ? match[1] : null;
|
||||||
|
};
|
||||||
39
client/modules/cliHandler.mjs
Normal file
39
client/modules/cliHandler.mjs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { spawn } from "child_process";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Executes a command and retrieves its output.
|
||||||
|
* @param {string} command - The command to execute.
|
||||||
|
* @param {string[]} args - The arguments to pass to the command.
|
||||||
|
* @returns {Promise<string>} A promise that resolves with the output of the command.
|
||||||
|
*/
|
||||||
|
export const executeCommand = (command, args) => {
|
||||||
|
return new Promise((resolve, reject) => {
|
||||||
|
const childProcess = spawn(command, args);
|
||||||
|
|
||||||
|
let commandOutput = '';
|
||||||
|
|
||||||
|
childProcess.stdout.on('data', (data) => {
|
||||||
|
commandOutput += data.toString();
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.stderr.on('data', (data) => {
|
||||||
|
// Log any errors to stderr
|
||||||
|
console.error(data.toString());
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.on('error', (error) => {
|
||||||
|
// Reject the promise if there's an error executing the command
|
||||||
|
reject(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
childProcess.on('close', (code) => {
|
||||||
|
if (code === 0) {
|
||||||
|
// Resolve the promise with the command output if it exits successfully
|
||||||
|
resolve(commandOutput.trim());
|
||||||
|
} else {
|
||||||
|
// Reject the promise if the command exits with a non-zero code
|
||||||
|
reject(new Error(`Command '${command}' exited with code ${code}`));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
@@ -1 +1 @@
|
|||||||
node . 2> stderr.2
|
node .
|
||||||
@@ -17,14 +17,17 @@ export const deferInitialReply = false; // If we the initial reply in discord sh
|
|||||||
*/
|
*/
|
||||||
export const execute = async (nodeIo, interaction) => {
|
export const execute = async (nodeIo, interaction) => {
|
||||||
try {
|
try {
|
||||||
const sockets = await nodeIo.allSockets();
|
const openSockets = [...await nodeIo.allSockets()]; // TODO - Filter the returned nodes to only nodes that have the radio capability
|
||||||
console.log("All open sockets: ",sockets);
|
console.log("All open sockets: ", openSockets);
|
||||||
await sockets.map(openSocket => {
|
|
||||||
requestNodeUpdate(openSocket);
|
// Check each open socket to see if the node has the requested system
|
||||||
})
|
await Promise.all(openSockets.map(openSocket => {
|
||||||
//await interaction.reply(`**Online Sockets: '${sockets}'**`);
|
openSocket = nodeIo.sockets.sockets.get(openSocket);
|
||||||
await interaction.reply('**Pong.**');
|
requestNodeUpdate(openSocket);
|
||||||
//await interaction.channel.send('**Pong.**');
|
}));
|
||||||
|
//await interaction.reply(`**Online Sockets: '${sockets}'**`);
|
||||||
|
await interaction.reply('All nodes have been requested to update');
|
||||||
|
//await interaction.channel.send('**Pong.**');
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
// await interaction.reply(err.toString());
|
// await interaction.reply(err.toString());
|
||||||
|
|||||||
Reference in New Issue
Block a user