diff options
author | Jordan Bracco <href@random.sh> | 2022-12-20 02:13:47 +0000 |
---|---|---|
committer | Jordan Bracco <href@random.sh> | 2022-12-20 19:29:41 +0100 |
commit | 70b9bba56f5319361ce5a7df5c489b9c0d6905ce (patch) | |
tree | f9b4438965f4c5e3e1f3a6129904cbb9a37047f2 /lib/nola_plugins/base_plugin.ex | |
parent | Update repo URL, refs T77. (diff) |
Rename to Nola
Summary:
Nola rename cont. pt. 2. Refs T77.
`find lib -name "*.ex" -type f | xargs sed -i '' 's/LSG/Nola/g'`
Nola rename, cont. pt. 3. Refs T77.
`s/:lsg/:nola/g`
Nola rename, cont. pt. 4. Refs T77.
Nola rename, cont. pt. 5. Refs T77. Configs.
find config -type f | xargs sed -i '' 's/LSG/Nola/g'
find config -type f | xargs sed -i '' 's/lsg/nola/g'
BREAKING CHANGE: Config keys switch from `:lsg` to `:nola`
Nola rename, the end. pt 6. Refs T77.
Nola rename: The Big Move, Refs T77
Update repo URL, refs T77.
Nola rename: Nola.Plugins, refs T77
Maniphest Tasks: T77
Differential Revision: https://phab.random.sh/D3
Diffstat (limited to 'lib/nola_plugins/base_plugin.ex')
-rw-r--r-- | lib/nola_plugins/base_plugin.ex | 131 |
1 files changed, 0 insertions, 131 deletions
diff --git a/lib/nola_plugins/base_plugin.ex b/lib/nola_plugins/base_plugin.ex deleted file mode 100644 index a2b9ffb..0000000 --- a/lib/nola_plugins/base_plugin.ex +++ /dev/null @@ -1,131 +0,0 @@ -defmodule Nola.IRC.BasePlugin do - - def irc_doc, do: nil - - def start_link() do - GenServer.start_link(__MODULE__, [], name: __MODULE__) - end - - def init([]) do - regopts = [plugin: __MODULE__] - {:ok, _} = Registry.register(IRC.PubSub, "trigger:version", regopts) - {: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([Nola.IRC, Macro.camelize(plugin<>"_plugin")]) - with true <- Code.ensure_loaded?(module), - pid when is_pid(pid) <- GenServer.whereis(module) - do - m.replyfun.("loaded, active: #{inspect(pid)}") - else - false -> m.replyfun.("not loaded") - nil -> - msg = case IRC.Plugin.get(module) do - :disabled -> "disabled" - {_, false, _} -> "disabled" - _ -> "not active" - end - m.replyfun.(msg) - end - {:noreply, nil} - end - - def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :plus, args: [plugin]}} = m}, _) do - module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")]) - with true <- Code.ensure_loaded?(module), - IRC.Plugin.switch(module, true), - {:ok, pid} <- IRC.Plugin.start(module) - do - m.replyfun.("started: #{inspect(pid)}") - else - false -> m.replyfun.("not loaded") - :ignore -> m.replyfun.("disabled or throttled") - {:error, _} -> m.replyfun.("start error") - end - {:noreply, nil} - end - - def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :tilde, args: [plugin]}} = m}, _) do - module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")]) - with true <- Code.ensure_loaded?(module), - pid when is_pid(pid) <- GenServer.whereis(module), - :ok <- GenServer.stop(pid), - {:ok, pid} <- IRC.Plugin.start(module) - do - m.replyfun.("restarted: #{inspect(pid)}") - else - false -> m.replyfun.("not loaded") - nil -> m.replyfun.("not active") - end - {:noreply, nil} - end - - - def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :minus, args: [plugin]}} = m}, _) do - module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")]) - with true <- Code.ensure_loaded?(module), - pid when is_pid(pid) <- GenServer.whereis(module), - :ok <- GenServer.stop(pid) - do - IRC.Plugin.switch(module, false) - m.replyfun.("stopped: #{inspect(pid)}") - else - false -> m.replyfun.("not loaded") - nil -> m.replyfun.("not active") - end - {:noreply, nil} - end - - def handle_info({:irc, :trigger, "liquidrender", m = %{trigger: %{args: args}}}, _) do - template = Enum.join(args, " ") - m.replyfun.(Tmpl.render(template, m)) - {:noreply, nil} - end - - def handle_info({:irc, :trigger, "help", m = %{trigger: %{type: :bang}}}, _) do - url = NolaWeb.Router.Helpers.irc_url(NolaWeb.Endpoint, :index, m.network, NolaWeb.format_chan(m.channel)) - m.replyfun.("-> #{url}") - {:noreply, nil} - end - - def handle_info({:irc, :trigger, "version", message = %{trigger: %{type: :bang}}}, _) do - {:ok, vsn} = :application.get_key(:nola, :vsn) - ver = List.to_string(vsn) - url = NolaWeb.Router.Helpers.irc_url(NolaWeb.Endpoint, :index) - elixir_ver = Application.started_applications() |> List.keyfind(:elixir, 0) |> elem(2) |> to_string() - otp_ver = :erlang.system_info(:system_version) |> to_string() |> String.trim() - system = :erlang.system_info(:system_architecture) |> to_string() - message.replyfun.([ - <<"🤖 I am a robot running", 2, "beautte, version #{ver}", 2, " — source: #{Nola.source_url()}">>, - "🦾 Elixir #{elixir_ver} #{otp_ver} on #{system}", - "👷♀️ Owner: href <href@random.sh>", - "🌍 Web interface: #{url}" - ]) - {:noreply, nil} - end - - def handle_info(msg, _) do - {:noreply, nil} - end - -end |