Commander register api

talking about permissions, im working on the registering api for the Commander, and I wanted to ask for some general feedback: if it makes sense, if I might be missing something obvious, possible ideas for something to add, you name it.
interface Command {
name: string; // name of the command - used for finding command suggestions
description?: string; // OPTIONAL will shown when hovering over a command suggestion, and can also be seen listing the command by console
schema: string; // expression that constitutes the command - MUST start with command name, and have each Argument name separated by spaces, each starting with a $ (e.g. "sum $first $second")
args: Argument[]; // array of arguments present on the schema
roles: Roles[]; // array of any user roles that can execute this as defined in CONST.USER_ROLES (default ['GAMEMASTER'])
permissions: Permissions[]; // array of user permissions needed to execute this command as defined in CONST.USER_PERMISSIONS; requires ALL to execute (default [])
// ideally it should be any permissions needed by whatever the handler() and suggestions() functions are doing, but it can impose artificial restrictions too
anyPermission: boolean; // changes the permissions behavoir to be require ANY instead of ALL (default false)
handler: (...params: any) => any; // waht you actually wanted to
}
interface Argument {
name: string; //schema must have this name prefixed by a $, and this name will be used for the param sent to the handler function
type: ARGUMENT_TYPES; // defines what regex to use to get this argument from the command line input. string | number | boolean | raw
suggestions: () => Suggestion[]; // OPTIONAL should return an array of objects with a displayName - handler function should know how to handle these
};
interface Suggestion {
displayName: string;
}
enum ARGUMENT_TYPES {
NUMBER = 'number',
STRING = 'string',
BOOLEAN = 'boolean',
RAW = 'raw',
}
interface Command {
name: string; // name of the command - used for finding command suggestions
description?: string; // OPTIONAL will shown when hovering over a command suggestion, and can also be seen listing the command by console
schema: string; // expression that constitutes the command - MUST start with command name, and have each Argument name separated by spaces, each starting with a $ (e.g. "sum $first $second")
args: Argument[]; // array of arguments present on the schema
roles: Roles[]; // array of any user roles that can execute this as defined in CONST.USER_ROLES (default ['GAMEMASTER'])
permissions: Permissions[]; // array of user permissions needed to execute this command as defined in CONST.USER_PERMISSIONS; requires ALL to execute (default [])
// ideally it should be any permissions needed by whatever the handler() and suggestions() functions are doing, but it can impose artificial restrictions too
anyPermission: boolean; // changes the permissions behavoir to be require ANY instead of ALL (default false)
handler: (...params: any) => any; // waht you actually wanted to
}
interface Argument {
name: string; //schema must have this name prefixed by a $, and this name will be used for the param sent to the handler function
type: ARGUMENT_TYPES; // defines what regex to use to get this argument from the command line input. string | number | boolean | raw
suggestions: () => Suggestion[]; // OPTIONAL should return an array of objects with a displayName - handler function should know how to handle these
};
interface Suggestion {
displayName: string;
}
enum ARGUMENT_TYPES {
NUMBER = 'number',
STRING = 'string',
BOOLEAN = 'boolean',
RAW = 'raw',
}
C
ccjmk815d ago
So, if roles/permissions/anyPermission get merged into a single function, it would look something like this:
interface Command {
name: string;
description?: string;
schema: string;
args: Argument[];
canRunIt: () => boolean;
handler: (...params: any) => any;
}
(the rest)
interface Command {
name: string;
description?: string;
schema: string;
args: Argument[];
canRunIt: () => boolean;
handler: (...params: any) => any;
}
(the rest)
maybe I could send the same args to the canRunIt function like to handler, in case they want to allow/forbid depending on some command arg. Can't think of a use case, but if Im already parsing it for A, I can send it for B 🤷‍♂️
That's the most versatile option, but it's certainly a lot simpler for Commander to have user roles to compare or the like
Eh not sure if its easier or no. For me it's certainly easier to offload that, I just call the function, if it returns true, good, if not, don't show it, and voilá
C
Calego815d ago
True, I'm imagining a world where someone is going to want to do async permissions calls (which could be a pita)
C
ccjmk815d ago
on second thought about the params to the permissions func, if I want to send the args, I need to show them the function all the time, and forbit it after trying to run it. so I think its better to at least initially just be a () => boolean
C
Calego815d ago
Yeah that's unnecessary IMO. The handler can escape hatch out if it gets that far
C
ccjmk815d ago
yeah ofc.. this would all run inside a huge try-catch, and if anything smells funny I will just show a message and abort
C
Calego815d ago
Oh a callback would actually be simple for you... You could just filter using that cb as the return.
C
ccjmk815d ago
to filter command suggestions? yeah indeed
C
Calego815d ago
You will need to define when that check happens though, whether it's cached at load or when the user first opens the menu, etc. As long as you define it in the docs, whatever you pick will be powerful Changing lanes, the suggestion callback would benefit from having the current arguments, you could suggest different things based on the current input
C
ccjmk815d ago
I'll probably do it at module start, just before calling the commanderReady hook, comparing against the known list of commands, and then refresh it on any additional registration. oh that's good I thought of it like "this is supposed to be a Player Character, go and fetch all PCs", but you could even use one arg to puppet the others with some hocus pocus
Want results from more Discord servers?
Add your server
More Posts
Azgaars Blurry MapHey all. I'm taking a look at my importer for Azgaar's Fantasy Map Generator and wondering how I canccjmk overlaybut for what I wanted I think I *needed* to append it there so that I can overlay the whole screencliits very very early alpha demoMonarch APIAlright, adventurous ones: I have a Beta version of Monarch with the new components API! Manifest: compacted chat cardsModules create problems to solve problems... Today's problem: "When I roll an attack, it eats the whdragdrop shenneneginsRight now, a user can drag a spell onto their character sheet. I store that in a 'spell' array and leffect mini modulesI've gotten to the point where I'm confident in releasing a slurry of tiny no-config Active Effect rdamage application hooksNew 5e Hook ideas, gimme yer thoughts: `Hooks.call('Actor5e.preDamageApplied')` args: `damageAmounthook conventionsRegarding hooks, is the convention that _all_ `pre...` hooks are executed on the machine that initiaexpand arraysIs there a way to `expandObject` except for an Array?edit-owned-item-effectI've made an abomination. This hacks its way past the limitations surrounding editing effects on ownItem Pile feedbackSimple is king!effects to chat@badideasbureau is the `temporary` flag you look for in Effects to Chat a convention from somewhere 5e AEsI've been messing pretty heavily with some Active Effect assumptions and mechanisms in 5e. This is mhero creator ui feedbackI'm trying to refactor the abilities' tab on the hero creation room to accomodate Race ASIs, but I deffect mechanic searchingI need someone to check me on a null hypothesis I'm making. > There are no abilities in 5e RAW whicDialog shennaneginsTIL the button callbacks for `Dialog.prompt` and `Dialog.confirm` can be asynchronous. ```js const Advancement Hooks@kandashi @ccjmk and anyone else who is currently working on modules that would interact with the AdAPI doc topicsGive me some ideas for what areas of the foundry core API would benefit from a wiki documentation paDiscord Permission IssueOh, I think you also need a Typescript role