54 lines
1.6 KiB
JavaScript
54 lines
1.6 KiB
JavaScript
// Debug
|
|
const { DebugBuilder } = require("../utilities/debugBuilder.js");
|
|
const log = new DebugBuilder("client", "clientController");
|
|
// Modules
|
|
const path = require('path');
|
|
const fork = require('child_process').fork;
|
|
const discordBotPath = path.resolve('discord-bot/app.js');
|
|
// Commands
|
|
const ping = require('../commands/ping.js');
|
|
const join = require('../commands/join.js');
|
|
const leave = require('../commands/leave.js');
|
|
const status = require('../commands/status.js');
|
|
|
|
/**
|
|
* Get an object of client guilds
|
|
* @returns
|
|
*/
|
|
function getGuilds() {
|
|
return client.guilds.cache.map(guild => guild.id)
|
|
}
|
|
|
|
/**
|
|
* Get Status of the discord process
|
|
*/
|
|
exports.getStatus = (req, res) => {
|
|
status({guildID: guildID, callback: (statusObj) => {
|
|
log.DEBUG("Status Object string: ", statusObj);
|
|
if (!statusObj.voiceConnection) return req.sendStatus(201);
|
|
return req.sendStatus(202);
|
|
}});
|
|
}
|
|
|
|
/**
|
|
* Start the bot and join the server and preset specified
|
|
*/
|
|
exports.joinServer = (req, res) => {
|
|
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 = (req, res) => {
|
|
leave({guildID: guildID, callback: (response) => {
|
|
return req.sendStatus(202);
|
|
}});
|
|
} |