za419 / CadenceBot

A Discord bot for Cadence Radio
MIT License
2 stars 1 forks source link

Provide a mechanism for a config override to overwrite an array #113

Open za419 opened 1 year ago

za419 commented 1 year ago

This is, in a way, related to #112, and could be considered an alternative to it (although I would not be opposed to doing both, as I think this is necessary either way)

Currently, an array in default-config will be merged through concatenation with an array in the override configuration. That's convenient, and I feel that it's a good default behavior - However, there are circumstances in which I can imagine an IA wanting to completely replace an array (for example, if deploying a bot not named "Cadence", it would be preferable to completely replace the default custom commands and autoselectable play channels).

Therefore, I think we should allow the override config file to specify when an array should be overwritten instead of concatenated.

In addition to the current syntax of providing an array ("key": [...]), which should continue to concatenate the arrays together, we should support one of the following syntaxes:

  1. {
    "key": {
        "overwrite": true,
        "values": [...]
    }
    }
  2. {
    "key": {
        "strategy": "overwrite",
        "values": [...]
    }
    }

Syntax 1 is a little more direct and slightly cleaner to implement, but it is less extensible than syntax 2 (which might allow us to provide new strategies in the future, such as a concatenateExcept sort of thing that allows an exceptions array to be removed).

If we go with syntax 1, we should permit overwrite to be false, and in syntax 2, we should allow the strategy to be set to concatenate. In both cases this would effectively be an extra-verbose way to state the default behavior.