Config Plugin
This plugin is built-in.
This plugin was added in Tennu v4.8.0
This plugin deals with everything configuration based.
When you instantiate a Tennu Client, you pass a configuration object
as the first parameter. It contains various required properties for the IRC
Socket (e.g. "server"
, "port"
) and values used to
configure plugins.
Static Hook: defaultConfig
Most of the time there is a sensible default for a plugin's config values. For example, the default of"!"
for the command-trigger
.
This static hook lets a plugin specify what the default value is.
This static hook takes an object where the keys are configuration values and
the values are the defaults to use.
For example, here is a Hello World plugin that exports a
!hello
command to say "Hello World!"
, but also takes
a configuration value "hello-noun"
to change "World"
to some other thing.
And now if we instantiate a Tennu Client without passing in a
"hello-thing"
configuration value, the plugin will default to
using "World"
.
config
export function
This plugin exports a config(configValue)
function for grabbing
values off of the configuration object. This function is available as a method
on the client object. It gives you the value on the config object.
This function can only give you values from the top level of the configuration object.
Tennu's Configuration Philosophy
This is the philosophy of configuration you should follow when writing plugins.
-
Do not make things configurable unless you or another user needs to actually configure it. Premature configuration leads to complicated code.
You can see this in the changelog where configuration values are added every once in awhile. Some of those configuration values were known as potentially useful earlier than when they were added, but without having somebody want them, they were left unimplemented.
- If a configuration value has a sensible default, default to it. There's no point requiring configuration when convention will do.
-
Do not have configuration values take objects of unrelated values. The
configDefaults
can only replace wholesale a value and theconfig
function can only take values from the top level of the configuration object.For example, say we wanted to modify the ending punctuation in the
!hello
command in the example earlier. Instead of having a configuration value of"hello"
that takes an object with properties"thing"
and"punctuation"
we would instead take configuration values"hello-thing"
and"hello-punctuation"
instead. -
Use names that will not clash with other plugins. The configuration
object is a shared namespace between all plugins (and the socket
constructor), and if you use general names, you can cause two plugins
to use the same configuration value for different reasons. This is why
the configuration value is called
"hello-thing"
instead of"thing"
in the earlier example.