- Server can now choose from IDs in the DB
- Implemented an active system to disable some IDs from being used
This commit is contained in:
Logan Cusano
2024-03-24 02:45:34 -04:00
parent bee95ed999
commit fea7ed2c7f
8 changed files with 205 additions and 26 deletions

View File

@@ -0,0 +1,90 @@
import { insertDocument, getDocuments, connectToDatabase } from "./mongoHandler.mjs";
const collectionName = 'discord-ids';
// Wrapper for inserting a Discord ID
export const createDiscordID = async (discordID) => {
try {
const insertedId = await insertDocument(collectionName, discordID);
return insertedId;
} catch (error) {
console.error('Error creating Discord ID:', error);
throw error;
}
};
// Wrapper for retrieving all Discord IDs
export const getAllDiscordIDs = async () => {
try {
const discordIDs = await getDocuments(collectionName);
return discordIDs;
} catch (error) {
console.error('Error getting all Discord IDs:', error);
throw error;
}
};
// Wrapper for retrieving a Discord ID by name or discord_id
export const getDiscordID = async (identifier) => {
const db = await connectToDatabase();
try {
const collection = db.db().collection(collectionName);
const discordID = await collection.findOne({
$or: [
{ name: identifier },
{ discord_id: identifier }
]
});
return discordID;
} catch (error) {
console.error('Error getting Discord ID:', error);
throw error;
} finally {
// Close the connection
await db.close();
}
};
// Wrapper for updating a Discord ID by name or discord_id
export const updateDiscordID = async (identifier, updatedFields) => {
const db = await connectToDatabase();
try {
const collection = db.db().collection(collectionName);
const result = await collection.updateOne({
$or: [
{ name: identifier },
{ discord_id: identifier }
]
}, { $set: updatedFields });
console.log('Discord ID updated:', result.modifiedCount);
return result.modifiedCount;
} catch (error) {
console.error('Error updating Discord ID:', error);
throw error;
} finally {
// Close the connection
await db.close();
}
};
// Wrapper for deleting a Discord ID by name or discord_id
export const deleteDiscordID = async (identifier) => {
const db = await connectToDatabase();
try {
const collection = db.db().collection(collectionName);
const result = await collection.deleteOne({
$or: [
{ name: identifier },
{ discord_id: identifier }
]
});
console.log('Discord ID deleted:', result.deletedCount);
return result.deletedCount;
} catch (error) {
console.error('Error deleting Discord ID:', error);
throw error;
} finally {
// Close the connection
await db.close();
}
};

View File

@@ -257,16 +257,29 @@ export const getNodeDiscordUsername = async (socket, guildId) => {
});
}
/**
* Get the discord ID from a given socket
* @param {any} socket The socket object of the node to check the ID of
* @returns {string} The ID of the bot
*/
export const getNodeDiscordID = async (socket) => {
return await new Promise((res) => {
socket.emit('node-get-discord-id', (discordID) => {
res(discordID);
});
});
}
/**
* Request a given socket node to join a given voice channel
* @param {any} socket The socket object of the node the request should be sent to
* @param {any} systemName The system preset name that we would like to listen to
* @param {string} discordChanelId The Discord channel ID to join the listening bot to
*/
export const requestNodeJoinSystem = async (socket, systemName, discordChanelId) => {
// Check for open client IDs
export const requestNodeJoinSystem = async (socket, systemName, discordChanelId, discordToken = "MTE5NjAwNTM2ODYzNjExMjk3Nw.GuCMXg.24iNNofNNumq46FIj68zMe9RmQgugAgfrvelEA") => {
// Join the system
const joinData = {
'clientID': "MTE5NjAwNTM2ODYzNjExMjk3Nw.GuCMXg.24iNNofNNumq46FIj68zMe9RmQgugAgfrvelEA",
'clientID': discordToken,
'channelID': discordChanelId,
'system': systemName
}