Compare commits
11 Commits
fd261ef015
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a4d07db766 | ||
|
|
03c940e07c | ||
|
|
fee40dd609 | ||
|
|
5671503594 | ||
|
|
0fd511cfaf | ||
|
|
9d0aa0191f | ||
|
|
9ce8928d82 | ||
|
|
abadcf5cb5 | ||
|
|
4b18df9e2c | ||
|
|
26a8d8a172 | ||
|
|
26f3493c8f |
@@ -12,18 +12,13 @@ env:
|
|||||||
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
drb_mocha_tests:
|
drb_server_build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout code
|
- name: Checkout code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: actions/setup-node@v4
|
|
||||||
with:
|
|
||||||
node-version: '20'
|
|
||||||
|
|
||||||
- name: Build the latest code
|
- name: Build the latest code
|
||||||
working-directory: './server'
|
working-directory: './server'
|
||||||
run: make build
|
run: make build
|
||||||
@@ -19,26 +19,6 @@ const __dirname = dirname(__filename);
|
|||||||
|
|
||||||
let botCallback;
|
let botCallback;
|
||||||
|
|
||||||
const port = process.env.PDAB_PORT || 3000;
|
|
||||||
|
|
||||||
io.on('connection', (socket) => {
|
|
||||||
console.log('A user connected');
|
|
||||||
|
|
||||||
socket.on('disconnect', () => {
|
|
||||||
console.log('User disconnected');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Listen for the discord client ready event
|
|
||||||
socket.on('discord_ready', (message) => {
|
|
||||||
console.log("Message from local client", message);
|
|
||||||
botCallback();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
server.listen(port, async () => {
|
|
||||||
console.log(`Server is running on port ${port}`);
|
|
||||||
});
|
|
||||||
|
|
||||||
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
||||||
botCallback = callback;
|
botCallback = callback;
|
||||||
|
|
||||||
@@ -46,6 +26,29 @@ export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
|
|||||||
pdabProcess = true; // TODO - Make this more dynamic
|
pdabProcess = true; // TODO - Make this more dynamic
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export const startPdabSocketServer = () => {
|
||||||
|
const port = process.env.PDAB_PORT || 3000;
|
||||||
|
|
||||||
|
io.on('connection', (socket) => {
|
||||||
|
console.log('A user connected');
|
||||||
|
|
||||||
|
socket.on('disconnect', () => {
|
||||||
|
console.log('User disconnected');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Listen for the discord client ready event
|
||||||
|
socket.on('discord_ready', (message) => {
|
||||||
|
console.log("Message from local client", message);
|
||||||
|
botCallback();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
server.listen(port, async () => {
|
||||||
|
console.log(`Server is running on port ${port}`);
|
||||||
|
});
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
export const closePdabSocketServer = () => {
|
export const closePdabSocketServer = () => {
|
||||||
if (io.sockets && io.sockets.length > 0) {
|
if (io.sockets && io.sockets.length > 0) {
|
||||||
io.sockets.forEach(socket => {
|
io.sockets.forEach(socket => {
|
||||||
@@ -75,6 +78,15 @@ export const leaveVoiceChannel = async (guildId) => {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Set the presense of the discord client
|
||||||
|
export const setDiscordClientPrsense = (system) => {
|
||||||
|
return new Promise((res) => {
|
||||||
|
io.timeout(25000).emit('set_system', { system: system }, (status) => {
|
||||||
|
res();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
// Placeholder functions (replace with actual implementation)
|
// Placeholder functions (replace with actual implementation)
|
||||||
export const checkIfConnectedToVC = async (guildId) => {
|
export const checkIfConnectedToVC = async (guildId) => {
|
||||||
console.log("Pdab process var:", pdabProcess);
|
console.log("Pdab process var:", pdabProcess);
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { connectToChannel, leaveVoiceChannel, checkIfConnectedToVC, initDiscordBotClient, requestDiscordUsername, requestDiscordID, requestDiscordClientClose, closePdabSocketServer } from './pdabHandler.mjs';
|
import { connectToChannel, leaveVoiceChannel, checkIfConnectedToVC, initDiscordBotClient, requestDiscordUsername, requestDiscordID, requestDiscordClientClose, closePdabSocketServer, setDiscordClientPrsense, startPdabSocketServer } from './pdabHandler.mjs';
|
||||||
import { openOP25, closeOP25 } from '../op25Handler/op25Handler.mjs';
|
import { openOP25, closeOP25 } from '../op25Handler/op25Handler.mjs';
|
||||||
|
|
||||||
let activeDiscordClient = undefined;
|
let activeDiscordClient = undefined;
|
||||||
@@ -14,13 +14,17 @@ export const joinDiscordVC = async (joinData) => {
|
|||||||
console.log("Checking if there is a client open");
|
console.log("Checking if there is a client open");
|
||||||
if (!await checkIfClientIsOpen()) {
|
if (!await checkIfClientIsOpen()) {
|
||||||
console.log("There is no open client, starting it now");
|
console.log("There is no open client, starting it now");
|
||||||
|
await startPdabSocketServer();
|
||||||
// Open an instance of OP25
|
// Open an instance of OP25
|
||||||
console.log("Starting OP25")
|
console.log("Starting OP25")
|
||||||
openOP25(joinData.system);
|
openOP25(joinData.system);
|
||||||
|
|
||||||
// Open a new client and join the requested channel with the requested ID
|
// Open a new client and join the requested channel with the requested ID
|
||||||
initDiscordBotClient(joinData.clientID, () => {
|
initDiscordBotClient(joinData.clientID, () => {
|
||||||
console.log("Started PDAB")
|
console.log("Started PDAB");
|
||||||
|
|
||||||
|
console.log("Setting the presense of the bot");
|
||||||
|
setDiscordClientPrsense(joinData.system);
|
||||||
|
|
||||||
// Add the client object to the IO instance
|
// Add the client object to the IO instance
|
||||||
console.log("Connecting to channel")
|
console.log("Connecting to channel")
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
npm install
|
npm install
|
||||||
|
|
||||||
# Install OP25 Updates
|
# Install OP25 Updates
|
||||||
cd ./op25
|
#cd ./op25
|
||||||
bash rebuild.sh
|
#bash rebuild.sh
|
||||||
|
|
||||||
# Check for PDAB updates
|
# Check for PDAB updates
|
||||||
cd ../discordAudioBot/pdab
|
cd ../discordAudioBot/pdab
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ WORKDIR /server
|
|||||||
COPY package*.json ./
|
COPY package*.json ./
|
||||||
|
|
||||||
# Install dependencies
|
# Install dependencies
|
||||||
|
RUN npm install -g node-gyp
|
||||||
RUN npm install
|
RUN npm install
|
||||||
|
|
||||||
# Copy the rest of the application code to the working directory
|
# Copy the rest of the application code to the working directory
|
||||||
|
|||||||
@@ -57,13 +57,19 @@ export async function execute(nodeIo, interaction) {
|
|||||||
const joinSelectedNode = async (selectedNodeSocketId) => {
|
const joinSelectedNode = async (selectedNodeSocketId) => {
|
||||||
const openSocket = await nodeIo.sockets.sockets.get(selectedNodeSocketId);
|
const openSocket = await nodeIo.sockets.sockets.get(selectedNodeSocketId);
|
||||||
// Get the open ID for this connection\
|
// Get the open ID for this connection\
|
||||||
const discordToken = await getAvailableTokensInGuild(nodeIo, interaction.guild.id);
|
const ss = await getAvailableTokensInGuild(nodeIo, interaction.guild.id);
|
||||||
// TODO - Implement a method to have preferred tokens (bot users) for specific systems
|
console.log("Available discord tokens: ", discordTokens);
|
||||||
|
|
||||||
console.log("Joining selected open socket:", selectedNodeSocketId, system.name, channelToJoin.id, openSocket.node.name, discordToken);
|
if (discordTokens.length >= 1) {
|
||||||
|
// TODO - Implement a method to have preferred tokens (bot users) for specific systems
|
||||||
|
console.log("Joining selected open socket:", selectedNodeSocketId, system.name, channelToJoin.id, openSocket.node.name, discordTokens[0].token);
|
||||||
|
|
||||||
// Ask the node to join the selected channel and system
|
// Ask the node to join the selected channel and system
|
||||||
await requestNodeJoinSystem(openSocket, system.name, channelToJoin.id, discordToken[0].token);
|
await requestNodeJoinSystem(openSocket, system.name, channelToJoin.id, discordTokens[0].token);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return await interaction.editReply({ content: `<@${interaction.member.id}>, there are no free bots. Free up or create a new bot ID (discord app) to listen to this system.`, ephemeral: true })
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get all open socket nodes
|
// Get all open socket nodes
|
||||||
|
|||||||
@@ -37,10 +37,7 @@ export const checkOnlineBotsInGuild = async (nodeIo, guildId) => {
|
|||||||
console.log("Online bots in the guild:", onlineBots);
|
console.log("Online bots in the guild:", onlineBots);
|
||||||
|
|
||||||
// Filter any discordIDs that are not active
|
// Filter any discordIDs that are not active
|
||||||
var availableDiscordIDs = discordIDs.filter(discordID => discordID.active == true);
|
const availableDiscordIDs = discordIDs.filter(discordID => discordID.active == true).filter(discordID => !onlineBots.some(bot => Number(bot.discord_id) == discordID.discord_id));
|
||||||
|
|
||||||
// Filter out discordIDs that are not found in onlineBots
|
|
||||||
availableDiscordIDs = availableDiscordIDs.filter(discordID => !onlineBots.some(bot => bot.discord_id === discordID.discord_id));
|
|
||||||
|
|
||||||
// Return the unavailable discordIDs
|
// Return the unavailable discordIDs
|
||||||
return availableDiscordIDs;
|
return availableDiscordIDs;
|
||||||
|
|||||||
Reference in New Issue
Block a user