summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2022-12-20 02:13:47 +0000
committerJordan Bracco <href@random.sh>2022-12-20 19:29:41 +0100
commit70b9bba56f5319361ce5a7df5c489b9c0d6905ce (patch)
treef9b4438965f4c5e3e1f3a6129904cbb9a37047f2
parentUpdate 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
-rw-r--r--lib/nola/plugins.ex (renamed from lib/nola_irc/plugin_supervisor.ex)10
-rw-r--r--lib/nola_irc/account.ex188
-rw-r--r--lib/nola_irc/admin_handler.ex (renamed from lib/nola_plugins/admin_handler.ex)2
-rw-r--r--lib/nola_irc/nola_irc.ex8
-rw-r--r--lib/nola_plugins/README.md1
-rw-r--r--lib/nola_plugins/account.ex188
-rw-r--r--lib/nola_plugins/alcoolog.ex (renamed from lib/nola_plugins/alcolog_plugin.ex)24
-rw-r--r--lib/nola_plugins/alcoolog_announcer.ex (renamed from lib/nola_plugins/alcoolog_announcer_plugin.ex)7
-rw-r--r--lib/nola_plugins/base.ex (renamed from lib/nola_plugins/base_plugin.ex)27
-rw-r--r--lib/nola_plugins/boursorama.ex (renamed from lib/nola_plugins/bourosama_plugin.ex)2
-rw-r--r--lib/nola_plugins/buffer.ex (renamed from lib/nola_plugins/buffer_plugin.ex)2
-rw-r--r--lib/nola_plugins/calc.ex (renamed from lib/nola_plugins/calc_plugin.ex)2
-rw-r--r--lib/nola_plugins/coronavirus.ex (renamed from lib/nola_plugins/coronavirus_plugin.ex)2
-rw-r--r--lib/nola_plugins/correction.ex (renamed from lib/nola_plugins/correction_plugin.ex)2
-rw-r--r--lib/nola_plugins/dice.ex (renamed from lib/nola_plugins/dice_plugin.ex)2
-rw-r--r--lib/nola_plugins/finance.ex (renamed from lib/nola_plugins/finance_plugin.ex)2
-rw-r--r--lib/nola_plugins/gpt.ex (renamed from lib/nola_plugins/gpt_plugin.ex)6
-rw-r--r--lib/nola_plugins/helpers/temp_ref.ex (renamed from lib/nola_irc/plugin/temp_ref.ex)2
-rw-r--r--lib/nola_plugins/kick_roulette.ex (renamed from lib/nola_plugins/kick_roulette_plugin.ex)2
-rw-r--r--lib/nola_plugins/last_fm.ex (renamed from lib/nola_plugins/last_fm_plugin.ex)2
-rw-r--r--lib/nola_plugins/link.ex (renamed from lib/nola_plugins/link_plugin.ex)12
-rw-r--r--lib/nola_plugins/link/github.ex (renamed from lib/nola_plugins/link_plugin/github.ex)4
-rw-r--r--lib/nola_plugins/link/html.ex (renamed from lib/nola_plugins/link_plugin/html.ex)4
-rw-r--r--lib/nola_plugins/link/imgur.ex (renamed from lib/nola_plugins/link_plugin/imgur.ex)4
-rw-r--r--lib/nola_plugins/link/pdf.ex (renamed from lib/nola_plugins/link_plugin/pdf.ex)4
-rw-r--r--lib/nola_plugins/link/redacted.ex (renamed from lib/nola_plugins/link_plugin/redacted.ex)4
-rw-r--r--lib/nola_plugins/link/reddit.ex (renamed from lib/nola_plugins/link_plugin/reddit.ex)4
-rw-r--r--lib/nola_plugins/link/twitter.ex (renamed from lib/nola_plugins/link_plugin/twitter.ex)4
-rw-r--r--lib/nola_plugins/link/youtube.ex (renamed from lib/nola_plugins/link_plugin/youtube.ex)4
-rw-r--r--lib/nola_plugins/logger.ex (renamed from lib/nola_plugins/logger_plugin.ex)3
-rw-r--r--lib/nola_plugins/outline.ex (renamed from lib/nola_plugins/outline_plugin.ex)2
-rw-r--r--lib/nola_plugins/preums.ex (renamed from lib/nola_plugins/preums_plugin.ex)4
-rw-r--r--lib/nola_plugins/quatre_cent_vingt.ex (renamed from lib/nola_plugins/quatre_cent_vingt_plugin.ex)2
-rw-r--r--lib/nola_plugins/radio_france.ex (renamed from lib/nola_plugins/radio_france_plugin.ex)2
-rw-r--r--lib/nola_plugins/say.ex (renamed from lib/nola_plugins/say_plugin.ex)2
-rw-r--r--lib/nola_plugins/script.ex (renamed from lib/nola_plugins/script_plugin.ex)2
-rw-r--r--lib/nola_plugins/seen.ex (renamed from lib/nola_plugins/seen_plugin.ex)2
-rw-r--r--lib/nola_plugins/sms.ex (renamed from lib/nola_plugins/sms_plugin.ex)2
-rw-r--r--lib/nola_plugins/tell.ex (renamed from lib/nola_plugins/tell_plugin.ex)2
-rw-r--r--lib/nola_plugins/txt.ex (renamed from lib/nola_plugins/txt_plugin.ex)4
-rw-r--r--lib/nola_plugins/txt/markov.ex (renamed from lib/nola_plugins/txt_plugin/markov.ex)2
-rw-r--r--lib/nola_plugins/txt/markov_native.ex (renamed from lib/nola_plugins/txt_plugin/markov_native.ex)4
-rw-r--r--lib/nola_plugins/txt/markov_py_markovify.ex (renamed from lib/nola_plugins/txt_plugin/markov_py_markovify.ex)6
-rw-r--r--lib/nola_plugins/untappd.ex (renamed from lib/nola_plugins/untappd_plugin.ex)2
-rw-r--r--lib/nola_plugins/user_mention.ex (renamed from lib/nola_plugins/user_mention_plugin.ex)6
-rw-r--r--lib/nola_plugins/wikipedia.ex (renamed from lib/nola_plugins/wikipedia_plugin.ex)2
-rw-r--r--lib/nola_plugins/wolfram_alpha.ex (renamed from lib/nola_plugins/wolfram_alpha_plugin.ex)2
-rw-r--r--lib/nola_plugins/youtube.ex (renamed from lib/nola_plugins/youtube_plugin.ex)2
-rw-r--r--lib/nola_web/controllers/alcoolog_controller.ex28
-rw-r--r--lib/nola_web/controllers/gpt_controller.ex4
-rw-r--r--lib/nola_web/controllers/irc_controller.ex6
-rw-r--r--lib/nola_web/controllers/sms_controller.ex2
-rw-r--r--lib/nola_web/live/chat_live.ex2
53 files changed, 310 insertions, 310 deletions
diff --git a/lib/nola_irc/plugin_supervisor.ex b/lib/nola/plugins.ex
index a65ad09..4b55f4c 100644
--- a/lib/nola_irc/plugin_supervisor.ex
+++ b/lib/nola/plugins.ex
@@ -1,4 +1,4 @@
-defmodule IRC.Plugin do
+defmodule Nola.Plugins do
require Logger
defmodule Supervisor do
@@ -11,7 +11,7 @@ defmodule IRC.Plugin do
def start_child(module, opts \\ []) do
Logger.info("Starting #{module}")
- spec = %{id: {IRC.Plugin,module}, start: {IRC.Plugin, :start_link, [module, opts]}, name: module, restart: :transient}
+ spec = %{id: {__MODULE__,module}, start: {__MODULE__, :start_link, [module, opts]}, name: module, restart: :transient}
case DynamicSupervisor.start_child(__MODULE__, spec) do
{:ok, _} = res -> res
:ignore ->
@@ -47,7 +47,7 @@ defmodule IRC.Plugin do
end
def start_all() do
- for mod <- enabled(), do: {mod, IRC.Plugin.Supervisor.start_child(mod)}
+ for mod <- enabled(), do: {mod, __MODULE__.Supervisor.start_child(mod)}
end
def declare(module) do
@@ -58,7 +58,7 @@ defmodule IRC.Plugin do
end
def start(module, opts \\ []) do
- IRC.Plugin.Supervisor.start_child(module)
+ __MODULE__.Supervisor.start_child(module)
end
@doc "Enables a plugin"
@@ -91,7 +91,7 @@ defmodule IRC.Plugin do
module.start_link()
else
{error, _} ->
- Logger.info("Plugin: #{to_string(module)} ignored start: #{to_string(error)}")
+ Logger.info("#{__MODULE__}: #{to_string(module)} ignored start: #{to_string(error)}")
:ignore
end
end
diff --git a/lib/nola_irc/account.ex b/lib/nola_irc/account.ex
index 45680f8..a39733c 100644
--- a/lib/nola_irc/account.ex
+++ b/lib/nola_irc/account.ex
@@ -260,192 +260,4 @@ defmodule IRC.Account do
:dets.select(file("predicates"), spec)
end
- defmodule AccountPlugin do
- @moduledoc """
- # Account
-
- * **account** Get current account id and token
- * **auth `<account-id>` `<token>`** Authenticate and link the current nickname to an account
- * **auth** list authentications methods
- * **whoami** list currently authenticated users
- * **web** get a one-time login link to web
- * **enable-telegram** Link a Telegram account
- * **enable-sms** Link a SMS number
- * **enable-untappd** Link a Untappd account
- * **set-name** set account name
- * **setusermeta puppet-nick `<nick>`** Set puppet IRC nickname
- """
-
- def irc_doc, do: @moduledoc
- def start_link(), do: GenServer.start_link(__MODULE__, [], name: __MODULE__)
- def init(_) do
- {:ok, _} = Registry.register(IRC.PubSub, "messages:private", [])
- {:ok, nil}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "help"}}, state) do
- text = [
- "account: show current account and auth token",
- "auth: show authentications methods",
- "whoami: list authenticated users",
- "set-name <name>: set account name",
- "web: login to web",
- "enable-sms | disable-sms: enable/change or disable sms",
- "enable-telegram: link/change telegram",
- "enable-untappd: link untappd account",
- "getmeta: show meta datas",
- "setusermeta: set user meta",
- ]
- m.replyfun.(text)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "auth"}}, state) do
- spec = [{{:"$1", :"$2"}, [{:==, :"$2", {:const, account.id}}], [:"$1"]}]
- predicates = :dets.select(IRC.Account.file("predicates"), spec)
- text = for {net, {key, value}} <- predicates, do: "#{net}: #{to_string(key)}: #{value}"
- m.replyfun.(text)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "whoami"}}, state) do
- users = for user <- IRC.UserTrack.find_by_account(m.account) do
- chans = Enum.map(user.privileges, fn({chan, _}) -> chan end)
- |> Enum.join(" ")
- "#{user.network} - #{user.nick}!#{user.username}@#{user.host} - #{chans}"
- end
- m.replyfun.(users)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "account"}}, state) do
- account = IRC.Account.lookup(m.sender)
- text = ["Account Id: #{account.id}",
- "Authenticate to this account from another network: \"auth #{account.id} #{account.token}\" to the other bot!"]
- m.replyfun.(text)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{sender: sender, text: "auth"<>_}}, state) do
- #account = IRC.Account.lookup(m.sender)
- case String.split(m.text, " ") do
- ["auth", id, token] ->
- join_account(m, id, token)
- _ ->
- m.replyfun.("Invalid parameters")
- end
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "set-name "<>name}}, state) do
- IRC.Account.update_account_name(account, name)
- m.replyfun.("Name changed: #{name}")
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "disable-sms"}}, state) do
- if IRC.Account.get_meta(m.account, "sms-number") do
- IRC.Account.delete_meta(m.account, "sms-number")
- m.replfyun.("SMS disabled.")
- else
- m.replyfun.("SMS already disabled.")
- end
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "web"}}, state) do
- auth_url = Untappd.auth_url()
- login_url = Nola.AuthToken.new_url(m.account.id, nil)
- m.replyfun.("-> " <> login_url)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "enable-sms"}}, state) do
- code = String.downcase(EntropyString.small_id())
- IRC.Account.put_meta(m.account, "sms-validation-code", code)
- IRC.Account.put_meta(m.account, "sms-validation-target", m.network)
- number = Nola.IRC.SmsPlugin.my_number()
- text = "To enable or change your number for SMS messaging, please send:"
- <> " \"enable #{code}\" to #{number}"
- m.replyfun.(text)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "enable-telegram"}}, state) do
- code = String.downcase(EntropyString.small_id())
- IRC.Account.delete_meta(m.account, "telegram-id")
- IRC.Account.put_meta(m.account, "telegram-validation-code", code)
- IRC.Account.put_meta(m.account, "telegram-validation-target", m.network)
- text = "To enable or change your number for telegram messaging, please open #{Nola.Telegram.my_path()} and send:"
- <> " \"/enable #{code}\""
- m.replyfun.(text)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "enable-untappd"}}, state) do
- auth_url = Untappd.auth_url()
- login_url = Nola.AuthToken.new_url(m.account.id, {:external_redirect, auth_url})
- m.replyfun.(["To link your Untappd account, open this URL:", login_url])
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "getmeta"<>_}}, state) do
- result = case String.split(m.text, " ") do
- ["getmeta"] ->
- for {k, v} <- IRC.Account.get_all_meta(m.account) do
- case k do
- "u:"<>key -> "(user) #{key}: #{v}"
- key -> "#{key}: #{v}"
- end
- end
- ["getmeta", key] ->
- value = IRC.Account.get_meta(m.account, key)
- text = if value do
- "#{key}: #{value}"
- else
- "#{key} is not defined"
- end
- _ ->
- "usage: getmeta [key]"
- end
- m.replyfun.(result)
- {:noreply, state}
- end
-
- def handle_info({:irc, :text, m = %IRC.Message{text: "setusermet"<>_}}, state) do
- result = case String.split(m.text, " ") do
- ["setusermeta", key, value] ->
- IRC.Account.put_user_meta(m.account, key, value)
- "ok"
- _ ->
- "usage: setusermeta <key> <value>"
- end
- m.replyfun.(result)
- {:noreply, state}
- end
-
- def handle_info(_, state) do
- {:noreply, state}
- end
-
- defp join_account(m, id, token) do
- old_account = IRC.Account.lookup(m.sender)
- new_account = IRC.Account.get(id)
- if new_account && token == new_account.token do
- case IRC.Account.merge_account(old_account.id, new_account.id) do
- :ok ->
- if old_account.id == new_account.id do
- m.replyfun.("Already authenticated, but hello")
- else
- m.replyfun.("Accounts merged!")
- end
- _ -> m.replyfun.("Something failed :(")
- end
- else
- m.replyfun.("Invalid token")
- end
- end
-
- end
-
end
diff --git a/lib/nola_plugins/admin_handler.ex b/lib/nola_irc/admin_handler.ex
index 9a5d557..282f3c2 100644
--- a/lib/nola_plugins/admin_handler.ex
+++ b/lib/nola_irc/admin_handler.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.AdminHandler do
+defmodule Nola.Irc.AdminHandler do
@moduledoc """
# admin
diff --git a/lib/nola_irc/nola_irc.ex b/lib/nola_irc/nola_irc.ex
index f64978a..870b99d 100644
--- a/lib/nola_irc/nola_irc.ex
+++ b/lib/nola_irc/nola_irc.ex
@@ -8,7 +8,7 @@ defmodule Nola.IRC do
import Supervisor.Spec
IRC.Connection.setup()
- IRC.Plugin.setup()
+ Nola.Plugins.setup()
[
worker(Registry, [[keys: :duplicate, name: IRC.ConnectionPubSub]], id: :registr_irc_conn),
@@ -16,8 +16,8 @@ defmodule Nola.IRC do
worker(IRC.Membership, []),
worker(IRC.Account, []),
worker(IRC.UserTrack.Storage, []),
- worker(IRC.Account.AccountPlugin, []),
- supervisor(IRC.Plugin.Supervisor, [], [name: IRC.Plugin.Supervisor]),
+ worker(Nola.Plugins.Account, []),
+ supervisor(Nola.Plugins.Supervisor, [], [name: Nola.Plugins.Supervisor]),
supervisor(IRC.Connection.Supervisor, [], [name: IRC.Connection.Supervisor]),
supervisor(IRC.PuppetConnection.Supervisor, [], [name: IRC.PuppetConnection.Supervisor]),
]
@@ -26,7 +26,7 @@ defmodule Nola.IRC do
# Start plugins first to let them get on connection events.
def after_start() do
Logger.info("Starting plugins")
- IRC.Plugin.start_all()
+ Nola.Plugins.start_all()
Logger.info("Starting connections")
IRC.Connection.start_all()
end
diff --git a/lib/nola_plugins/README.md b/lib/nola_plugins/README.md
new file mode 100644
index 0000000..82adba8
--- /dev/null
+++ b/lib/nola_plugins/README.md
@@ -0,0 +1 @@
+## Nola Plugins directory
diff --git a/lib/nola_plugins/account.ex b/lib/nola_plugins/account.ex
new file mode 100644
index 0000000..c11d077
--- /dev/null
+++ b/lib/nola_plugins/account.ex
@@ -0,0 +1,188 @@
+defmodule Nola.Plugins.Account do
+ @moduledoc """
+ # Account
+
+ * **account** Get current account id and token
+ * **auth `<account-id>` `<token>`** Authenticate and link the current nickname to an account
+ * **auth** list authentications methods
+ * **whoami** list currently authenticated users
+ * **web** get a one-time login link to web
+ * **enable-telegram** Link a Telegram account
+ * **enable-sms** Link a SMS number
+ * **enable-untappd** Link a Untappd account
+ * **set-name** set account name
+ * **setusermeta puppet-nick `<nick>`** Set puppet IRC nickname
+ """
+
+ def irc_doc, do: @moduledoc
+ def start_link(), do: GenServer.start_link(__MODULE__, [], name: __MODULE__)
+ def init(_) do
+ {:ok, _} = Registry.register(IRC.PubSub, "messages:private", [])
+ {:ok, nil}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "help"}}, state) do
+ text = [
+ "account: show current account and auth token",
+ "auth: show authentications methods",
+ "whoami: list authenticated users",
+ "set-name <name>: set account name",
+ "web: login to web",
+ "enable-sms | disable-sms: enable/change or disable sms",
+ "enable-telegram: link/change telegram",
+ "enable-untappd: link untappd account",
+ "getmeta: show meta datas",
+ "setusermeta: set user meta",
+ ]
+ m.replyfun.(text)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "auth"}}, state) do
+ spec = [{{:"$1", :"$2"}, [{:==, :"$2", {:const, account.id}}], [:"$1"]}]
+ predicates = :dets.select(IRC.Account.file("predicates"), spec)
+ text = for {net, {key, value}} <- predicates, do: "#{net}: #{to_string(key)}: #{value}"
+ m.replyfun.(text)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "whoami"}}, state) do
+ users = for user <- IRC.UserTrack.find_by_account(m.account) do
+ chans = Enum.map(user.privileges, fn({chan, _}) -> chan end)
+ |> Enum.join(" ")
+ "#{user.network} - #{user.nick}!#{user.username}@#{user.host} - #{chans}"
+ end
+ m.replyfun.(users)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "account"}}, state) do
+ account = IRC.Account.lookup(m.sender)
+ text = ["Account Id: #{account.id}",
+ "Authenticate to this account from another network: \"auth #{account.id} #{account.token}\" to the other bot!"]
+ m.replyfun.(text)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{sender: sender, text: "auth"<>_}}, state) do
+ #account = IRC.Account.lookup(m.sender)
+ case String.split(m.text, " ") do
+ ["auth", id, token] ->
+ join_account(m, id, token)
+ _ ->
+ m.replyfun.("Invalid parameters")
+ end
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{account: account, text: "set-name "<>name}}, state) do
+ IRC.Account.update_account_name(account, name)
+ m.replyfun.("Name changed: #{name}")
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "disable-sms"}}, state) do
+ if IRC.Account.get_meta(m.account, "sms-number") do
+ IRC.Account.delete_meta(m.account, "sms-number")
+ m.replfyun.("SMS disabled.")
+ else
+ m.replyfun.("SMS already disabled.")
+ end
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "web"}}, state) do
+ auth_url = Untappd.auth_url()
+ login_url = Nola.AuthToken.new_url(m.account.id, nil)
+ m.replyfun.("-> " <> login_url)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "enable-sms"}}, state) do
+ code = String.downcase(EntropyString.small_id())
+ IRC.Account.put_meta(m.account, "sms-validation-code", code)
+ IRC.Account.put_meta(m.account, "sms-validation-target", m.network)
+ number = Nola.IRC.Sms.my_number()
+ text = "To enable or change your number for SMS messaging, please send:"
+ <> " \"enable #{code}\" to #{number}"
+ m.replyfun.(text)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "enable-telegram"}}, state) do
+ code = String.downcase(EntropyString.small_id())
+ IRC.Account.delete_meta(m.account, "telegram-id")
+ IRC.Account.put_meta(m.account, "telegram-validation-code", code)
+ IRC.Account.put_meta(m.account, "telegram-validation-target", m.network)
+ text = "To enable or change your number for telegram messaging, please open #{Nola.Telegram.my_path()} and send:"
+ <> " \"/enable #{code}\""
+ m.replyfun.(text)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "enable-untappd"}}, state) do
+ auth_url = Untappd.auth_url()
+ login_url = Nola.AuthToken.new_url(m.account.id, {:external_redirect, auth_url})
+ m.replyfun.(["To link your Untappd account, open this URL:", login_url])
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "getmeta"<>_}}, state) do
+ result = case String.split(m.text, " ") do
+ ["getmeta"] ->
+ for {k, v} <- IRC.Account.get_all_meta(m.account) do
+ case k do
+ "u:"<>key -> "(user) #{key}: #{v}"
+ key -> "#{key}: #{v}"
+ end
+ end
+ ["getmeta", key] ->
+ value = IRC.Account.get_meta(m.account, key)
+ text = if value do
+ "#{key}: #{value}"
+ else
+ "#{key} is not defined"
+ end
+ _ ->
+ "usage: getmeta [key]"
+ end
+ m.replyfun.(result)
+ {:noreply, state}
+ end
+
+ def handle_info({:irc, :text, m = %IRC.Message{text: "setusermeta"<>_}}, state) do
+ result = case String.split(m.text, " ") do
+ ["setusermeta", key, value] ->
+ IRC.Account.put_user_meta(m.account, key, value)
+ "ok"
+ _ ->
+ "usage: setusermeta <key> <value>"
+ end
+ m.replyfun.(result)
+ {:noreply, state}
+ end
+
+ def handle_info(_, state) do
+ {:noreply, state}
+ end
+
+ defp join_account(m, id, token) do
+ old_account = IRC.Account.lookup(m.sender)
+ new_account = IRC.Account.get(id)
+ if new_account && token == new_account.token do
+ case IRC.Account.merge_account(old_account.id, new_account.id) do
+ :ok ->
+ if old_account.id == new_account.id do
+ m.replyfun.("Already authenticated, but hello")
+ else
+ m.replyfun.("Accounts merged!")
+ end
+ _ -> m.replyfun.("Something failed :(")
+ end
+ else
+ m.replyfun.("Invalid token")
+ end
+ end
+
+ end
+
diff --git a/lib/nola_plugins/alcolog_plugin.ex b/lib/nola_plugins/alcoolog.ex
index 145e4fc..7f44ca2 100644
--- a/lib/nola_plugins/alcolog_plugin.ex
+++ b/lib/nola_plugins/alcoolog.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.AlcoologPlugin do
+defmodule Nola.Plugins.Alcoolog do
require Logger
@moduledoc """
@@ -102,7 +102,7 @@ defmodule Nola.IRC.AlcoologPlugin do
@eau ["santo", "santeau"]
def handle_info({:irc, :trigger, santeau, m = %IRC.Message{trigger: %IRC.Trigger{args: _, type: :bang}}}, state) when santeau in @eau do
- Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.santo")
+ Nola.Plugins.Txt.reply_random(m, "alcoolog.santo")
{:noreply, state}
end
@@ -330,9 +330,9 @@ defmodule Nola.IRC.AlcoologPlugin do
cond do
cl == nil -> m.replyfun.(cl_extra)
deg == nil -> m.replyfun.(comment)
- cl >= 500 || deg >= 100 -> Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_toohuge")
- cl == 0 || deg == 0 -> Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_zero")
- cl < 0 || deg < 0 -> Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.drink_negative")
+ cl >= 500 || deg >= 100 -> Nola.Plugins.Txt.reply_random(m, "alcoolog.drink_toohuge")
+ cl == 0 || deg == 0 -> Nola.Plugins.Txt.reply_random(m, "alcoolog.drink_zero")
+ cl < 0 || deg < 0 -> Nola.Plugins.Txt.reply_random(m, "alcoolog.drink_negative")
true ->
points = Alcool.units(cl, deg)
now = m.at || DateTime.utc_now()
@@ -347,7 +347,7 @@ defmodule Nola.IRC.AlcoologPlugin do
:ok = :dets.insert(state.dets, {m.account.id, now, points, if(old_stats, do: old_stats.active, else: 0), cl, deg, name, comment, meta})
true = :ets.insert(state.ets, {{m.account.id, now}, points, if(old_stats, do: old_stats.active, else: 0),cl, deg, name, comment, meta})
#sante = @santai |> Enum.map(fn(s) -> String.trim(String.upcase(s)) end) |> Enum.shuffle() |> Enum.random()
- sante = Nola.IRC.TxtPlugin.random("alcoolog.santai")
+ sante = Nola.Plugins.Txt.random("alcoolog.santai")
k = if user_meta.sex, do: 0.7, else: 0.6
weight = user_meta.weight
peak = Float.round((10*points||0.0)/(k*weight), 4)
@@ -449,7 +449,7 @@ defmodule Nola.IRC.AlcoologPlugin do
end
if miss do
- miss = Nola.IRC.TxtPlugin.random("alcoolog.#{to_string(miss)}")
+ miss = Nola.Plugins.Txt.random("alcoolog.#{to_string(miss)}")
if miss do
for {net, chan} <- IRC.Membership.notify_channels(m.account) do
user = IRC.UserTrack.find_by_account(net, m.account)
@@ -532,7 +532,7 @@ defmodule Nola.IRC.AlcoologPlugin do
rising_file_key = if rising, do: "_rising", else: ""
txt_file = "alcoolog." <> "user_" <> to_string(user_state) <> rising_file_key
- user_status = Nola.IRC.TxtPlugin.random(txt_file)
+ user_status = Nola.Plugins.Txt.random(txt_file)
meta = get_user_meta(state, nick)
minutes_til_sober = h1/((meta.loss_factor/100)/60)
@@ -831,11 +831,11 @@ defmodule Nola.IRC.AlcoologPlugin do
put_user_meta(state, m.account.id, meta)
cond do
old_meta.weight < meta.weight ->
- Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.fatter")
+ Nola.Plugins.Txt.reply_random(m, "alcoolog.fatter")
old_meta.weight == meta.weight ->
m.replyfun.("aucun changement!")
true ->
- Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.thinner")
+ Nola.Plugins.Txt.reply_random(m, "alcoolog.thinner")
end
end
@@ -848,7 +848,7 @@ defmodule Nola.IRC.AlcoologPlugin do
:dets.delete_object(state.dets, obj)
:ets.delete(state.ets, {m.account.id, date})
m.replyfun.("supprimΓ©: #{m.sender.nick} #{points} #{type} #{descr}")
- Nola.IRC.TxtPlugin.reply_random(m, "alcoolog.delete")
+ Nola.Plugins.Txt.reply_random(m, "alcoolog.delete")
notify = IRC.Membership.notify_channels(m.account) -- [{m.network,m.channel}]
for {net, chan} <- notify do
user = IRC.UserTrack.find_by_account(net, m.account)
@@ -995,7 +995,7 @@ defmodule Nola.IRC.AlcoologPlugin do
end
def handle_info(t, state) do
- Logger.debug("AlcoologPlugin: unhandled info #{inspect t}")
+ Logger.debug("#{__MODULE__}: unhandled info #{inspect t}")
{:noreply, state}
end
diff --git a/lib/nola_plugins/alcoolog_announcer_plugin.ex b/lib/nola_plugins/alcoolog_announcer.ex
index f90dc42..674f19b 100644
--- a/lib/nola_plugins/alcoolog_announcer_plugin.ex
+++ b/lib/nola_plugins/alcoolog_announcer.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.AlcoologAnnouncerPlugin do
+defmodule Nola.Plugins.AlcoologAnnouncer do
require Logger
@moduledoc """
@@ -52,9 +52,6 @@ defmodule Nola.IRC.AlcoologAnnouncerPlugin do
dets_filename = (Nola.data_path() <> "/" <> "alcoologlog.dets") |> String.to_charlist
{:ok, dets} = :dets.open_file(dets_filename, [{:type,:bag}])
ets = nil # :ets.new(__MODULE__.ETS, [:ordered_set, :named_table, :protected, {:read_concurrency, true}])
- #:ok = Nola.IRC.SettingPlugin.declare("alcoolog.alerts", __MODULE__, true, :boolean)
- #:ok = Nola.IRC.SettingPlugin.declare("alcoolog.aperoalert", __MODULE__, true, :boolean)
- #
{:ok, {stats, now(), dets, ets}}#, {:continue, :traverse}}
end
@@ -262,7 +259,7 @@ defmodule Nola.IRC.AlcoologAnnouncerPlugin do
end
defp get_stats() do
- Enum.into(Nola.IRC.AlcoologPlugin.get_all_stats(), %{})
+ Enum.into(Nola.Plugins.Alcoolog.get_all_stats(), %{})
end
defp timer() do
diff --git a/lib/nola_plugins/base_plugin.ex b/lib/nola_plugins/base.ex
index a2b9ffb..b7b5e16 100644
--- a/lib/nola_plugins/base_plugin.ex
+++ b/lib/nola_plugins/base.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.BasePlugin do
+defmodule Nola.Plugins.Base do
def irc_doc, do: nil
@@ -17,13 +17,12 @@ defmodule Nola.IRC.BasePlugin do
end
def handle_info({:irc, :trigger, "plugins", msg = %{trigger: %{type: :bang, args: []}}}, _) do
- enabled_string = IRC.Plugin.enabled()
+ enabled_string = Nola.Plugins.enabled()
|> Enum.map(fn(mod) ->
mod
|> Macro.underscore()
|> String.split("/", parts: :infinity)
|> List.last()
- |> String.replace("_plugin", "")
|> Enum.sort()
end)
|> Enum.join(", ")
@@ -32,7 +31,7 @@ defmodule Nola.IRC.BasePlugin do
end
def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :query, args: [plugin]}} = m}, _) do
- module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")])
+ module = Module.concat([Nola.Plugins, Macro.camelize(plugin)])
with true <- Code.ensure_loaded?(module),
pid when is_pid(pid) <- GenServer.whereis(module)
do
@@ -40,7 +39,7 @@ defmodule Nola.IRC.BasePlugin do
else
false -> m.replyfun.("not loaded")
nil ->
- msg = case IRC.Plugin.get(module) do
+ msg = case Nola.Plugins.get(module) do
:disabled -> "disabled"
{_, false, _} -> "disabled"
_ -> "not active"
@@ -51,10 +50,10 @@ defmodule Nola.IRC.BasePlugin do
end
def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :plus, args: [plugin]}} = m}, _) do
- module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")])
+ module = Module.concat([Nola.Plugins, Macro.camelize(plugin)])
with true <- Code.ensure_loaded?(module),
- IRC.Plugin.switch(module, true),
- {:ok, pid} <- IRC.Plugin.start(module)
+ Nola.Plugins.switch(module, true),
+ {:ok, pid} <- Nola.Plugins.start(module)
do
m.replyfun.("started: #{inspect(pid)}")
else
@@ -66,11 +65,11 @@ defmodule Nola.IRC.BasePlugin do
end
def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :tilde, args: [plugin]}} = m}, _) do
- module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")])
+ module = Module.concat([Nola.Plugins, Macro.camelize(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)
+ {:ok, pid} <- Nola.Plugins.start(module)
do
m.replyfun.("restarted: #{inspect(pid)}")
else
@@ -82,7 +81,7 @@ defmodule Nola.IRC.BasePlugin do
def handle_info({:irc, :trigger, "plugin", %{trigger: %{type: :minus, args: [plugin]}} = m}, _) do
- module = Module.concat([Nola.IRC, Macro.camelize(plugin<>"_plugin")])
+ module = Module.concat([Nola.Plugins, Macro.camelize(plugin)])
with true <- Code.ensure_loaded?(module),
pid when is_pid(pid) <- GenServer.whereis(module),
:ok <- GenServer.stop(pid)
@@ -115,10 +114,12 @@ defmodule Nola.IRC.BasePlugin do
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()
+ brand = Nola.brand(:name)
+ owner = "#{Nola.brand(:owner)} <#{Nola.brand(:owner_email)}>"
message.replyfun.([
- <<"πŸ€– I am a robot running", 2, "beautte, version #{ver}", 2, " β€” source: #{Nola.source_url()}">>,
+ <<"πŸ€– I am a robot running", 2, "#{brand}, version #{ver}", 2, " β€” source: #{Nola.source_url()}">>,
"🦾 Elixir #{elixir_ver} #{otp_ver} on #{system}",
- "πŸ‘·β€β™€οΈ Owner: href <href@random.sh>",
+ "πŸ‘·β€β™€οΈ Owner: h#{owner}",
"🌍 Web interface: #{url}"
])
{:noreply, nil}
diff --git a/lib/nola_plugins/bourosama_plugin.ex b/lib/nola_plugins/boursorama.ex
index dd05144..f872584 100644
--- a/lib/nola_plugins/bourosama_plugin.ex
+++ b/lib/nola_plugins/boursorama.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.BoursoramaPlugin do
+defmodule Nola.Plugins.Boursorama do
def irc_doc() do
"""
diff --git a/lib/nola_plugins/buffer_plugin.ex b/lib/nola_plugins/buffer.ex
index eece34e..67aea35 100644
--- a/lib/nola_plugins/buffer_plugin.ex
+++ b/lib/nola_plugins/buffer.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.BufferPlugin do
+defmodule Nola.Plugins.Buffer do
@table __MODULE__.ETS
def irc_doc, do: nil
diff --git a/lib/nola_plugins/calc_plugin.ex b/lib/nola_plugins/calc.ex
index 264370c..91fbbae 100644
--- a/lib/nola_plugins/calc_plugin.ex
+++ b/lib/nola_plugins/calc.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.CalcPlugin do
+defmodule Nola.Plugins.Calc do
@moduledoc """
# calc
diff --git a/lib/nola_plugins/coronavirus_plugin.ex b/lib/nola_plugins/coronavirus.ex
index d04d8f9..624bae7 100644
--- a/lib/nola_plugins/coronavirus_plugin.ex
+++ b/lib/nola_plugins/coronavirus.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.CoronavirusPlugin do
+defmodule Nola.Plugins.Coronavirus do
require Logger
NimbleCSV.define(CovidCsv, separator: ",", escape: "\"")
@moduledoc """
diff --git a/lib/nola_plugins/correction_plugin.ex b/lib/nola_plugins/correction.ex
index 5f9b278..03968c8 100644
--- a/lib/nola_plugins/correction_plugin.ex
+++ b/lib/nola_plugins/correction.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.CorrectionPlugin do
+defmodule Nola.Plugins.Correction do
@moduledoc """
# correction
diff --git a/lib/nola_plugins/dice_plugin.ex b/lib/nola_plugins/dice.ex
index b5e7649..2c1515b 100644
--- a/lib/nola_plugins/dice_plugin.ex
+++ b/lib/nola_plugins/dice.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.DicePlugin do
+defmodule Nola.Plugins.Dice do
require Logger
@moduledoc """
diff --git a/lib/nola_plugins/finance_plugin.ex b/lib/nola_plugins/finance.ex
index 16d06ee..d6f890a 100644
--- a/lib/nola_plugins/finance_plugin.ex
+++ b/lib/nola_plugins/finance.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.FinancePlugin do
+defmodule Nola.Plugins.Finance do
require Logger
@moduledoc """
diff --git a/lib/nola_plugins/gpt_plugin.ex b/lib/nola_plugins/gpt.ex
index 2c8f182..3d2a66d 100644
--- a/lib/nola_plugins/gpt_plugin.ex
+++ b/lib/nola_plugins/gpt.ex
@@ -1,6 +1,6 @@
-defmodule Nola.IRC.GptPlugin do
+defmodule Nola.Plugins.Gpt do
require Logger
- import Irc.Plugin.TempRef
+ import Nola.Plugins.TempRefHelper
def irc_doc() do
"""
@@ -164,7 +164,7 @@ defmodule Nola.IRC.GptPlugin do
end
defp prompt(msg, prompt = %{"type" => "completions", "prompt" => prompt_template}, content, state) do
- Logger.debug("gpt_plugin:prompt/4 #{inspect prompt}")
+ Logger.debug("gpt:prompt/4 #{inspect prompt}")
prompt_text = case Map.get(prompt, "prompt_format", "liquid") do
"liquid" -> Tmpl.render(prompt_template, msg, Map.merge(Map.get(prompt, "prompt_liquid_variables", %{}), %{"content" => content}))
"norender" -> prompt_template
diff --git a/lib/nola_irc/plugin/temp_ref.ex b/lib/nola_plugins/helpers/temp_ref.ex
index 923fa1a..160169d 100644
--- a/lib/nola_irc/plugin/temp_ref.ex
+++ b/lib/nola_plugins/helpers/temp_ref.ex
@@ -1,4 +1,4 @@
-defmodule Irc.Plugin.TempRef do
+defmodule Nola.Plugins.TempRefHelper do
@moduledoc """
This module allows to easily implement local temporary simple references for easy access from IRC.
diff --git a/lib/nola_plugins/kick_roulette_plugin.ex b/lib/nola_plugins/kick_roulette.ex
index 55b7da4..f6d2ba2 100644
--- a/lib/nola_plugins/kick_roulette_plugin.ex
+++ b/lib/nola_plugins/kick_roulette.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.KickRoulettePlugin do
+defmodule Nola.Plugins.KickRoulette do
@moduledoc """
# kick roulette
diff --git a/lib/nola_plugins/last_fm_plugin.ex b/lib/nola_plugins/last_fm.ex
index 03df675..1a9b7dd 100644
--- a/lib/nola_plugins/last_fm_plugin.ex
+++ b/lib/nola_plugins/last_fm.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.LastFmPlugin do
+defmodule Nola.Plugins.LastFm do
require Logger
@moduledoc """
diff --git a/lib/nola_plugins/link_plugin.ex b/lib/nola_plugins/link.ex
index dee78e8..381bdab 100644
--- a/lib/nola_plugins/link_plugin.ex
+++ b/lib/nola_plugins/link.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.LinkPlugin do
+defmodule Nola.Plugins.Link do
@moduledoc """
# Link Previewer
@@ -6,7 +6,7 @@ defmodule Nola.IRC.LinkPlugin do
To extend the supported sites, create a new handler implementing the callbacks.
- See `link_plugin/` directory for examples. The first in list handler that returns true to the `match/2` callback will be used,
+ See `link/` directory. The first in list handler that returns true to the `match/2` callback will be used,
and if the handler returns `:error` or crashes, will fallback to the default preview.
Unsupported websites will use the default link preview method, which is for html document the title, otherwise it'll use
@@ -15,13 +15,13 @@ defmodule Nola.IRC.LinkPlugin do
## Configuration:
```
- config :nola, Nola.IRC.LinkPlugin,
+ config :nola, Nola.Plugins.Link,
handlers: [
- Nola.IRC.LinkPlugin.Youtube: [
+ Nola.Plugins.Link.Youtube: [
invidious: true
],
- Nola.IRC.LinkPlugin.Twitter: [],
- Nola.IRC.LinkPlugin.Imgur: [],
+ Nola.Plugins.Link.Twitter: [],
+ Nola.Plugins.Link.Imgur: [],
]
```
diff --git a/lib/nola_plugins/link_plugin/github.ex b/lib/nola_plugins/link/github.ex
index 93e0892..0069a40 100644
--- a/lib/nola_plugins/link_plugin/github.ex
+++ b/lib/nola_plugins/link/github.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.Github do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.Github do
+ @behaviour Nola.Plugins.Link
@impl true
def match(uri = %URI{host: "github.com", path: path}, _) do
diff --git a/lib/nola_plugins/link_plugin/html.ex b/lib/nola_plugins/link/html.ex
index 56a8ceb..9b44319 100644
--- a/lib/nola_plugins/link_plugin/html.ex
+++ b/lib/nola_plugins/link/html.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.HTML do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.HTML do
+ @behaviour Nola.Plugins.Link
@impl true
def match(_, _), do: false
diff --git a/lib/nola_plugins/link_plugin/imgur.ex b/lib/nola_plugins/link/imgur.ex
index 5d74956..9fe9354 100644
--- a/lib/nola_plugins/link_plugin/imgur.ex
+++ b/lib/nola_plugins/link/imgur.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.Imgur do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.Imgur do
+ @behaviour Nola.Plugins.Link
@moduledoc """
# Imgur link preview
diff --git a/lib/nola_plugins/link_plugin/pdf.ex b/lib/nola_plugins/link/pdf.ex
index 5f72ef5..e91dcc2 100644
--- a/lib/nola_plugins/link_plugin/pdf.ex
+++ b/lib/nola_plugins/link/pdf.ex
@@ -1,6 +1,6 @@
-defmodule Nola.IRC.LinkPlugin.PDF do
+defmodule Nola.Plugins.Link.PDF do
require Logger
- @behaviour Nola.IRC.LinkPlugin
+ @behaviour Nola.Plugins.Link
@impl true
def match(_, _), do: false
diff --git a/lib/nola_plugins/link_plugin/redacted.ex b/lib/nola_plugins/link/redacted.ex
index 7a6229d..a7cfe74 100644
--- a/lib/nola_plugins/link_plugin/redacted.ex
+++ b/lib/nola_plugins/link/redacted.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.Redacted do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.Redacted do
+ @behaviour Nola.Plugins.Link
@impl true
def match(uri = %URI{host: "redacted.ch", path: "/torrent.php", query: query = "id="<>id}, _opts) do
diff --git a/lib/nola_plugins/link_plugin/reddit.ex b/lib/nola_plugins/link/reddit.ex
index 79102e0..016e025 100644
--- a/lib/nola_plugins/link_plugin/reddit.ex
+++ b/lib/nola_plugins/link/reddit.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.Reddit do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.Reddit do
+ @behaviour Nola.Plugins.Link
@impl true
def match(uri = %URI{host: "reddit.com", path: path}, _) do
diff --git a/lib/nola_plugins/link_plugin/twitter.ex b/lib/nola_plugins/link/twitter.ex
index 640b193..e7f3e63 100644
--- a/lib/nola_plugins/link_plugin/twitter.ex
+++ b/lib/nola_plugins/link/twitter.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.Twitter do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.Twitter do
+ @behaviour Nola.Plugins.Link
@moduledoc """
# Twitter Link Preview
diff --git a/lib/nola_plugins/link_plugin/youtube.ex b/lib/nola_plugins/link/youtube.ex
index f7c7541..1b14221 100644
--- a/lib/nola_plugins/link_plugin/youtube.ex
+++ b/lib/nola_plugins/link/youtube.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.LinkPlugin.YouTube do
- @behaviour Nola.IRC.LinkPlugin
+defmodule Nola.Plugins.Link.YouTube do
+ @behaviour Nola.Plugins.Link
@moduledoc """
# YouTube link preview
diff --git a/lib/nola_plugins/logger_plugin.ex b/lib/nola_plugins/logger.ex
index b13f33a..69cac66 100644
--- a/lib/nola_plugins/logger_plugin.ex
+++ b/lib/nola_plugins/logger.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.LoggerPlugin do
+defmodule Nola.Plugins.Logger do
require Logger
@couch_db "bot-logs"
@@ -13,6 +13,7 @@ defmodule Nola.IRC.LoggerPlugin do
regopts = [plugin: __MODULE__]
{:ok, _} = Registry.register(IRC.PubSub, "triggers", regopts)
{:ok, _} = Registry.register(IRC.PubSub, "messages", regopts)
+ {:ok, _} = Registry.register(IRC.PubSub, "messages:telegram", regopts)
{:ok, _} = Registry.register(IRC.PubSub, "irc:outputs", regopts)
{:ok, _} = Registry.register(IRC.PubSub, "messages:private", regopts)
{:ok, nil}
diff --git a/lib/nola_plugins/outline_plugin.ex b/lib/nola_plugins/outline.ex
index 820500e..f0ccfd2 100644
--- a/lib/nola_plugins/outline_plugin.ex
+++ b/lib/nola_plugins/outline.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.OutlinePlugin do
+defmodule Nola.Plugins.Outline do
@moduledoc """
# outline auto-link
diff --git a/lib/nola_plugins/preums_plugin.ex b/lib/nola_plugins/preums.ex
index f250e85..80c5af0 100644
--- a/lib/nola_plugins/preums_plugin.ex
+++ b/lib/nola_plugins/preums.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.PreumsPlugin do
+defmodule Nola.Plugins.Preums do
@moduledoc """
# preums !!!
@@ -229,7 +229,7 @@ defmodule Nola.IRC.PreumsPlugin do
end
defp timezone(channel) do
- env = Application.get_env(:nola, Nola.IRC.PreumsPlugin, [])
+ env = Application.get_env(:nola, Nola.Plugins.Preums, [])
channels = Keyword.get(env, :channels, %{})
channel_settings = Map.get(channels, channel, [])
default = Keyword.get(env, :default_tz, "Europe/Paris")
diff --git a/lib/nola_plugins/quatre_cent_vingt_plugin.ex b/lib/nola_plugins/quatre_cent_vingt.ex
index 8953ea3..3331625 100644
--- a/lib/nola_plugins/quatre_cent_vingt_plugin.ex
+++ b/lib/nola_plugins/quatre_cent_vingt.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.QuatreCentVingtPlugin do
+defmodule Nola.Plugins.QuatreCentVingt do
require Logger
@moduledoc """
diff --git a/lib/nola_plugins/radio_france_plugin.ex b/lib/nola_plugins/radio_france.ex
index c2e966f..2096de8 100644
--- a/lib/nola_plugins/radio_france_plugin.ex
+++ b/lib/nola_plugins/radio_france.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.RadioFrancePlugin do
+defmodule Nola.Plugins.RadioFrance do
require Logger
def irc_doc() do
diff --git a/lib/nola_plugins/say_plugin.ex b/lib/nola_plugins/say.ex
index 915b0f6..91ffacc 100644
--- a/lib/nola_plugins/say_plugin.ex
+++ b/lib/nola_plugins/say.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.SayPlugin do
+defmodule Nola.Plugins.Say do
def irc_doc do
"""
diff --git a/lib/nola_plugins/script_plugin.ex b/lib/nola_plugins/script.ex
index 94d4edf..d383abb 100644
--- a/lib/nola_plugins/script_plugin.ex
+++ b/lib/nola_plugins/script.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.ScriptPlugin do
+defmodule Nola.Plugins.Script do
require Logger
@moduledoc """
diff --git a/lib/nola_plugins/seen_plugin.ex b/lib/nola_plugins/seen.ex
index 2a4d0dd..65af0c1 100644
--- a/lib/nola_plugins/seen_plugin.ex
+++ b/lib/nola_plugins/seen.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.SeenPlugin do
+defmodule Nola.Plugins.Seen do
@moduledoc """
# seen
diff --git a/lib/nola_plugins/sms_plugin.ex b/lib/nola_plugins/sms.ex
index d8f7387..ad16f78 100644
--- a/lib/nola_plugins/sms_plugin.ex
+++ b/lib/nola_plugins/sms.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.SmsPlugin do
+defmodule Nola.Plugins.Sms do
@moduledoc """
## sms
diff --git a/lib/nola_plugins/tell_plugin.ex b/lib/nola_plugins/tell.ex
index ecc98df..8978c82 100644
--- a/lib/nola_plugins/tell_plugin.ex
+++ b/lib/nola_plugins/tell.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.TellPlugin do
+defmodule Nola.Plugins.Tell do
use GenServer
@moduledoc """
diff --git a/lib/nola_plugins/txt_plugin.ex b/lib/nola_plugins/txt.ex
index cab912a..f6e71a3 100644
--- a/lib/nola_plugins/txt_plugin.ex
+++ b/lib/nola_plugins/txt.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.TxtPlugin do
+defmodule Nola.Plugins.Txt do
alias IRC.UserTrack
require Logger
@@ -55,7 +55,7 @@ defmodule Nola.IRC.TxtPlugin do
def init([]) do
dets_locks_filename = (Nola.data_path() <> "/" <> "txtlocks.dets") |> String.to_charlist
{:ok, locks} = :dets.open_file(dets_locks_filename, [])
- markov_handler = Keyword.get(Application.get_env(:nola, __MODULE__, []), :markov_handler, Nola.IRC.TxtPlugin.Markov.Native)
+ markov_handler = Keyword.get(Application.get_env(:nola, __MODULE__, []), :markov_handler, Nola.Plugins.Txt.Markov.Native)
{:ok, markov} = markov_handler.start_link()
{:ok, _} = Registry.register(IRC.PubSub, "triggers", [plugin: __MODULE__])
{:ok, %__MODULE__{locks: locks, markov_handler: markov_handler, markov: markov, triggers: load()}}
diff --git a/lib/nola_plugins/txt_plugin/markov.ex b/lib/nola_plugins/txt/markov.ex
index 2e30dfa..b47666c 100644
--- a/lib/nola_plugins/txt_plugin/markov.ex
+++ b/lib/nola_plugins/txt/markov.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.TxtPlugin.Markov do
+defmodule Nola.Plugins.Txt.Markov do
@type state :: any()
@callback start_link() :: {:ok, state()}
diff --git a/lib/nola_plugins/txt_plugin/markov_native.ex b/lib/nola_plugins/txt/markov_native.ex
index 4c403c2..aa6b454 100644
--- a/lib/nola_plugins/txt_plugin/markov_native.ex
+++ b/lib/nola_plugins/txt/markov_native.ex
@@ -1,5 +1,5 @@
-defmodule Nola.IRC.TxtPlugin.MarkovNative do
- @behaviour Nola.IRC.TxtPlugin.Markov
+defmodule Nola.Plugins.Txt.MarkovNative do
+ @behaviour Nola.Plugins.Txt.Markov
def start_link() do
ExChain.MarkovModel.start_link()
diff --git a/lib/nola_plugins/txt_plugin/markov_py_markovify.ex b/lib/nola_plugins/txt/markov_py_markovify.ex
index b610ea8..f79ed47 100644
--- a/lib/nola_plugins/txt_plugin/markov_py_markovify.ex
+++ b/lib/nola_plugins/txt/markov_py_markovify.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.TxtPlugin.MarkovPyMarkovify do
+defmodule Nola.Plugins.Txt.MarkovPyMarkovify do
def start_link() do
{:ok, nil}
@@ -18,7 +18,7 @@ defmodule Nola.IRC.TxtPlugin.MarkovPyMarkovify do
defp run(args \\ []) do
{binary, script} = script()
- args = [script, Path.expand(Nola.IRC.TxtPlugin.directory()) | args]
+ args = [script, Path.expand(Nola.Plugins.Txt.directory()) | args]
IO.puts "Args #{inspect args}"
case MuonTrap.cmd(binary, args) do
{response, 0} -> response
@@ -28,7 +28,7 @@ defmodule Nola.IRC.TxtPlugin.MarkovPyMarkovify do
defp script() do
default_script = to_string(:code.priv_dir(:nola)) <> "/irc/txt/markovify.py"
- env = Application.get_env(:nola, Nola.IRC.TxtPlugin, [])
+ env = Application.get_env(:nola, Nola.Plugins.Txt, [])
|> Keyword.get(:py_markovify, [])
{Keyword.get(env, :python, "python3"), Keyword.get(env, :script, default_script)}
diff --git a/lib/nola_plugins/untappd_plugin.ex b/lib/nola_plugins/untappd.ex
index 50b0c4d..cf5c694 100644
--- a/lib/nola_plugins/untappd_plugin.ex
+++ b/lib/nola_plugins/untappd.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.UntappdPlugin do
+defmodule Nola.Plugins.Untappd do
def irc_doc() do
"""
diff --git a/lib/nola_plugins/user_mention_plugin.ex b/lib/nola_plugins/user_mention.ex
index eb230fd..c4dd719 100644
--- a/lib/nola_plugins/user_mention_plugin.ex
+++ b/lib/nola_plugins/user_mention.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.UserMentionPlugin do
+defmodule Nola.Plugins.UserMention do
@moduledoc """
# mention
@@ -33,11 +33,11 @@ defmodule Nola.IRC.UserMentionPlugin do
telegram ->
Nola.Telegram.send_message(telegram, "`#{channel}` <**#{sender.nick}**> #{Enum.join(content, " ")}")
sms ->
- case Nola.IRC.SmsPlugin.send_sms(sms, text) do
+ case Nola.Plugins.Sms.send_sms(sms, text) do
{:error, code} -> message.replyfun("#{sender.nick}: erreur #{code} (sms)")
end
true ->
- Nola.IRC.TellPlugin.tell(message, nick, content)
+ Nola.Plugins.Tell.tell(message, nick, content)
end
else
message.replyfun.("#{nick} m'est inconnu")
diff --git a/lib/nola_plugins/wikipedia_plugin.ex b/lib/nola_plugins/wikipedia.ex
index 3202e13..dcd1874 100644
--- a/lib/nola_plugins/wikipedia_plugin.ex
+++ b/lib/nola_plugins/wikipedia.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.WikipediaPlugin do
+defmodule Nola.Plugins.Wikipedia do
require Logger
@moduledoc """
diff --git a/lib/nola_plugins/wolfram_alpha_plugin.ex b/lib/nola_plugins/wolfram_alpha.ex
index 6ee06f0..c2f106e 100644
--- a/lib/nola_plugins/wolfram_alpha_plugin.ex
+++ b/lib/nola_plugins/wolfram_alpha.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.WolframAlphaPlugin do
+defmodule Nola.Plugins.WolframAlpha do
use GenServer
require Logger
diff --git a/lib/nola_plugins/youtube_plugin.ex b/lib/nola_plugins/youtube.ex
index fb9bea2..c62f73c 100644
--- a/lib/nola_plugins/youtube_plugin.ex
+++ b/lib/nola_plugins/youtube.ex
@@ -1,4 +1,4 @@
-defmodule Nola.IRC.YouTubePlugin do
+defmodule Nola.Plugins.YouTube do
require Logger
@moduledoc """
diff --git a/lib/nola_web/controllers/alcoolog_controller.ex b/lib/nola_web/controllers/alcoolog_controller.ex
index 3081762..3c812c5 100644
--- a/lib/nola_web/controllers/alcoolog_controller.ex
+++ b/lib/nola_web/controllers/alcoolog_controller.ex
@@ -21,8 +21,8 @@ defmodule NolaWeb.AlcoologController do
days = String.to_integer(Map.get(params, "days", "180"))
friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id)
if friend? do
- stats = Nola.IRC.AlcoologPlugin.get_full_statistics(profile_account.id)
- history = for {{nick, ts}, points, active, cl, deg, type, descr, meta} <- Nola.IRC.AlcoologPlugin.nick_history(profile_account) do
+ stats = Nola.Plugins.Alcoolog.get_full_statistics(profile_account.id)
+ history = for {{nick, ts}, points, active, cl, deg, type, descr, meta} <- Nola.Plugins.Alcoolog.nick_history(profile_account) do
%{
at: ts |> DateTime.from_unix!(:millisecond),
points: points,
@@ -50,7 +50,7 @@ defmodule NolaWeb.AlcoologController do
profile_account = IRC.Account.find_always_by_nick(network, nick, nick)
friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id)
if friend? do
- stats = Nola.IRC.AlcoologPlugin.get_full_statistics(profile_account.id)
+ stats = Nola.Plugins.Alcoolog.get_full_statistics(profile_account.id)
conn
|> put_resp_content_type("application/json")
@@ -67,7 +67,7 @@ defmodule NolaWeb.AlcoologController do
friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id)
count = String.to_integer(Map.get(params, "days", "180"))
if friend? do
- data = Nola.IRC.AlcoologPlugin.user_over_time_gl(profile_account, count)
+ data = Nola.Plugins.Alcoolog.user_over_time_gl(profile_account, count)
delay = count*((24 * 60)*60)
now = DateTime.utc_now()
start_date = DateTime.utc_now()
@@ -101,7 +101,7 @@ defmodule NolaWeb.AlcoologController do
friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id)
count = String.to_integer(Map.get(params, "days", "180"))
if friend? do
- data = Nola.IRC.AlcoologPlugin.user_over_time(profile_account, count)
+ data = Nola.Plugins.Alcoolog.user_over_time(profile_account, count)
delay = count*((24 * 60)*60)
now = DateTime.utc_now()
start_date = DateTime.utc_now()
@@ -132,7 +132,7 @@ defmodule NolaWeb.AlcoologController do
profile_account = IRC.Account.find_always_by_nick(network, nick, nick)
friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id)
if friend? do
- history = for {{nick, ts}, points, active, cl, deg, type, descr, meta} <- Nola.IRC.AlcoologPlugin.nick_history(profile_account) do
+ history = for {{nick, ts}, points, active, cl, deg, type, descr, meta} <- Nola.Plugins.Alcoolog.nick_history(profile_account) do
%{
at: ts |> DateTime.from_unix!(:millisecond) |> DateTime.to_iso8601(),
points: points,
@@ -145,7 +145,7 @@ defmodule NolaWeb.AlcoologController do
}
end
last = List.last(history)
- {_, active} = Nola.IRC.AlcoologPlugin.user_stats(profile_account)
+ {_, active} = Nola.Plugins.Alcoolog.user_stats(profile_account)
last = %{last | active: active, at: DateTime.utc_now() |> DateTime.to_iso8601()}
history = history ++ [last]
@@ -163,7 +163,7 @@ defmodule NolaWeb.AlcoologController do
profile_account = IRC.Account.find_always_by_nick(network, nick, nick)
friend? = Enum.member?(IRC.Membership.friends(account), profile_account.id)
if friend? do
- history = for {_, date, value} <- Nola.IRC.AlcoologAnnouncerPlugin.log(profile_account) do
+ history = for {_, date, value} <- Nola.Plugs.AlcoologAnnouncer.log(profile_account) do
%{date: DateTime.to_iso8601(date), value: value}
end
conn
@@ -223,12 +223,12 @@ defmodule NolaWeb.AlcoologController do
members = IRC.Membership.expanded_members_or_friends(account, network, channel)
members_ids = Enum.map(members, fn({account, _, nick}) -> account.id end)
member_names = Enum.reduce(members, %{}, fn({account, _, nick}, acc) -> Map.put(acc, account.id, nick) end)
- drinks = :ets.select(Nola.IRC.AlcoologPlugin.ETS, match)
+ drinks = :ets.select(Nola.Plugins.Alcoolog.ETS, match)
|> Enum.filter(fn({{account, _}, _vol, _cur, _cl, _deg, _name, _cmt, _meta}) -> Enum.member?(members_ids, account) end)
|> Enum.map(fn({{account, _}, _, _, _, _, _, _, _} = object) -> {object, Map.get(member_names, account)} end)
|> Enum.sort_by(fn({{{_, ts}, _, _, _, _, _, _, _}, _}) -> ts end, &>/2)
- stats = Nola.IRC.AlcoologPlugin.get_channel_statistics(account, network, channel)
+ stats = Nola.Plugins.Alcoolog.get_channel_statistics(account, network, channel)
top = Enum.reduce(drinks, %{}, fn({{{account_id, _}, vol, _, _, _, _, _, _}, _}, acc) ->
nick = Map.get(member_names, account_id)
@@ -266,7 +266,7 @@ defmodule NolaWeb.AlcoologController do
|> Enum.into(Map.new)
gls = Enum.reduce(members, filled, fn({account, _, _}, gls) ->
- Enum.reduce(Nola.IRC.AlcoologPlugin.user_over_time_gl(account, count), gls, fn({date, gl}, gls) ->
+ Enum.reduce(Nola.Plugins.Alcoolog.user_over_time_gl(account, count), gls, fn({date, gl}, gls) ->
u = Map.get(gls, date, %{})
|> Map.put(Map.get(member_names, account.id, account.id), gl)
Map.put(gls, date, u)
@@ -302,12 +302,12 @@ defmodule NolaWeb.AlcoologController do
def minisync(conn, %{"user_id" => user_id, "key" => key, "value" => value}) do
account = IRC.Account.get(user_id)
if account do
- ds = Nola.IRC.AlcoologPlugin.data_state()
- meta = Nola.IRC.AlcoologPlugin.get_user_meta(ds, account.id)
+ ds = Nola.Plugins.Alcoolog.data_state()
+ meta = Nola.Plugins.Alcoolog.get_user_meta(ds, account.id)
case Float.parse(value) do
{val, _} ->
new_meta = Map.put(meta, String.to_existing_atom(key), val)
- Nola.IRC.AlcoologPlugin.put_user_meta(ds, account.id, new_meta)
+ Nola.Plugins.Alcoolog.put_user_meta(ds, account.id, new_meta)
_ ->
conn
|> put_status(:unprocessable_entity)
diff --git a/lib/nola_web/controllers/gpt_controller.ex b/lib/nola_web/controllers/gpt_controller.ex
index 038b235..810a875 100644
--- a/lib/nola_web/controllers/gpt_controller.ex
+++ b/lib/nola_web/controllers/gpt_controller.ex
@@ -5,7 +5,7 @@ defmodule NolaWeb.GptController do
plug NolaWeb.ContextPlug
def result(conn, params = %{"id" => result_id}) do
- case Nola.IRC.GptPlugin.get_result(result_id) do
+ case Nola.Plugins.Gpt.get_result(result_id) do
{:ok, result} ->
network = Map.get(params, "network")
channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c)
@@ -18,7 +18,7 @@ defmodule NolaWeb.GptController do
end
def prompt(conn, params = %{"id" => prompt_id}) do
- case Nola.IRC.GptPlugin.get_prompt(prompt_id) do
+ case Nola.Plugins.Gpt.get_prompt(prompt_id) do
{:ok, prompt} ->
network = Map.get(params, "network")
channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c)
diff --git a/lib/nola_web/controllers/irc_controller.ex b/lib/nola_web/controllers/irc_controller.ex
index c617e78..d6114e6 100644
--- a/lib/nola_web/controllers/irc_controller.ex
+++ b/lib/nola_web/controllers/irc_controller.ex
@@ -6,9 +6,9 @@ defmodule NolaWeb.IrcController do
def index(conn, params) do
network = Map.get(params, "network")
channel = if c = Map.get(params, "chan"), do: NolaWeb.reformat_chan(c)
- commands = for mod <- Enum.uniq([IRC.Account.AccountPlugin] ++ IRC.Plugin.enabled()) do
+ commands = for mod <- Enum.uniq([Nola.Plugins.Account] ++ Nola.Plugins.enabled()) do
if is_atom(mod) do
- identifier = Module.split(mod) |> List.last |> String.replace("Plugin", "") |> Macro.underscore
+ identifier = Module.split(mod) |> List.last |> Macro.underscore
{identifier, mod.irc_doc()}
end
end
@@ -42,7 +42,7 @@ defmodule NolaWeb.IrcController do
defp do_txt(conn, nil) do
- doc = Nola.IRC.TxtPlugin.irc_doc()
+ doc = Nola.IRC.Txt.irc_doc()
data = data()
main = Enum.filter(data, fn({trigger, _}) -> !String.contains?(trigger, ".") end) |> Enum.into(Map.new)
system = Enum.filter(data, fn({trigger, _}) -> String.contains?(trigger, ".") end) |> Enum.into(Map.new)
diff --git a/lib/nola_web/controllers/sms_controller.ex b/lib/nola_web/controllers/sms_controller.ex
index 575655c..0fffa23 100644
--- a/lib/nola_web/controllers/sms_controller.ex
+++ b/lib/nola_web/controllers/sms_controller.ex
@@ -3,7 +3,7 @@ defmodule NolaWeb.SmsController do
require Logger
def ovh_callback(conn, %{"senderid" => from, "message" => message}) do
- spawn(fn() -> Nola.IRC.SmsPlugin.incoming(from, String.trim(message)) end)
+ spawn(fn() -> Nola.Plugins.Sms.incoming(from, String.trim(message)) end)
text(conn, "")
end
diff --git a/lib/nola_web/live/chat_live.ex b/lib/nola_web/live/chat_live.ex
index 276b362..678ea36 100644
--- a/lib/nola_web/live/chat_live.ex
+++ b/lib/nola_web/live/chat_live.ex
@@ -22,7 +22,7 @@ defmodule NolaWeb.ChatLive do
Map.put(acc, id, user)
end)
- backlog = case Nola.IRC.BufferPlugin.select_buffer(connection.network, chan) do
+ backlog = case Nola.IRC.Buffer.select_buffer(connection.network, chan) do
{backlog, _} ->
{backlog, _} = Enum.reduce(backlog, {backlog, nil}, &reduce_contextual_event/2)
Enum.reverse(backlog)