// Debug const { DebugBuilder } = require("../utilities/debugBuilder.js"); const log = new DebugBuilder("client", "clientController"); // Modules const { status, join, leave } = require("./commandController") /** * Get an object of client guilds * @param req The express request which includes the discord client * @returns */ function getGuilds(req) { return req.discordClient.guilds.cache.map(guild => guild.id) } /** * Get Status of the discord process */ exports.getStatus = (res, req) => { log.INFO("Getting the status of the bot"); guildIds = getGuilds(req); log.DEBUG("Guild IDs: ", guildIds); var guildStatuses = [] for (const guildID of guildIds){ status({guildID: guildID, callback: (statusObj) => { log.DEBUG("Status Object string: ", statusObj); if (!statusObj.voiceConnection) guildStatuses.push({ guildID : 201 }); else guildStatuses.push({ guildID: 202 }) }}); } return res.send(200).json(guildStatuses); } /** * Start the bot and join the server and preset specified */ exports.joinServer = (res, req) => { const channelID = req.body.channelID; const presetName = req.body.presetName; if (!channelID || !presetName) return res.status(400).json({'message': "Channel ID or Preset Name not present in the request"}); // Start the bot join({guildID: guildID, guildObj: client.guilds.cache.get(guildID), channelID: channelID, callback: () => { return req.sendStatus(202); }}); } /** * Leaves the server if it's in one */ exports.leaveServer = (res, req) => { leave({guildID: guildID, callback: (response) => { return res.sendStatus(202); }}); }