59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
import express from 'express';
|
|
|
|
const router = express.Router();
|
|
|
|
// Get all voice channels
|
|
router.get('/', async (req, res) => {
|
|
try {
|
|
const response = await fetch(`${req.app.locals.botUrl}/channels`);
|
|
const result = await response.json();
|
|
res.json(result);
|
|
} catch (error) {
|
|
req.app.locals.logger.error(`Error getting channels: ${error.message}`);
|
|
res.status(500).json({ error: 'Failed to get channels' });
|
|
}
|
|
});
|
|
|
|
// Join a voice channel
|
|
router.post('/join', async (req, res) => {
|
|
try {
|
|
const { channelId } = req.body;
|
|
const response = await fetch(`${req.app.locals.botUrl}/join`, {
|
|
method: 'POST',
|
|
headers: { 'Content-Type': 'application/json' },
|
|
body: JSON.stringify({ channelId })
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
req.app.locals.broadcast('channelChange', { channelId, channelName: result.channelName });
|
|
}
|
|
|
|
res.status(response.status).json(result);
|
|
} catch (error) {
|
|
req.app.locals.logger.error(`Error joining channel: ${error.message}`);
|
|
res.status(500).json({ error: 'Failed to join channel' });
|
|
}
|
|
});
|
|
|
|
// Disconnect from voice channel
|
|
router.post('/disconnect', async (req, res) => {
|
|
try {
|
|
const response = await fetch(`${req.app.locals.botUrl}/disconnect`, {
|
|
method: 'POST'
|
|
});
|
|
const result = await response.json();
|
|
|
|
if (response.ok) {
|
|
req.app.locals.broadcast('channelChange', { disconnected: true });
|
|
}
|
|
|
|
res.status(response.status).json(result);
|
|
} catch (error) {
|
|
req.app.locals.logger.error(`Error disconnecting: ${error.message}`);
|
|
res.status(500).json({ error: 'Failed to disconnect' });
|
|
}
|
|
});
|
|
|
|
export default router;
|