decaprime / VampireCommandFramework

Framework for VRising mods to Easily build chat commands.
MIT License
5 stars 1 forks source link

Config system to support overrides and more. #11

Open decaprime opened 2 years ago

decaprime commented 2 years ago

Server operators will want to configure and modify aspects of VCF. Some simple examples are: Disabling a command, changing the adminOnly status of a command, or adding an alias. You could imagine more complete features like managing middleware, remapping to resolve conflicts, localizing commands, and updating more contextualized details/usage.

Simple worked example

Given this class from upcoming 0.6 release of LeadAHorseToWater

[CommandGroup("horse")]
public class HorseCommands
{
    [Command("whistle", description:"Sets the horse to you", adminOnly:true)
    public void Whistle(ICommandCtx ctx){/*...*/}
}

You should be able to canonically refer to this command as horse.whistle.

Let's say you want to set this to be a public command you could either run something like:

.vcf set command horse.whistle adminOnly false

or in a file like vcf.cfg

{
"horse.whistle.showAdmin" : false
}

Middleware

This will likely be split into it's own issue but ultimately could be handled by this system. Some considerations:

decaprime commented 2 years ago

While we're at it, how about support for manipulating any BepInEx.Configuration right out of the box. For example with LeadAHorseToWater Settings you could have some attribute or method to register the mods config command where like the above example you could then set up .horse config set DistanceRequired 12.

As this with above, these commands themselves should be configurable because I could readily imagine not trusting just anyone with adminauth on the server to be able to manipulate server config files.

aontas commented 4 months ago

I want to be able to tag a command with role(s) which can then be assigned to users. Ideally I'd like to have it somewhat configurable for mod users to manage, but want to be able to set up some general sensible defaults to start with.

Needs:

Wants:

Something like this would be good:

[CommandGroup("horse")]
public class HorseCommands
{
    [Command("whistle", description:"Sets the horse to you")]
    [CommandRole("user")]
    public void Whistle(ICommandCtx ctx){/*...*/}

    [Command("whistle", description:"Sets the horse to you")]
    [CommandRole("admin")]
    [CommandRole("poweruser")]
    public void AdminWhistle(ICommandCtx ctx){/*...*/}
}

Other

Currently, I am using a middleware in XPRising to manager permissions there. Middleware basically needs to have access to a database of users to "privilege" level and commands to "privilege" level and just compares the the number. This change would check to ensure that a user has the required role instead of some arbitrary number. I would expect that VCF would store files/database to manage the permissions so I don't have to manage basically the same config in every mod that I use this in.

aontas commented 4 months ago

It would also be great to have something that will generate a Commands.md file from the mod. I have some code that generates this: https://github.com/aontas/XPRising/blob/main/Command.md

Rianaid commented 4 months ago

Perhaps this option of adding configuration to commands will work. https://github.com/Rianaid/VampireCommandFramework/commit/bf26369d755327f6c291805d55cb34a5e4f26c32

aontas commented 4 months ago

That just seems to bind the configuration for the command to a file? I'm not sure that is what I am after.

Rianaid commented 4 months ago

That just seems to bind the configuration for the command to a file? I'm not sure that is what I am after.

Yes, this is for setting up commands. I just wanted to add this setting as stated at the beginning of the topic. I don’t understand how Middleware works, so I can’t yet offer a solution to your problem. I have roles in another solution but it is not compatible with VCF. I'm currently trying to figure out how to merge them together and see what Deca says.