Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement commands system #40

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

flakey5
Copy link

@flakey5 flakey5 commented Jan 2, 2025

As titled and described in the issues linked.

Opening this as a draft just to get feedback on the approach here before moving forward.

What's currently here:

  • Command manager
  • Permission checking
  • ptzplayaudio and ptzstopaudio commands for demonstration purposes

For the permission system, it's pretty similar to what's there now with two main differences:

  1. Individual users can be given permission to run an individual command
  2. Changed how which user is in which group was defined to be a map of user:group instead of group:users. This was just for a minor performance bump (object lookup vs array indexOf)

This does allow for more granular access to commands, but, it makes giving someone access to say all the ptz commands w/o adding them to a group kinda annoying since you'd need to add them to each of the command's permissions individually. A better approach to this might be having permission "nodes" similar to how Minecraft does it (and also might be what #34 is talking about here:

a permission for just preset access

?). Then, going back to the example of giving someone access to all the ptz commands, we can just make all the ptz commands take the permission node ptz-bla-bla-bla-something. Then in config.js we define which groups and individual users have a permission node. If a user has that permission node or the group they're in has that node, then they can run the command.

Closes #32
Closes #33
Closes #34

Closes alveusgg#32
Closes alveusgg#33
Closes alveusgg#34

Signed-off-by: flakey5 <[email protected]>
Comment on lines +83 to +93
const result = command.run({
controller: this.#controller,
channel,
user,
args,
msg
})

if (typeof result?.then === 'function') {
await result
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of this if, I think you could do await Promise.resolve(command.run(...))?

}

if (permission.group && user in groupMemberships) {
const userGroup = groupMemberships[user]
Copy link
Member

@MattIPv4 MattIPv4 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would think we'd want a user to be able to be in multiple groups (so we could have a group for full PTZ commands, a group for just the ptzload etc. commands, and so on)?

I think that might be an easier approach that having an intrinsic ranking to groups?

throw new TypeError(`${file}: expected enabled to be a boolean, got ${typeof command.enabled}`)
}

if (typeof command.permission !== 'undefined' && typeof command.permission === 'object') {
Copy link
Member

@MattIPv4 MattIPv4 Jan 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (typeof command.permission !== 'undefined' && typeof command.permission === 'object') {
if (typeof command.permission !== 'undefined' && typeof command.permission !== 'object') {
  • worth also checking the structure beyond that it is an obj?

/**
* @type {Array<import('./types.d.ts').Command>}
*/
const commands = aliases.map(alias => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the command structure should have an aliases prop (during the command loading you can generate an obj/map to do quick lookups) instead of us needing to create multiple identical objects for each alias (and having a single obj per command means we could more easily use the data to power the site commands list etc.)

@@ -496,6 +496,8 @@ class Axis {
*
* `controller.connections.cameras` is an object of Axis camera connections
*
* @typedef {Record<typeof config.axisCameras[number], Axis>} CamerasConnection
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A typedef inside the jsdoc for a func seems wrong?

@MattIPv4
Copy link
Member

MattIPv4 commented Jan 6, 2025

@dansza1 @wazix11 @spacevoyager03 @pjeweb would appreciate y'all taking a look at this draft as well and hearing any thoughts you have on it in terms of direction

@pjeweb
Copy link
Member

pjeweb commented Jan 6, 2025

@dansza1 @wazix11 @spacevoyager03 @pjeweb would appreciate y'all taking a look at this draft as well and hearing any thoughts you have on it in terms of direction

I think generally this is a good approach. I'm not the biggest fan of classes in JS but that is besides the point.

I have not thought about the permissions in depth yet, even though that seems to be one of the bigger points here. Maybe someone else can think that through ;)

There are a bunch of commands with shared code, sometimes only changing one var, like customcamstl, …tr etc. I think it would make sense to allow them as aliases of one command and pass the command name as a CommandArg.

Also I would probably move the alias mapping in to the command manager and define them in the exported config as an array or something.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove modules/legacy Implement permissions system Implement commands system
3 participants