Testing updates
- Added client tests, started with the pdabHandler interactions - Updated caps in socket server tests - Updated pdabHandler with uniform 'guild_id' - Updated pdabHandler with production check to launch or not launch the python client -
This commit is contained in:
@@ -6,6 +6,9 @@ import { launchProcess } from '../modules/subprocessHandler.mjs';
|
||||
import { join, dirname } from 'path';
|
||||
import { fileURLToPath } from 'url';
|
||||
|
||||
import dotenv from 'dotenv';
|
||||
dotenv.config()
|
||||
|
||||
const app = express();
|
||||
const server = http.createServer(app);
|
||||
const io = new Server(server);
|
||||
@@ -34,11 +37,17 @@ export const initDiscordBotClient = (clientId, callback) => {
|
||||
server.listen(port, async () => {
|
||||
console.log(`Server is running on port ${port}`);
|
||||
|
||||
launchProcess("python", [join(__dirname, "./pdab/main.py"), process.env.AUDIO_DEVICE_ID, clientId, port], false, join(__dirname, "./pdab"));
|
||||
if (process.env.NODE_ENV == "production") {
|
||||
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 closePdabSocketServer = () => {
|
||||
return io.close();
|
||||
}
|
||||
|
||||
|
||||
// Function to emit a command to join a voice channel
|
||||
export const connectToChannel = (channelId) => {
|
||||
@@ -53,7 +62,7 @@ export const connectToChannel = (channelId) => {
|
||||
// Function to emit a command to leave a voice channel
|
||||
export const leaveVoiceChannel = async (guildId) => {
|
||||
return await new Promise((res) => {
|
||||
io.timeout(25000).emit('leave_server', { guild_id: guildId }, (status, clientRemainsOpen) => {
|
||||
io.timeout(25000).emit('leave_server', { guildId: guildId }, (status, clientRemainsOpen) => {
|
||||
console.log("Discord client remains open?", clientRemainsOpen);
|
||||
res(clientRemainsOpen[0])
|
||||
});
|
||||
@@ -67,7 +76,7 @@ export const checkIfConnectedToVC = async (guildId) => {
|
||||
if (!pdabProcess) return false;
|
||||
|
||||
return await new Promise((res) => {
|
||||
io.timeout(25000).emit('check_discord_vc_connected', { guild_id: guildId }, (status, result) => {
|
||||
io.timeout(25000).emit('check_discord_vc_connected', { guildId: guildId }, (status, result) => {
|
||||
console.log(`Discord VC connected for guild ${guildId}: ${result}`);
|
||||
res((result[0]));
|
||||
});
|
||||
@@ -76,7 +85,7 @@ export const checkIfConnectedToVC = async (guildId) => {
|
||||
|
||||
export const requestDiscordUsername = (guildId) => {
|
||||
return new Promise((res) => {
|
||||
io.timeout(25000).emit('request_discord_username', { guild_id: guildId }, (status, result) => {
|
||||
io.timeout(25000).emit('request_discord_username', { guildId: guildId }, (status, result) => {
|
||||
console.log(`Discord username: ${result[0]}`);
|
||||
res(result[0]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user