From 0f3edb52bcd34ef6e4c370b7cef0930352533cf6 Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Wed, 12 Aug 2020 15:27:07 -0700 Subject: [PATCH] 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 --- lib/plugin/plugin.ex | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/plugin/plugin.ex b/lib/plugin/plugin.ex index d56e33f..9ab04d8 100644 --- a/lib/plugin/plugin.ex +++ b/lib/plugin/plugin.ex @@ -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