applyCustomSettings

Changes a setting of a plugin, given both the names of the plugin and the setting, in string form.

This merely iterates the passed plugins and calls their IRCPlugin.setMemberByName

methods.

applyCustomSettings
(,
const string[] customSettings
)

Parameters

plugins IRCPlugin[]

Array of all IRCPlugins.

customSettings string[]

Array of custom settings to apply to plugins' own setting, in the string forms of "plugin.setting=value".

Return Value

Type: auto

true if no setting name mismatches occurred, false if it did.

Examples

@Settings static struct MyPluginSettings
{
    @Enabler bool enabled;

    string s;
    int i;
    float f;
    bool b;
    double d;
}

static final class MyPlugin : IRCPlugin
{
    MyPluginSettings myPluginSettings;

    override string name() const
    {
        return "myplugin";
    }

    mixin IRCPluginImpl;
}

IRCPluginState state;
IRCPlugin plugin = new MyPlugin(state);

auto newSettings =
[
    `myplugin.s="abc def ghi"`,
    "myplugin.i=42",
    "myplugin.f=3.14",
    "myplugin.b=true",
    "myplugin.d=99.99",
];

cast(void)applyCustomSettings([ plugin ], newSettings);

const ps = (cast(MyPlugin)plugin).myPluginSettings;

import std.conv : to;
import std.math : isClose;

assert((ps.s == "abc def ghi"), ps.s);
assert((ps.i == 42), ps.i.to!string);
assert(ps.f.isClose(3.14f), ps.f.to!string);
assert(ps.b);
assert(ps.d.isClose(99.99), ps.d.to!string);

See Also