From 9a3757655ef233ef0352d930f84066b475d19e8c Mon Sep 17 00:00:00 2001 From: Jordan Bracco Date: Sun, 11 Dec 2022 16:59:02 +0000 Subject: feat(base-plugin): list enabled plugins with `!plugins` --- lib/lsg_irc/base_plugin.ex | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'lib') diff --git a/lib/lsg_irc/base_plugin.ex b/lib/lsg_irc/base_plugin.ex index d5da532..ca2e8f3 100644 --- a/lib/lsg_irc/base_plugin.ex +++ b/lib/lsg_irc/base_plugin.ex @@ -12,9 +12,25 @@ defmodule LSG.IRC.BasePlugin do {:ok, _} = Registry.register(IRC.PubSub, "trigger:help", regopts) {:ok, _} = Registry.register(IRC.PubSub, "trigger:liquidrender", regopts) {:ok, _} = Registry.register(IRC.PubSub, "trigger:plugin", regopts) + {:ok, _} = Registry.register(IRC.PubSub, "trigger:plugins", regopts) {:ok, nil} end + def handle_info({:irc, :trigger, "plugins", msg = %{trigger: %{type: :bang, args: []}}}, _) do + enabled_string = IRC.Plugin.enabled() + |> Enum.map(fn(mod) -> + mod + |> Macro.underscore() + |> String.split("/", parts: :infinity) + |> List.last() + |> String.replace("_plugin", "") + |> Enum.sort() + end) + |> Enum.join(", ") + msg.replyfun.("Enabled plugins: #{enabled_string}") + {:noreply, nil} + end + def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :query, args: [plugin]}} = m}, _) do module = Module.concat([LSG.IRC, Macro.camelize(plugin<>"_plugin")]) with true <- Code.ensure_loaded?(module), -- cgit v1.2.3