mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 09:31:20 -04:00
replay in web UI
This commit is contained in:
@@ -300,6 +300,24 @@ async function buildReplayVideo() {
|
||||
}
|
||||
}
|
||||
|
||||
function buildReplayCaption(requester) {
|
||||
const requesterLabel = requester || 'unknown';
|
||||
return [
|
||||
`Replay requested by ${requesterLabel}.`,
|
||||
buildDriverCaption(),
|
||||
].join(' ');
|
||||
}
|
||||
|
||||
async function sendReplayToChannel(channelId, requester) {
|
||||
if (!channelId) {
|
||||
throw new Error('Replay channel not configured');
|
||||
}
|
||||
const buffer = await buildReplayVideo();
|
||||
const attachment = new AttachmentBuilder(buffer, { name: 'replay.mp4' });
|
||||
const caption = buildReplayCaption(requester);
|
||||
await sendToChannel(channelId, caption, { files: [attachment] }, { parse: [] });
|
||||
}
|
||||
|
||||
async function handleReplayCommand(message) {
|
||||
if (getMode() === MODES.LOCKDOWN) {
|
||||
await message.reply({
|
||||
@@ -325,10 +343,7 @@ async function handleReplayCommand(message) {
|
||||
try {
|
||||
const buffer = await buildReplayVideo();
|
||||
const attachment = new AttachmentBuilder(buffer, { name: 'replay.mp4' });
|
||||
const caption = [
|
||||
`Replay requested by ${requester}.`,
|
||||
buildDriverCaption(),
|
||||
].join(' ');
|
||||
const caption = buildReplayCaption(requester);
|
||||
await message.reply({
|
||||
content: sanitizeMentions(caption),
|
||||
files: [attachment],
|
||||
@@ -701,6 +716,11 @@ function handleBusEvent(event) {
|
||||
});
|
||||
updatePresence();
|
||||
break;
|
||||
case 'replay.requested':
|
||||
sendReplayToChannel(payload?.channelId, payload?.requester).catch((err) => {
|
||||
logger.warn('Replay send failed', err.message);
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
const io = require('../globals/io');
|
||||
const logger = require('../globals/logger').child('replaySocket');
|
||||
const { getMode, MODES } = require('./modeManager');
|
||||
const { publishEvent } = require('./eventBus');
|
||||
const { tryTriggerReplay } = require('./replayService');
|
||||
const { getNickname } = require('./nicknameService');
|
||||
const { loadConfig } = require('../helpers/configLoader');
|
||||
|
||||
const config = loadConfig();
|
||||
const discordConfig = config.discord || {};
|
||||
|
||||
function buildRequesterLabel(socket) {
|
||||
return getNickname(socket) || socket?.data?.user?.username || socket?.id || 'unknown';
|
||||
}
|
||||
|
||||
io.on('connection', (socket) => {
|
||||
socket.on('replay:trigger', (payload = {}, cb = () => {}) => {
|
||||
if (getMode() === MODES.LOCKDOWN) {
|
||||
cb({ error: 'Replay disabled in lockdown', state: null });
|
||||
return;
|
||||
}
|
||||
const channelId = discordConfig?.channels?.replay || null;
|
||||
if (!channelId) {
|
||||
cb({ error: 'Replay channel not configured', state: null });
|
||||
return;
|
||||
}
|
||||
const requester = buildRequesterLabel(socket);
|
||||
const attempt = tryTriggerReplay({ by: { source: 'web', requester } });
|
||||
if (!attempt.ok) {
|
||||
cb({ error: 'Replay cooldown active', remainingMs: attempt.remainingMs, state: attempt.state });
|
||||
return;
|
||||
}
|
||||
publishEvent({
|
||||
source: 'replaySocket',
|
||||
type: 'replay.requested',
|
||||
payload: {
|
||||
channelId,
|
||||
requester,
|
||||
requestedBy: { socketId: socket.id },
|
||||
},
|
||||
});
|
||||
logger.info('Replay requested via web', { socketId: socket.id });
|
||||
cb({ success: true, state: attempt.state });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user