mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 01:21:20 -04:00
replay beroke
This commit is contained in:
@@ -153,7 +153,7 @@ const commands = createCommandHandlers({
|
|||||||
config,
|
config,
|
||||||
});
|
});
|
||||||
|
|
||||||
const integrations = createIntegrations({
|
const integrations = createIntegrations({
|
||||||
logger,
|
logger,
|
||||||
client,
|
client,
|
||||||
config,
|
config,
|
||||||
@@ -184,6 +184,7 @@ const integrations = createIntegrations({
|
|||||||
clearTypingMessage: channelIO.clearTypingMessage,
|
clearTypingMessage: channelIO.clearTypingMessage,
|
||||||
sendTypingMessage: channelIO.sendTypingMessage,
|
sendTypingMessage: channelIO.sendTypingMessage,
|
||||||
schedulePresenceRotation: presence.schedulePresenceRotation,
|
schedulePresenceRotation: presence.schedulePresenceRotation,
|
||||||
|
buildReplayVideo,
|
||||||
});
|
});
|
||||||
|
|
||||||
const integrationHandlers = integrations.register();
|
const integrationHandlers = integrations.register();
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ const { EmbedBuilder, AttachmentBuilder } = require('discord.js');
|
|||||||
const { buildBatteryStatusEmbed, buildBatteryCaption } = require('../batteryEmbeds');
|
const { buildBatteryStatusEmbed, buildBatteryCaption } = require('../batteryEmbeds');
|
||||||
|
|
||||||
function createBusEventHandler(deps) {
|
function createBusEventHandler(deps) {
|
||||||
const { logger, discordConfig, MODES, roverManager, rovers, schedulePresenceRotation, formatDuration, sendToChannel } = deps;
|
const { logger, discordConfig, MODES, roverManager, rovers, schedulePresenceRotation, formatDuration, sendToChannel, buildReplayVideo } = deps;
|
||||||
const ADMIN_ALERT_EVENT_TYPES = new Set(['rover.online', 'rover.offline', 'rover.dockGuard', 'battery.warn', 'battery.urgent', 'battery.docked', 'battery.undocked', 'battery.charging.start', 'battery.charging.stop', 'battery.locked', 'battery.unlocked']);
|
const ADMIN_ALERT_EVENT_TYPES = new Set(['rover.online', 'rover.offline', 'rover.dockGuard', 'battery.warn', 'battery.urgent', 'battery.docked', 'battery.undocked', 'battery.charging.start', 'battery.charging.stop', 'battery.locked', 'battery.unlocked']);
|
||||||
let skippedFirstModeAnnouncement = false;
|
let skippedFirstModeAnnouncement = false;
|
||||||
|
|
||||||
@@ -26,7 +26,33 @@ function createBusEventHandler(deps) {
|
|||||||
await sendToChannel(channelId, `${prefix}${content || ''}`.trim(), { embeds: payloadEmbeds, files: Array.isArray(files) ? files : undefined }, { parse: [], roles: pingRoleId ? [pingRoleId] : [] }, !pingRoleId);
|
await sendToChannel(channelId, `${prefix}${content || ''}`.trim(), { embeds: payloadEmbeds, files: Array.isArray(files) ? files : undefined }, { parse: [], roles: pingRoleId ? [pingRoleId] : [] }, !pingRoleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return function handleBusEvent(event) {
|
function sanitizeReplayTitleForFilename(title) {
|
||||||
|
const cleaned = String(title || '').replace(/[\\/:*?"<>|]+/g, ' ').replace(/\s+/g, ' ').trim().slice(0, 96);
|
||||||
|
return cleaned || 'replay';
|
||||||
|
}
|
||||||
|
|
||||||
|
async function sendReplayToChannel(channelId, requester, sources = [], explicitTitle = '', includeSidebar = true) {
|
||||||
|
if (!channelId) throw new Error('Replay channel not configured');
|
||||||
|
const resolvedTitle = String(explicitTitle || '').trim() || `${String(requester || 'Someone').trim() || 'Someone'} replay`;
|
||||||
|
const { buffer } = await buildReplayVideo({ sources, title: resolvedTitle, requester, includeSidebar });
|
||||||
|
const attachment = new AttachmentBuilder(buffer, { name: `${sanitizeReplayTitleForFilename(resolvedTitle)}.mp4` });
|
||||||
|
await sendToChannel(channelId, `**${resolvedTitle}**`, { files: [attachment] }, { parse: [] });
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleReplayRequested(event) {
|
||||||
|
const payload = event?.payload || {};
|
||||||
|
sendReplayToChannel(
|
||||||
|
payload?.channelId,
|
||||||
|
payload?.requester,
|
||||||
|
payload?.sources || [],
|
||||||
|
payload?.title || '',
|
||||||
|
payload?.includeSidebar !== false,
|
||||||
|
).catch((err) => {
|
||||||
|
logger.warn('Replay send failed', { error: err.message });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function handleBusEvent(event) {
|
||||||
const { type, payload } = event || {};
|
const { type, payload } = event || {};
|
||||||
const channels = discordConfig.channels || {};
|
const channels = discordConfig.channels || {};
|
||||||
const roles = discordConfig.roles || {};
|
const roles = discordConfig.roles || {};
|
||||||
@@ -84,10 +110,15 @@ function createBusEventHandler(deps) {
|
|||||||
announce({ channelId: channels.humanAlerts, pingRoleId: roles.humanAlertPing || null, content: payload?.message || 'Human alert button pressed.', embeds: [buildEmbed({ title: 'Human Alert Button Pressed', description: null, color: 0xe53935 })], files: attachment ? [attachment] : [] });
|
announce({ channelId: channels.humanAlerts, pingRoleId: roles.humanAlertPing || null, content: payload?.message || 'Human alert button pressed.', embeds: [buildEmbed({ title: 'Human Alert Button Pressed', description: null, color: 0xe53935 })], files: attachment ? [attachment] : [] });
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'replay.requested':
|
||||||
|
handleReplayRequested(event);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
|
return { handleBusEvent, handleReplayRequested };
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { createBusEventHandler };
|
module.exports = { createBusEventHandler };
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ function createIntegrations(deps) {
|
|||||||
|
|
||||||
const dm = createDmModerationHandlers({ ...deps, sanitizeMentions });
|
const dm = createDmModerationHandlers({ ...deps, sanitizeMentions });
|
||||||
const chat = createChatBridgeHandlers({ ...deps, clearTypingMessage, sendTypingMessage, formatWebhookUsername, getTypingId });
|
const chat = createChatBridgeHandlers({ ...deps, clearTypingMessage, sendTypingMessage, formatWebhookUsername, getTypingId });
|
||||||
const handleBusEvent = createBusEventHandler({ ...deps, sendToChannel, schedulePresenceRotation, formatDuration });
|
const { handleBusEvent, handleReplayRequested } = createBusEventHandler({ ...deps, sendToChannel, schedulePresenceRotation, formatDuration });
|
||||||
|
|
||||||
function register() {
|
function register() {
|
||||||
client.on('typingStart', (typing) => {
|
client.on('typingStart', (typing) => {
|
||||||
@@ -32,6 +32,7 @@ function createIntegrations(deps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
subscribe('*', handleBusEvent);
|
subscribe('*', handleBusEvent);
|
||||||
|
subscribe('replay.requested', handleReplayRequested);
|
||||||
subscribe('verification.requested', dm.sendVerificationRequestDms);
|
subscribe('verification.requested', dm.sendVerificationRequestDms);
|
||||||
subscribe('privateRoverAccess.requested', dm.sendPrivateRoverAccessRequestDms);
|
subscribe('privateRoverAccess.requested', dm.sendPrivateRoverAccessRequestDms);
|
||||||
subscribe('chat:message', chat.handleChatBridgeOutbound);
|
subscribe('chat:message', chat.handleChatBridgeOutbound);
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ function normalizeIncludeSidebar(value) {
|
|||||||
|
|
||||||
function registerReplaySocketHooks({ tryTriggerReplay, validateSources, getDefaultWebSources }) {
|
function registerReplaySocketHooks({ tryTriggerReplay, validateSources, getDefaultWebSources }) {
|
||||||
io.on('connection', (socket) => {
|
io.on('connection', (socket) => {
|
||||||
socket.on('replay:trigger', (payload = {}, cb = () => {}) => {
|
const handleReplayTrigger = (payload = {}, cb = () => {}) => {
|
||||||
if (getMode() === MODES.LOCKDOWN) {
|
if (getMode() === MODES.LOCKDOWN) {
|
||||||
cb({ error: 'Replay disabled in lockdown', state: null });
|
cb({ error: 'Replay disabled in lockdown', state: null });
|
||||||
return;
|
return;
|
||||||
@@ -72,7 +72,9 @@ function registerReplaySocketHooks({ tryTriggerReplay, validateSources, getDefau
|
|||||||
});
|
});
|
||||||
logger.info('Replay requested via web', { socketId: socket.id });
|
logger.info('Replay requested via web', { socketId: socket.id });
|
||||||
cb({ success: true, state: attempt.state });
|
cb({ success: true, state: attempt.state });
|
||||||
});
|
};
|
||||||
|
|
||||||
|
socket.on('replay:trigger', handleReplayTrigger);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user