# Plugin settings

Declare settings, and the WebUI builds the form for you.

Plugins often need settings that users fill in for their own setup: an API key, a polling interval, the groups to watch… Put a `_conf_schema.json` in the plugin folder, and a matching form appears in the plugin's settings in the WebUI.

ShiritaiBot's plugin settings use the same format as AstrBot. If you're moving a plugin from AstrBot to ShiritaiBot, you can copy its JSON as it is.

## Declare settings

```json _conf_schema.json
{
  "api_key": {
    "type": "secret",
    "description": "API Key",
    "hint": "Get it from the weather service's console",
    "secret": true
  },
  "default_city": {
    "type": "string",
    "description": "Default city",
    "default": "London"
  },
  "unit": {
    "type": "string",
    "description": "Temperature unit",
    "options": ["c", "f"],
    "labels": ["Celsius", "Fahrenheit"],
    "default": "c"
  },
  "interval": {
    "type": "int",
    "description": "Refresh interval (seconds)",
    "slider": { "min": 60, "max": 3600, "step": 60 },
    "default": 600
  }
}
```

Each key is a setting's name, and its value describes the setting. The most common fields are `type`, `description`, `hint` and `default`, which set the setting's type, label, help text and default value.

Labels and help text can be given in each language, such as `"description": {"zh-CN": "默认城市", "en": "Default city"}`; see [Languages](https://shiritaibot.dev/en/docs/plugins#languages).

## Setting types

| type            | Description                                    | Default when `default` isn't set |
| --------------- | ---------------------------------------------- | -------------------------------- |
| `string`        | One line of text                               | `""`                             |
| `text`          | Several lines of text                          | `""`                             |
| `int`           | Whole number                                   | `0`                              |
| `float`         | Decimal number                                 | `0.0`                            |
| `bool`          | Switch                                         | `false`                          |
| `list`          | List of strings                                | `[]`                             |
| `object`        | A group of sub-settings, declared with `items` | Each sub-setting's default       |
| `dict`          | Free-form key-value pairs                      | `{}`                             |
| `template_list` | A list of entries added from templates         | `[]`                             |

Here's how to write an `object` field:

```json _conf_schema.json
{
  "advanced": {
    "type": "object",
    "description": "Advanced settings",
    "items": {
      "retries": { "type": "int", "description": "Retries", "default": 3 },
      "verbose": { "type": "bool", "description": "Verbose logging" }
    }
  }
}
```

To read `retries`, use `self.config["advanced"]["retries"]` (see below).

## Common options

| Option                             | Description                                                                                                                       |
| ---------------------------------- | --------------------------------------------------------------------------------------------------------------------------------- |
| `description`                      | The label shown on the form                                                                                                       |
| `hint`                             | Help text under the label; add `"obvious_hint": true` to make it stand out                                                        |
| `default`                          | The default value                                                                                                                 |
| `options` / `labels` / `subtitles` | Dropdown choices, their display names and their descriptions, matched up in order. A `list` with `options` becomes a multi-select |
| `slider`                           | Adds a slider to an `int` / `float`: `{"min": 0, "max": 10, "step": 1}`                                                           |
| `secret`                           | A secret field; see below                                                                                                         |
| `invisible`                        | Not shown on the form, but its value is kept; useful for data the plugin maintains itself                                         |
| `editor_mode` / `editor_language`  | Shows a code editor, for JSON, regular expressions and the like                                                                   |
| `minimum` / `maximum` / `pattern`  | Range and regular-expression checks; when a value fails them, the plugin doesn't load                                             |

`template_schema` for `dict` and `templates` for `template_list` work as in AstrBot. The `file` type isn't supported yet.

## Read settings

`self.config` is a dict of the defaults merged with the values the user entered:

```python main.py
class Weather(Plugin):
    async def initialize(self):
        self.city = self.config["default_city"]
        self.interval = self.config["interval"]
```

When the user saves the settings in the WebUI, the plugin reloads automatically and the new instance gets the new settings. So reading them in `initialize()` is enough; you don't need to watch for changes.

If the settings don't fit their definition (exceeding `maximum`, for example), the plugin doesn't load, and the plugin list shows which field is wrong.

## Secret fields

Fields with `"secret": true` (only for `string` or `list`) are stored encrypted, and the WebUI never shows a saved value.

What the plugin reads isn't the plain value but a reference like `secret:...`. Turn it into the real value with `resolve_secret()`:

```python main.py
async def initialize(self):
    self.api_key = await self.context.resolve_secret(self.config["api_key"])
```

**Once you have the plain value, use it only inside the plugin: don't log it, don't return it to the model, and don't put it in a subprocess's environment.**

## Change settings from code

A plugin can change its own settings and save them:

```python main.py
self.config["last_sync"] = "2026-11-03T09:00:00+08:00"
await self.config.save_config()
```

`save_config()` only saves; it doesn't reload the plugin, and the current instance keeps using this `self.config` object.

For data produced while running, rather than settings the user needs to see or change, [KV storage](https://shiritaibot.dev/en/docs/plugins/context#storage) is a better fit.

## Update your settings

When you upgrade a plugin, just edit `_conf_schema.json`. After a reload, new settings get their defaults, removed ones are dropped, and the values the user already entered stay as they are.
