mirror of
https://github.com/legop3/MultiRoombaRover.git
synced 2026-09-16 17:40:46 -04:00
chat history and other stuffs, light commands replay fixes
This commit is contained in:
@@ -33,6 +33,34 @@ function createLightsCommand({ homeAssistantService, sanitizeMentions, config })
|
||||
return;
|
||||
}
|
||||
|
||||
const isAdmin = Boolean(message.actor?.isAdmin);
|
||||
const adminActions = new Set(['status', 'lock', 'unlock']);
|
||||
|
||||
// The lights namespace intentionally contains both public feature actions
|
||||
// and room-policy actions. The shared dispatcher applies the current server
|
||||
// mode to the feature as a whole; this focused check preserves the stronger
|
||||
// historical permission on status/lock/unlock without making on/off/colors
|
||||
// admin-only during normal open or turns operation.
|
||||
if (adminActions.has(action) && !isAdmin) {
|
||||
await message.reply({
|
||||
content: 'Only admins can manage the room-light lock.',
|
||||
allowedMentions: { parse: [], repliedUser: false },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// An active lock is a policy boundary for ordinary feature commands. Admin
|
||||
// lock management remains available, but public scene commands must not
|
||||
// silently defeat a locked-on or locked-off room state.
|
||||
const lightPolicy = homeAssistantService.getLightPolicyState?.() || {};
|
||||
if ((action === 'on' || action === 'off' || action === 'colors') && lightPolicy.locked) {
|
||||
await message.reply({
|
||||
content: describeLightPolicy(lightPolicy),
|
||||
allowedMentions: { parse: [], repliedUser: false },
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === 'status') {
|
||||
await message.reply({
|
||||
content: describeLightPolicy(homeAssistantService.getLightPolicyState?.() || {}),
|
||||
@@ -41,9 +69,35 @@ function createLightsCommand({ homeAssistantService, sanitizeMentions, config })
|
||||
return;
|
||||
}
|
||||
|
||||
if (action === 'on' || action === 'off' || action === 'colors') {
|
||||
try {
|
||||
const result = action === 'colors'
|
||||
? await homeAssistantService.setRandomColorScene({ source: 'bot-command:lights:colors' })
|
||||
: await homeAssistantService.setAllControllableEntitiesState(action, {
|
||||
source: `bot-command:lights:${action}`,
|
||||
});
|
||||
const failed = result?.failures?.length || 0;
|
||||
const succeeded = result?.succeeded?.length || 0;
|
||||
const description = action === 'colors'
|
||||
? `Applied random colors to ${result?.colorLights || 0} RGB lights and requested off for ${result?.nonColorEntities || 0} non-RGB lights.`
|
||||
: `Turned ${action} ${succeeded} room lights.`;
|
||||
const failureSuffix = failed ? ` ${failed} failed.` : '';
|
||||
await message.reply({
|
||||
content: sanitizeMentions(`${description}${failureSuffix}`),
|
||||
allowedMentions: { parse: [], repliedUser: false },
|
||||
});
|
||||
} catch (err) {
|
||||
await message.reply({
|
||||
content: sanitizeMentions(`Failed to update room lights: ${err.message}`),
|
||||
allowedMentions: { parse: [], repliedUser: false },
|
||||
});
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (action !== 'lock' && action !== 'unlock') {
|
||||
await message.reply({
|
||||
content: `Invalid lights command. Use \`${commandPrefix} lights lock\`, \`${commandPrefix} lights unlock\`, or \`${commandPrefix} lights status\`.`,
|
||||
content: `Invalid lights command. Use \`${commandPrefix} lights on\`, \`${commandPrefix} lights off\`, \`${commandPrefix} lights colors\`, \`${commandPrefix} lights lock\`, \`${commandPrefix} lights unlock\`, or \`${commandPrefix} lights status\`.`,
|
||||
allowedMentions: { parse: [], repliedUser: false },
|
||||
});
|
||||
return;
|
||||
|
||||
@@ -93,9 +93,10 @@ function createCommandHandlers(deps) {
|
||||
return;
|
||||
}
|
||||
// Actions in this set can change operational safety or access policy, so
|
||||
// lockdown mode narrows them from normal admins to lockdown admins. Room
|
||||
// light locking belongs here because it can force the physical room lights
|
||||
// on and disables ordinary Home Assistant room controls for everyone else.
|
||||
// lockdown mode narrows them from normal admins to lockdown admins. Lights
|
||||
// is included because its lock/unlock subcommands change room policy. Its
|
||||
// ordinary on/off/color actions are also intentionally restricted to a
|
||||
// lockdown admin while the entire server is in lockdown.
|
||||
const moderationActions = new Set(['lock', 'unlock', 'mode', 'goal', 'reason', 'verify', 'deter', 'lights', 'kick', 'lift', 'neato']);
|
||||
const isAccessModeCommand = commandDefinition?.permission === 'access-mode';
|
||||
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
// Scope: Supplies transport-neutral metadata; execution handlers remain focused on server operations.
|
||||
const CATEGORIES = {
|
||||
system: { title: 'System', names: ['help', 'status', 'replay', 'time-status'] },
|
||||
admin: { title: 'Admin', names: ['lock', 'unlock', 'mode', 'reason', 'goal', 'lights', 'kick', 'verify', 'deter'] },
|
||||
features: { title: 'Features', names: ['lift', 'neato'] },
|
||||
admin: { title: 'Admin', names: ['lock', 'unlock', 'mode', 'reason', 'goal', 'kick', 'verify', 'deter'] },
|
||||
features: { title: 'Features', names: ['lights', 'lift', 'neato'] },
|
||||
discord: { title: 'Discord', names: ['bridge'] },
|
||||
};
|
||||
|
||||
@@ -19,7 +19,18 @@ function buildCommandRegistry(prefix, timeCommand) {
|
||||
mode: { category: 'admin', summary: 'Change the server mode.', usage: [`${prefix} mode <open|turns|admin|lockdown>`], access: 'Admin', permission: 'admin' },
|
||||
reason: { category: 'admin', summary: 'Show, set, or clear the admin-mode reason.', usage: [`${prefix} reason [text|clear]`], access: 'Admin to change' },
|
||||
goal: { category: 'admin', summary: 'Show, set, or clear the global objective.', usage: [`${prefix} goal [text|clear]`], access: 'Admin to change' },
|
||||
lights: { category: 'admin', summary: 'Show or change the room-light lock.', usage: [`${prefix} lights <status|lock|unlock>`], access: 'Admin', permission: 'admin' },
|
||||
lights: {
|
||||
category: 'features',
|
||||
summary: 'Control room lights or manage the admin light lock.',
|
||||
usage: [
|
||||
`${prefix} lights <on|off|colors>`,
|
||||
`${prefix} lights <status|lock|unlock>`,
|
||||
],
|
||||
access: 'Light controls are public unless server access is restricted; lock controls require admin',
|
||||
permission: 'access-mode',
|
||||
requiredFeature: 'homeAssistant',
|
||||
unavailableLabel: 'Home Assistant',
|
||||
},
|
||||
kick: { category: 'admin', summary: 'Remove a user from their current rover.', usage: [`${prefix} kick <user> [reason]`], access: 'Admin', permission: 'admin' },
|
||||
verify: { category: 'admin', summary: 'List or remove verified identities.', usage: [`${prefix} verify list`, `${prefix} verify remove <identity>`], access: 'Lockdown admin', permission: 'lockdown-admin' },
|
||||
deter: { category: 'admin', summary: 'List, add, or remove identity deterrence.', usage: [`${prefix} deter list`, `${prefix} deter ban <identity>`, `${prefix} deter unban <identity>`], access: 'Lockdown admin', permission: 'lockdown-admin' },
|
||||
|
||||
Reference in New Issue
Block a user