2026-07-30 11:50:48 +07:00
|
|
|
import { createChildLogger } from "@/shared/logger/index";
|
2026-06-02 00:11:29 +07:00
|
|
|
import type { Request, Response } from "express";
|
2026-06-09 19:46:08 +07:00
|
|
|
import { asyncHandler } from "../../shared/middlewares/index.js";
|
2026-06-08 22:55:11 +07:00
|
|
|
import { publishCommandNoReply } from "../../shared/redis/index.js";
|
2026-07-27 21:54:31 +07:00
|
|
|
import type { ConnectVoiceInput, VoiceCommandInput } from "./voice.schema.js";
|
2026-07-04 03:03:36 +07:00
|
|
|
import {
|
|
|
|
|
connectVoice,
|
|
|
|
|
disconnectVoice,
|
|
|
|
|
getVoiceStatus,
|
|
|
|
|
} from "./voice.service.js";
|
2026-06-02 00:11:29 +07:00
|
|
|
|
2026-06-09 19:46:08 +07:00
|
|
|
const logger = createChildLogger("voice.controller");
|
|
|
|
|
|
|
|
|
|
export const handleGetVoiceStatus = asyncHandler(
|
|
|
|
|
async (_req: Request, res: Response) => {
|
|
|
|
|
const status = await getVoiceStatus();
|
|
|
|
|
res.json(status);
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-06-02 00:11:29 +07:00
|
|
|
|
2026-06-09 19:46:08 +07:00
|
|
|
export const handleConnectVoice = asyncHandler(
|
|
|
|
|
async (req: Request, res: Response) => {
|
2026-07-27 21:54:31 +07:00
|
|
|
const { guildId, channelId } = req.body as ConnectVoiceInput;
|
2026-06-09 19:46:08 +07:00
|
|
|
logger.debug({ guildId, channelId }, "Connecting to voice channel");
|
|
|
|
|
const status = await connectVoice(guildId, channelId);
|
|
|
|
|
res.json(status);
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-06-02 00:11:29 +07:00
|
|
|
|
2026-06-09 19:46:08 +07:00
|
|
|
export const handleDisconnectVoice = asyncHandler(
|
|
|
|
|
async (_req: Request, res: Response) => {
|
|
|
|
|
logger.debug("Disconnecting from voice");
|
|
|
|
|
const status = await disconnectVoice();
|
|
|
|
|
res.json(status);
|
|
|
|
|
},
|
|
|
|
|
);
|
2026-06-02 00:11:29 +07:00
|
|
|
|
2026-06-09 19:46:08 +07:00
|
|
|
export const handleVoiceCommand = asyncHandler(
|
|
|
|
|
async (req: Request, res: Response) => {
|
2026-07-27 21:54:31 +07:00
|
|
|
const { command } = req.body as VoiceCommandInput;
|
2026-06-09 19:46:08 +07:00
|
|
|
logger.debug({ command }, "Publishing voice command");
|
2026-06-09 16:56:44 +07:00
|
|
|
await publishCommandNoReply(command);
|
2026-06-08 22:55:11 +07:00
|
|
|
res.json({ success: true, command });
|
2026-06-09 19:46:08 +07:00
|
|
|
},
|
|
|
|
|
);
|