2026-06-02 00:11:29 +07:00
|
|
|
import type { Request, Response } from "express";
|
2026-06-08 22:55:11 +07:00
|
|
|
import { publishCommandNoReply } from "../../shared/redis/index.js";
|
2026-06-02 00:11:29 +07:00
|
|
|
import {
|
|
|
|
|
connectVoice,
|
|
|
|
|
disconnectVoice,
|
|
|
|
|
getVoiceChannels,
|
|
|
|
|
getVoiceStatus,
|
|
|
|
|
} from "./voice.service.js";
|
|
|
|
|
|
|
|
|
|
export async function handleGetVoiceStatus(_req: Request, res: Response) {
|
2026-06-02 00:32:38 +07:00
|
|
|
const status = await getVoiceStatus();
|
2026-06-02 00:11:29 +07:00
|
|
|
res.json(status);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-09 16:56:44 +07:00
|
|
|
/** Safely extract a string value that may be a single string or string array. */
|
|
|
|
|
function asString(val: unknown): string {
|
|
|
|
|
if (Array.isArray(val)) return String(val[0] ?? "");
|
|
|
|
|
return String(val ?? "");
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-02 00:11:29 +07:00
|
|
|
export async function handleConnectVoice(req: Request, res: Response) {
|
2026-06-09 16:56:44 +07:00
|
|
|
const guildId = asString(req.body.guildId);
|
|
|
|
|
const channelId = asString(req.body.channelId);
|
2026-06-02 00:11:29 +07:00
|
|
|
if (!guildId || !channelId) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
error: "VALIDATION_ERROR",
|
|
|
|
|
message: "guildId and channelId are required",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
const status = await connectVoice(guildId, channelId);
|
|
|
|
|
res.json(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function handleDisconnectVoice(_req: Request, res: Response) {
|
|
|
|
|
const status = await disconnectVoice();
|
|
|
|
|
res.json(status);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export async function handleGetVoiceChannels(req: Request, res: Response) {
|
2026-06-09 16:56:44 +07:00
|
|
|
const guildId = asString(req.params.guildId);
|
2026-06-02 00:11:29 +07:00
|
|
|
const channels = await getVoiceChannels(guildId);
|
|
|
|
|
res.json(channels);
|
|
|
|
|
}
|
2026-06-08 22:55:11 +07:00
|
|
|
|
|
|
|
|
export async function handleVoiceCommand(req: Request, res: Response) {
|
2026-06-09 16:56:44 +07:00
|
|
|
const command = asString(req.body.command);
|
2026-06-08 22:55:11 +07:00
|
|
|
|
|
|
|
|
if (!command) {
|
|
|
|
|
return res.status(400).json({
|
|
|
|
|
error: "VALIDATION_ERROR",
|
|
|
|
|
message: "command is required",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
2026-06-09 16:56:44 +07:00
|
|
|
await publishCommandNoReply(command);
|
2026-06-08 22:55:11 +07:00
|
|
|
res.json({ success: true, command });
|
|
|
|
|
} catch (err) {
|
|
|
|
|
res.status(500).json({
|
|
|
|
|
error: "COMMAND_FAILED",
|
|
|
|
|
message: err instanceof Error ? err.message : "Unknown error",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|