Add cfg/1 to Omnibot.Plugin macro

This allows getting a specific key from the configuration instead of
getting the full array. Allows for using this:

    cfg(:some_config)

instead of this:

    cfg()[:some_config]

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-08-12 15:27:07 -07:00
parent c1602065ae
commit 0f3edb52bc

View File

@@ -37,6 +37,10 @@ defmodule Omnibot.Plugin do
Omnibot.Plugin.CfgState.cfg(__MODULE__.CfgState)
end
def cfg(opt, default \\ nil) when unquote(opts[:include_base]) do
Keyword.get(cfg(), opt, default)
end
def state() when unquote(opts[:include_base]) do
Omnibot.Plugin.CfgState.state(__MODULE__.CfgState)
end