summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2023-03-02 15:43:20 +0100
committerJordan Bracco <href@random.sh>2023-03-02 15:43:20 +0100
commite398b47b33681f167a070652368558caecc14a86 (patch)
tree0cc5e53d240fa20a4b18da33bd5f16b0731de7d9 /lib
parentVarious fixes, refs T77. (diff)
More fixes
Diffstat (limited to 'lib')
-rw-r--r--lib/irc.ex2
-rw-r--r--lib/nola/account.ex6
-rw-r--r--lib/nola/plugins.ex38
-rw-r--r--lib/plugins/base.ex16
4 files changed, 51 insertions, 11 deletions
diff --git a/lib/irc.ex b/lib/irc.ex
index 8d04d50..1592955 100644
--- a/lib/irc.ex
+++ b/lib/irc.ex
@@ -1,7 +1,7 @@
defmodule Nola.Irc do
require Logger
- def env(), do: Nola.env(:irc)
+ def env(), do: Nola.env(:irc, [])
def env(key, default \\ nil), do: Keyword.get(env(), key, default)
def send_message_as(account, network, channel, text, force_puppet \\ false) do
diff --git a/lib/nola/account.ex b/lib/nola/account.ex
index 47e46b8..70e9e40 100644
--- a/lib/nola/account.ex
+++ b/lib/nola/account.ex
@@ -236,16 +236,16 @@ defmodule Nola.Account do
if make_default, do: new_account(user), else: nil
end
- def new_account(nick) do
+ def new_account(%{nick: nick, network: server}) do
id = EntropyString.large_id()
:dets.insert(file("db"), {id, nick, EntropyString.token()})
+ :dets.insert(file("predicates"), {{server, {:nick, nick}}, id})
get(id)
end
- def new_account(%{nick: nick, network: server}) do
+ def new_account(nick) when is_binary(nick) do
id = EntropyString.large_id()
:dets.insert(file("db"), {id, nick, EntropyString.token()})
- :dets.insert(file("predicates"), {{server, {:nick, nick}}, id})
get(id)
end
diff --git a/lib/nola/plugins.ex b/lib/nola/plugins.ex
index b0c3ce3..7872cd6 100644
--- a/lib/nola/plugins.ex
+++ b/lib/nola/plugins.ex
@@ -1,6 +1,38 @@
defmodule Nola.Plugins do
require Logger
+ @builtins [
+ Nola.Plugins.Account,
+ Nola.Plugins.Alcoolog,
+ Nola.Plugins.AlcoologAnnouncer,
+ Nola.Plugins.Base,
+ Nola.Plugins.Boursorama,
+ Nola.Plugins.Buffer,
+ Nola.Plugins.Calc,
+ Nola.Plugins.Coronavirus,
+ Nola.Plugins.Correction,
+ Nola.Plugins.Dice,
+ Nola.Plugins.Finance,
+ Nola.Plugins.Gpt,
+ Nola.Plugins.KickRoulette,
+ Nola.Plugins.LastFm,
+ Nola.Plugins.Link,
+ Nola.PLugins.Logger,
+ Nola.Plugins.Preums,
+ Nola.Plugins.QuatreCentVingt,
+ Nola.Plugins.RadioFrance,
+ Nola.Plugins.Say,
+ Nola.Plugins.Script,
+ Nola.Plugins.Seen,
+ Nola.Plugins.Sms,
+ Nola.Plugins.Tell,
+ Nola.Plugins.Txt,
+ Nola.Plugins.Untappd,
+ Nola.Plugins.UserMention,
+ Nola.Plugins.WolframAlpha,
+ Nola.Plugins.YouTube,
+ ]
+
defmodule Supervisor do
use DynamicSupervisor
require Logger
@@ -11,7 +43,7 @@ defmodule Nola.Plugins do
def start_child(module, opts \\ []) do
Logger.info("Starting #{module}")
- spec = %{id: {__MODULE__,module}, start: {__MODULE__, :start_link, [module, opts]}, name: module, restart: :transient}
+ spec = %{id: {Nola.Plugins,module}, start: {Nola.Plugins, :start_link, [module, opts]}, name: module, restart: :transient}
case DynamicSupervisor.start_child(__MODULE__, spec) do
{:ok, _} = res -> res
:ignore ->
@@ -58,6 +90,10 @@ defmodule Nola.Plugins do
end
end
+ def declare_all_builtins do
+ for b <- @builtins, do: declare(b)
+ end
+
def start(module, opts \\ []) do
__MODULE__.Supervisor.start_child(module)
end
diff --git a/lib/plugins/base.ex b/lib/plugins/base.ex
index 0f2c7e5..1baf066 100644
--- a/lib/plugins/base.ex
+++ b/lib/plugins/base.ex
@@ -18,13 +18,17 @@ defmodule Nola.Plugins.Base do
def handle_info({:irc, :trigger, "plugins", msg = %{trigger: %{type: :bang, args: []}}}, _) do
enabled_string = Nola.Plugins.enabled()
- |> Enum.map(fn(mod) ->
- mod
- |> Macro.underscore()
- |> String.split("/", parts: :infinity)
- |> List.last()
- |> Enum.sort()
+ |> Enum.map(fn(string_or_module) ->
+ case string_or_module do
+ string when is_binary(string) -> string
+ module when is_atom(module) ->
+ module
+ |> Macro.underscore()
+ |> String.split("/", parts: :infinity)
+ |> List.last()
+ end
end)
+ |> Enum.sort()
|> Enum.join(", ")
msg.replyfun.("Enabled plugins: #{enabled_string}")
{:noreply, nil}