Compare commits

..

39 Commits

Author SHA1 Message Date
Logan Cusano
a4d07db766 #16 Update variable name
Some checks failed
DRB Server Build / drb_server_build (push) Successful in 36s
DRB Tests / drb_mocha_tests (push) Failing after 1m13s
2024-05-11 14:40:10 -04:00
Logan Cusano
03c940e07c Update PDAB handler
- Move PDAB socket server startup to function
- Updated join server wrapper to start the server before opening the python app
2024-05-05 23:39:05 -04:00
Logan Cusano
fee40dd609 #16 Updated join
-  After getting all available IDs, it now checks if there are IDs. If not telling the user
2024-05-05 22:00:04 -04:00
Logan Cusano
5671503594 Omitting OP25 update in the post update for now 2024-05-05 18:29:06 -04:00
Logan Cusano
0fd511cfaf Adding handlers for discord presense 2024-05-05 18:24:59 -04:00
Logan Cusano
9d0aa0191f Resolve bug when selecting ID on join 2024-05-05 18:24:11 -04:00
Logan Cusano
9ce8928d82 Revert base image and add global gyp install
Some checks failed
DRB Server Build / drb_server_build (push) Successful in 24s
DRB Tests / drb_mocha_tests (push) Failing after 59s
2024-04-29 23:25:34 -04:00
Logan Cusano
abadcf5cb5 Change base image of the dockerfile
Some checks failed
DRB Server Build / drb_server_build (push) Failing after 9s
DRB Tests / drb_mocha_tests (push) Failing after 1m38s
2024-04-29 22:16:17 -04:00
Logan Cusano
4b18df9e2c Fix server build name and removed clean and run code, just update
Some checks failed
DRB Server Build / drb_server_build (push) Successful in 6s
DRB Tests / drb_mocha_tests (push) Failing after 58s
2024-04-29 01:28:18 -04:00
Logan Cusano
26a8d8a172 Update build to clean and run the container
All checks were successful
DRB Server Build / drb_mocha_tests (push) Successful in 6s
2024-04-29 01:20:50 -04:00
Logan Cusano
26f3493c8f Remove node setup from build action
Some checks failed
DRB Tests / drb_mocha_tests (push) Failing after 58s
DRB Server Build / drb_mocha_tests (push) Successful in 8s
2024-04-29 01:17:14 -04:00
Logan Cusano
fd261ef015 Missed addition
Some checks failed
DRB Server Build / drb_mocha_tests (push) Failing after 7s
DRB Tests / drb_mocha_tests (push) Failing after 55s
- Server build action
2024-04-29 01:13:00 -04:00
Logan Cusano
91201c3527 Update tests
- Update test names
- Added new action to build the latest server code on the server it's running on
- Removed unnecessary vars from makefile
2024-04-29 01:12:30 -04:00
Logan Cusano
dfb4c6afa1 Remove build from tests 2024-04-28 22:52:39 -04:00
Logan Cusano
3b8e70208a Update build tests
Some checks failed
DRB Build Tests / build (push) Failing after 5s
DRB Build Tests / drb_build_and_test (push) Failing after 53s
Start docker in the test
2024-04-28 22:22:01 -04:00
Logan Cusano
99b60bf02c Update build tests
Some checks failed
DRB Build Tests / build (push) Failing after 5s
DRB Build Tests / drb_build_and_test (push) Failing after 58s
2024-04-28 22:19:09 -04:00
Logan Cusano
831317b9f0 Update build test
Some checks failed
DRB Build Tests / build (push) Failing after 7s
DRB Build Tests / drb_build_and_test (push) Failing after 56s
- Switch to installing docker io
2024-04-28 20:13:25 -04:00
Logan Cusano
2477b10900 Add docker install step to build test
Some checks failed
DRB Build Tests / build (push) Failing after 1m17s
DRB Build Tests / drb_build_and_test (push) Failing after 57s
2024-04-28 06:08:57 -04:00
Logan Cusano
67c29f1d72 Remove gitea debug after potential resolution
Some checks failed
DRB Build Tests / build (push) Failing after 8s
DRB Build Tests / drb_build_and_test (push) Failing after 1m1s
2024-04-28 06:07:06 -04:00
Logan Cusano
91ed4fb1dc gitea debug 2
Some checks failed
DRB Build Tests / build (push) Failing after 1m3s
DRB Build Tests / drb_build_and_test (push) Failing after 1m31s
2024-04-28 05:50:52 -04:00
Logan Cusano
8ea02d1c0b gitea debug
Some checks failed
DRB Build Tests / build (push) Failing after 16s
DRB Build Tests / drb_build_and_test (push) Has been cancelled
2024-04-28 05:49:57 -04:00
Logan Cusano
b15ac7c973 Added working directory to build step
Some checks failed
DRB Build Tests / build (push) Failing after 14s
DRB Build Tests / drb_build_and_test (push) Failing after 52s
2024-04-28 05:32:54 -04:00
Logan Cusano
c2c90019d7 Update tests
Some checks failed
DRB Build Tests / build (push) Failing after 32s
DRB Build Tests / drb_build_and_test (push) Failing after 58s
2024-04-28 05:30:13 -04:00
Logan Cusano
686ddc8a0f Gitea runner debug
Some checks failed
DRB Build Tests / build (push) Failing after 25s
DRB Build Tests / drb_build_and_test (push) Failing after 41s
2024-04-28 05:22:20 -04:00
Logan Cusano
463ccc1bd5 Setup docker in the test
Some checks failed
DRB Build Tests / build (push) Failing after 1m13s
DRB Build Tests / drb_build_and_test (push) Failing after 59s
2024-04-28 05:17:08 -04:00
Logan Cusano
14a2b4a1b9 Update tests
Some checks failed
DRB Build Tests / build (push) Failing after 41s
DRB Build Tests / drb_build_and_test (push) Failing after 43s
- Output docker ps before curl
2024-04-28 05:13:40 -04:00
Logan Cusano
0c1f6cd867 Update dockerfile
Some checks failed
DRB Build Tests / build (push) Failing after 34s
DRB Build Tests / drb_build_and_test (push) Failing after 51s
- Use the startup command used in the terminal
2024-04-28 05:11:49 -04:00
Logan Cusano
7175487d77 Update makefile
Some checks failed
DRB Build Tests / build (push) Failing after 31s
DRB Build Tests / drb_build_and_test (push) Failing after 43s
- Run docker detached
2024-04-28 05:06:50 -04:00
Logan Cusano
f0eac45955 Replace space with tab in makefile
Some checks failed
DRB Build Tests / build (push) Failing after 12s
DRB Build Tests / drb_build_and_test (push) Has been cancelled
2024-04-28 05:05:43 -04:00
Logan Cusano
c81dce99e2 Update makefile with clean step
Some checks failed
DRB Build Tests / build (push) Failing after 7s
DRB Build Tests / drb_build_and_test (push) Has been cancelled
2024-04-28 05:04:52 -04:00
Logan Cusano
38cb1054e0 Add DISCORD_TOKEN var to tests and makefile
Some checks failed
DRB Build Tests / build (push) Failing after 12s
DRB Build Tests / drb_build_and_test (push) Failing after 59s
2024-04-28 05:00:10 -04:00
Logan Cusano
12441c5c6d Update makefile
Some checks failed
DRB Build Tests / build (push) Failing after 1m38s
DRB Build Tests / drb_build_and_test (push) Failing after 56s
- Mistake in the docker build path
2024-04-28 04:54:53 -04:00
Logan Cusano
1c1b071bd7 Update makefile
Some checks failed
DRB Build Tests / build (push) Failing after 9s
DRB Build Tests / drb_build_and_test (push) Has been cancelled
- Removed all spaces for tabs
2024-04-28 04:53:55 -04:00
Logan Cusano
961c5c19e2 Update drb tests
Some checks failed
DRB Build Tests / build (push) Failing after 7s
DRB Build Tests / drb_build_and_test (push) Failing after 56s
- Update working directory for make
2024-04-28 04:49:56 -04:00
Logan Cusano
49e52d8944 Add makefile for server and related action build test
Some checks failed
DRB Build Tests / build (push) Failing after 7s
DRB Build Tests / drb_build_and_test (push) Failing after 58s
2024-04-28 04:46:08 -04:00
Logan Cusano
63ccfa70d3 Add server docker file and related action tests
Some checks failed
DRB Build Tests / build (push) Failing after 15s
DRB Build Tests / drb_build_and_test (push) Failing after 1m2s
2024-04-28 04:34:15 -04:00
Logan Cusano
4bb8038a1d Update variables in test action
Some checks failed
DRB Build Tests / drb_build_and_test (push) Failing after 57s
2024-04-28 03:26:06 -04:00
Logan Cusano
a353b9adbb Improvements to tests and from testing
- Moved OP25 start outside of PDAB start callback
- Added more logging
- Set the pdabProcess variable to false when closing the discord client
- Update test variable names
- Added new WIP pdabWrappers tests to test the full wrappers as the client would
2024-04-28 03:21:03 -04:00
Logan Cusano
bf69e93e29 Improve subprocess handler
- Will now output the subprocess console when in dev mode
2024-04-28 03:18:13 -04:00
12 changed files with 209 additions and 68 deletions

View File

@@ -0,0 +1,24 @@
name: DRB Server Build
on:
push:
branches:
- master
env:
NODE_ENV: production
SERVER_PORT: 3000
MONGO_URL: ${{ secrets.MONGO_URL }}
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
jobs:
drb_server_build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Build the latest code
working-directory: './server'
run: make build

View File

@@ -1,4 +1,4 @@
name: DRB Build Tests
name: DRB Tests
on:
pull_request:
@@ -13,16 +13,19 @@ env:
MONGO_INITDB_ROOT_USERNAME: admin
MONGO_INITDB_ROOT_PASSWORD: admin
MONGO_INITDB_DATABASE: drb
SERVER_PORT: 6000
SERVER_PORT: 3000
MONGO_URL: "mongodb://mongodb:27017/drb"
DISCORD_CLIENT_ID: ${{ secrets.DISCORD_CLIENT_ID }}
TEST_CHANNEL_ID: ${{ secrets.TEST_CHANNEL_ID }}
DISCORD_TOKEN: ${{ secrets.DISCORD_TOKEN }}
TEST_GUILD_ID: ${{ secrets.TEST_GUILD_ID }}
EXPECTED_CLIENT_ID: ${{ secrets.EXPECTED_CLIENT_ID }}
TEST_CLIENT_TOKEN: ${{ secrets.TEST_CLIENT_TOKEN }}
TEST_CHANNEL_ID: ${{ secrets.TEST_CHANNEL_ID }}
TEST_SYSTEM: ${{ secrets.TEST_SYSTEM }}
EXPECTED_CLIENT_ID: ${{ secrets.TEST_CLIENT_ID }}
EXPECTED_USERNAME: ${{ secrets.EXPECTED_USERNAME }}
PDAB_PORT: ${{ vars.PDAB_PORT }}
jobs:
drb_build_and_test:
drb_mocha_tests:
runs-on: ubuntu-latest
services:

View File

@@ -19,6 +19,14 @@ const __dirname = dirname(__filename);
let botCallback;
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
botCallback = callback;
if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab"));
pdabProcess = true; // TODO - Make this more dynamic
}
export const startPdabSocketServer = () => {
const port = process.env.PDAB_PORT || 3000;
io.on('connection', (socket) => {
@@ -38,12 +46,7 @@ io.on('connection', (socket) => {
server.listen(port, async () => {
console.log(`Server is running on port ${port}`);
});
export const initDiscordBotClient = (clientId, callback, runPDAB = true) => {
botCallback = callback;
if (runPDAB) launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab"));
pdabProcess = true; // TODO - Make this more dynamic
return
}
export const closePdabSocketServer = () => {
@@ -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)
export const checkIfConnectedToVC = async (guildId) => {
console.log("Pdab process var:", pdabProcess);
@@ -120,6 +132,7 @@ export const requestDiscordID = () => {
export const requestDiscordClientClose = () => {
return new Promise((res) => {
io.timeout(25000).emit('request_client_close');
pdabProcess = false;
res();
});
};

View File

@@ -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';
let activeDiscordClient = undefined;
@@ -8,16 +8,26 @@ let activeDiscordClient = undefined;
* @param {object} joinData The object containing all the information to join the server
*/
export const joinDiscordVC = async (joinData) => {
console.log("Join requested: ", joinData)
console.log("Join requested: ", joinData);
const connection = await new Promise(async (res) => {
// Check if a client already exists
console.log("Checking if there is a client open");
if (!await checkIfClientIsOpen()) {
// Open a new client and join the requested channel with the requested ID
initDiscordBotClient(joinData.clientID, () => {
console.log("There is no open client, starting it now");
await startPdabSocketServer();
// Open an instance of OP25
console.log("Starting OP25")
openOP25(joinData.system);
// Open a new client and join the requested channel with the requested ID
initDiscordBotClient(joinData.clientID, () => {
console.log("Started PDAB");
console.log("Setting the presense of the bot");
setDiscordClientPrsense(joinData.system);
// Add the client object to the IO instance
console.log("Connecting to channel")
connectToChannel(joinData.channelID, (connectionStatus) => {
console.log("Bot Connected to VC:", connectionStatus);
res(connectionStatus);
@@ -25,7 +35,9 @@ export const joinDiscordVC = async (joinData) => {
});
} else {
// Join the requested channel with the requested ID
// Add the client object to the IO instance
console.log("There is an open client");
console.log("Connecting to channel")
const connection = connectToChannel(joinData.channelID);
console.log("Bot Connected to VC::");
res(connection);

View File

@@ -1,4 +1,6 @@
import { spawn } from "child_process";
import dotenv from 'dotenv';
dotenv.config()
/**
* Object to store references to spawned processes.
@@ -25,11 +27,29 @@ export const launchProcess = (processName, args, waitForClose=false, pcwd=undefi
// Store reference to the spawned process
runningProcesses[processName] = childProcess;
// Output the process output in development
var scriptOutput = "";
// Get the stdout from the child process
childProcess.stdout.setEncoding('utf8');
childProcess.stdout.on('data', (data) => {
if (process.env.NODE_ENV === "development") console.log(`Data from ${processName}:`, data);
scriptOutput += data.toString();
});
// Get the stderr from the child process
childProcess.stderr.setEncoding('utf8');
childProcess.stderr.on('data', (data) => {
if (process.env.NODE_ENV === "development") console.log(`Data from ${processName}:`, data);
scriptOutput += data.toString();
})
let code = new Promise(res => {
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("Child process console output: ", scriptOutput);
res(code);
})
});

View File

@@ -4,8 +4,8 @@
npm install
# Install OP25 Updates
cd ./op25
bash rebuild.sh
#cd ./op25
#bash rebuild.sh
# Check for PDAB updates
cd ../discordAudioBot/pdab

View File

@@ -1,8 +1,5 @@
// Import necessary modules for testing
import { use, expect } from 'chai'
import chaiHttp from 'chai-http'
const chai = use(chaiHttp)
import { expect } from 'chai'
import io from 'socket.io-client';
const ioClient = io;
@@ -35,7 +32,7 @@ describe('Socket Server Tests', done => {
});
it('Should open a socket server and callback when the client is connected and ready', done => {
const clientId = process.env.DISCORD_CLIENT_ID;
const clientId = process.env.TEST_CLIENT_TOKEN;
const callback = () => {
done();
@@ -130,19 +127,9 @@ describe('Socket Server Tests', done => {
});
describe('Socket Client & Python IPC Tests', done => {
after(async () => {
// Any teardown needed after tests
try {
await socket.close();
}
catch {
console.log("Socket already closed");
}
});
it('Should open a socket server and callback when the client is connected and ready', done => {
let clientConnected = false;
const clientId = process.env.DISCORD_CLIENT_ID;
const clientId = process.env.TEST_CLIENT_TOKEN;
const callback = () => {
clientConnected = true;
@@ -165,13 +152,6 @@ describe('Socket Client & Python IPC Tests', done => {
expect(status).to.be.true;
});
it('Should have opened OP25', async () => {
// Assuming your server is running on localhost:8081
const res = await chai.request('http://localhost:8081').get('/');
expect(res).to.have.status(200); // Assuming 200 is the expected status code
// Add more assertions if needed
});
it('Should emit command for and return status if connected to voice channel', async () => {
// Simulate emitting 'check_discord_vc_connected' event
const isConnected = await checkIfConnectedToVC(process.env.TEST_GUILD_ID);

View File

@@ -0,0 +1,40 @@
import { use } from 'chai';
import chaiHttp from 'chai-http';
const chai = use(chaiHttp)
chai.should();
import dotenv from 'dotenv';
dotenv.config()
import { joinDiscordVC, leaveDiscordVC } from '../discordAudioBot/pdabWrappers.mjs'
before(async () => {
// Any setup needed before tests
});
after(async () => {
// Any teardown needed after tests
});
describe('PDAB Wrapper Tests', () => {
it('Should open the discord bot, and join the first server when requested', async () => {
// Test case
const joinData = {
channelID: process.env.TEST_CHANNEL_ID,
clientID: process.env.TEST_CLIENT_TOKEN,
system: process.env.TEST_SYSTEM,
};
const connection = await joinDiscordVC(joinData);
console.log("Connection:", connection);
});
it('Should open OP25', async () => {
const res = await chai.request('http://localhost:8081').get('/');
expect(res).to.have.status(200); // Assuming 200 is the expected status code
// Add more assertions if needed
})
it("Should disconnect from the discord server", async () => {
await leaveDiscordVC(process.env.TEST_GUILD_ID);
})
});

21
server/Dockerfile Normal file
View File

@@ -0,0 +1,21 @@
# Use the official Node.js image as the base image
FROM node:20
# Set the working directory inside the container
WORKDIR /server
# Copy package.json and package-lock.json (if available) to the working directory
COPY package*.json ./
# Install dependencies
RUN npm install -g node-gyp
RUN npm install
# Copy the rest of the application code to the working directory
COPY . .
# Expose the port on which your Node.js application will run
EXPOSE 3000
# Command to run the Node.js application
CMD ["node", "."]

View File

@@ -57,13 +57,19 @@ export async function execute(nodeIo, interaction) {
const joinSelectedNode = async (selectedNodeSocketId) => {
const openSocket = await nodeIo.sockets.sockets.get(selectedNodeSocketId);
// Get the open ID for this connection\
const discordToken = await getAvailableTokensInGuild(nodeIo, interaction.guild.id);
// TODO - Implement a method to have preferred tokens (bot users) for specific systems
const ss = await getAvailableTokensInGuild(nodeIo, interaction.guild.id);
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
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

View File

@@ -37,10 +37,7 @@ export const checkOnlineBotsInGuild = async (nodeIo, guildId) => {
console.log("Online bots in the guild:", onlineBots);
// Filter any discordIDs that are not active
var availableDiscordIDs = discordIDs.filter(discordID => discordID.active == true);
// Filter out discordIDs that are not found in onlineBots
availableDiscordIDs = availableDiscordIDs.filter(discordID => !onlineBots.some(bot => bot.discord_id === discordID.discord_id));
const availableDiscordIDs = discordIDs.filter(discordID => discordID.active == true).filter(discordID => !onlineBots.some(bot => Number(bot.discord_id) == discordID.discord_id));
// Return the unavailable discordIDs
return availableDiscordIDs;

25
server/makefile Normal file
View File

@@ -0,0 +1,25 @@
# Define variables
DOCKER_IMAGE_NAME := drb-server
# Define targets and rules
.PHONY: clean build run
clean:
@echo "Cleaning existing Docker images, containers, and builds..."
docker stop drb || true
docker rm drb || true
docker rmi $(DOCKER_IMAGE_NAME) || true
build:
@echo "Building Docker image..."
docker build -t $(DOCKER_IMAGE_NAME) .
run:
@echo "Running Docker container..."
docker run -d -e NODE_ENV=${NODE_ENV} \
-e SERVER_PORT=${SERVER_PORT} \
-e MONGO_URL=${MONGO_URL} \
-e DISCORD_TOKEN=${DISCORD_TOKEN} \
-p ${SERVER_PORT}:${SERVER_PORT} \
--name=drb \
$(DOCKER_IMAGE_NAME)