summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJordan Bracco <href@random.sh>2023-03-05 10:14:31 +0100
committerJordan Bracco <href@random.sh>2023-03-05 10:14:31 +0100
commit53b9b921987e5e61a6149f46ef98671da7907043 (patch)
treece23bf045ed78e981c39a77589bca572965e0ad9
parentlink/image with pyerlai (tbc) (diff)
-rw-r--r--config/config.exs4
-rw-r--r--lib/plugins/base.ex22
-rw-r--r--lib/plugins/last_fm.ex4
-rw-r--r--lib/plugins/link/youtube.ex2
-rw-r--r--lib/telegram.ex7
-rw-r--r--lib/telegram/room.ex26
-rw-r--r--lib/web.ex2
-rw-r--r--lib/web/views/layout_view.ex2
8 files changed, 44 insertions, 25 deletions
diff --git a/config/config.exs b/config/config.exs
index e2d7db9..bf52838 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -15,7 +15,9 @@ config :nola, :data_path, "priv"
config :nola, :brand,
name: "Nola",
- source_url: "https://phab.random.sh/source/Nola/"
+ source_url: "https://phab.random.sh/source/Nola/",
+ owner: "Ashamed Owner",
+ owner_email: "do@not.mail.him"
config :ex_aws,
region: "us-east-1",
diff --git a/lib/plugins/base.ex b/lib/plugins/base.ex
index 1baf066..97aaa05 100644
--- a/lib/plugins/base.ex
+++ b/lib/plugins/base.ex
@@ -120,16 +120,24 @@ defmodule Nola.Plugins.Base do
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, "#{brand}, version #{ver}", 2, " — source: #{Nola.source_url()}">>,
- "🦾 Elixir #{elixir_ver} #{otp_ver} on #{system}",
- "👷‍♀️ Owner: h#{owner}",
- "🌍 Web interface: #{url}"
- ])
+
+ if message.channel do
+ message.replyfun.([
+ <<"🤖 ", 2, "#{brand}", 2, " v", 2, "#{ver}", 2, "! My owner is #{Nola.brand(:owner)} and help is at #{url}">>,
+ ])
+ else
+ message.replyfun.([
+ <<"🤖 I am a robot running ", 2, "#{brand}", 2, " version ", 2, "#{ver}", 2, " — source: #{Nola.source_url()}">>,
+ "Source code: #{Nola.source_url()}",
+ "🦾 Elixir #{elixir_ver} #{otp_ver} on #{system}",
+ "🙋🏻 Owner: #{owner}",
+ "🌍 Web interface: #{url}"
+ ])
+ end
{:noreply, nil}
end
- def handle_info(msg, _) do
+ def handle_info(_msg, _) do
{:noreply, nil}
end
diff --git a/lib/plugins/last_fm.ex b/lib/plugins/last_fm.ex
index 8e872ea..b7d0a92 100644
--- a/lib/plugins/last_fm.ex
+++ b/lib/plugins/last_fm.ex
@@ -21,8 +21,8 @@ defmodule Nola.Plugins.LastFm do
end
def init([]) do
- regopts = [type: __MODULE__]
- for t <- @pubsub_topics, do: {:ok, _} = Registry.register(Nola.PubSub, t, type: __MODULE__)
+ regopts = [plugin: __MODULE__]
+ for t <- @pubsub_topics, do: {:ok, _} = Registry.register(Nola.PubSub, t, regopts)
dets_filename = (Nola.data_path() <> "/" <> "lastfm.dets") |> String.to_charlist
{:ok, dets} = :dets.open_file(dets_filename, [])
{:ok, %__MODULE__{dets: dets}}
diff --git a/lib/plugins/link/youtube.ex b/lib/plugins/link/youtube.ex
index 1b14221..0114940 100644
--- a/lib/plugins/link/youtube.ex
+++ b/lib/plugins/link/youtube.ex
@@ -31,7 +31,7 @@ defmodule Nola.Plugins.Link.YouTube do
def post_match(_, _, _, _), do: false
@impl true
- def expand(uri, %{video_id: video_id}, opts) do
+ def expand(_uri, %{video_id: video_id}, opts) do
key = Application.get_env(:nola, :youtube)[:api_key]
params = %{
"part" => "snippet,contentDetails,statistics",
diff --git a/lib/telegram.ex b/lib/telegram.ex
index f2c9eca..b161b63 100644
--- a/lib/telegram.ex
+++ b/lib/telegram.ex
@@ -15,9 +15,12 @@ defmodule Nola.Telegram do
@impl Telegram.ChatBot
def init(chat_id) when chat_id < 0 do
- {:ok, state} = Nola.TelegramRoom.init(chat_id)
- {:ok, %{room_state: state}}
+ case Nola.TelegramRoom.init(chat_id) do
+ {:ok, state} -> {:ok, %{room_state: state}}
+ _ -> :ignore
+ end
end
+
def init(chat_id) do
Logger.info("Telegram session starting: #{chat_id}")
account = Nola.Account.find_meta_account("telegram-id", chat_id)
diff --git a/lib/telegram/room.ex b/lib/telegram/room.ex
index ede939e..7a8f427 100644
--- a/lib/telegram/room.ex
+++ b/lib/telegram/room.ex
@@ -32,7 +32,12 @@ defmodule Nola.TelegramRoom do
end
def after_start() do
- for id <- room(:ids), do: Telegram.Bot.ChatBot.Chat.Session.Supervisor.start_child(Nola.Telegram, Integer.parse(id) |> elem(0))
+ {:ok, rooms} = rooms(:ids)
+ for id <- rooms do
+ spawn(fn() ->
+ Telegram.Bot.ChatBot.Chat.Session.Supervisor.start_child(Nola.Telegram, Integer.parse(id) |> elem(0))
+ end)
+ end
end
@impl Telegram.ChatBot
@@ -40,16 +45,16 @@ defmodule Nola.TelegramRoom do
token = Keyword.get(Application.get_env(:nola, :telegram, []), :key)
{:ok, chat} = Api.request(token, "getChat", chat_id: id)
Logger.metadata(transport: :telegram, id: id, telegram_room_id: id)
- tg_room = case room(id) do
+ tg_room = case room(to_string(id)) do
{:ok, tg_room = %{"network" => _net, "channel" => _chan}} -> tg_room
- {:error, :not_found} ->
+ _ ->
[net, chan] = String.split(chat["title"], "/", parts: 2)
{net, chan} = case Nola.Irc.Connection.get_network(net, chan) do
%Nola.Irc.Connection{} -> {net, chan}
_ -> {nil, nil}
end
- {:ok, _id, _rev} = Couch.post(@couch, %{"_id" => id, "network" => net, "channel" => nil})
- {:ok, tg_room} = room(id)
+ _ = Couch.post(@couch, %{"_id" => id, "network" => net, "channel" => chan})
+ {:ok, tg_room} = room(to_string(id))
tg_room
end
%{"network" => net, "channel" => chan} = tg_room
@@ -68,7 +73,7 @@ defmodule Nola.TelegramRoom do
def init(id) do
Logger.error("telegram_room: bad id (not room id)", transport: :telegram, id: id, telegram_room_id: id)
- :ignoree
+ :ignore
end
defp find_or_create_meta_account(from = %{"id" => user_id}, state) do
@@ -86,7 +91,8 @@ defmodule Nola.TelegramRoom do
account = username
|> Nola.Account.new_account()
|> Nola.Account.update_account_name(name)
- |> Nola.Account.put_meta("telegram-id", user_id)
+
+ Nola.Account.put_meta(account, "telegram-id", user_id)
Logger.info("telegram_room: created account #{account.id} for telegram user #{user_id}")
account
@@ -95,14 +101,14 @@ defmodule Nola.TelegramRoom do
def handle_update(%{"message" => %{"from" => from = %{"id" => user_id}, "text" => text}}, _token, state) do
account = find_or_create_meta_account(from, state)
- connection = Nola.Irc.Connection.get_network(state.net)
+ #connection = Nola.Irc.Connection.get_network(state.net)
Nola.Irc.send_message_as(account, state.net, state.chan, text, true)
{:ok, state}
end
def handle_update(data = %{"message" => %{"from" => from = %{"id" => user_id}, "location" => %{"latitude" => lat, "longitude" => lon}}}, _token, state) do
account = find_or_create_meta_account(from, state)
- connection = Nola.Irc.Connection.get_network(state.net)
+ #connection = Nola.Irc.Connection.get_network(state.net)
Nola.Irc.send_message_as(account, state.net, state.chan, "@ #{lat}, #{lon}", true)
{:ok, state}
end
@@ -172,7 +178,7 @@ defmodule Nola.TelegramRoom do
do
path = NolaWeb.Router.Helpers.url(NolaWeb.Endpoint) <> "/files/#{s3path}"
txt = "#{type}: #{text}#{path}"
- connection = Nola.Irc.Connection.get_network(state.net)
+ #connection = Nola.Irc.Connection.get_network(state.net)
Nola.Irc.send_message_as(account, state.net, state.chan, txt, true)
else
error ->
diff --git a/lib/web.ex b/lib/web.ex
index 906e961..c1720a0 100644
--- a/lib/web.ex
+++ b/lib/web.ex
@@ -55,7 +55,7 @@ defmodule NolaWeb do
def view do
quote do
- use Phoenix.View, root: "lib/nola_web/templates",
+ use Phoenix.View, root: "lib/web/templates",
namespace: NolaWeb
# Import convenience functions from controllers
diff --git a/lib/web/views/layout_view.ex b/lib/web/views/layout_view.ex
index 2bffc6f..663eccf 100644
--- a/lib/web/views/layout_view.ex
+++ b/lib/web/views/layout_view.ex
@@ -24,7 +24,7 @@ defmodule NolaWeb.LayoutView do
conn.assigns[:chan] ->
"#{conn.assigns.chan} @ #{conn.assigns.network}"
conn.assigns[:network] -> conn.assigns.network
- true -> Keyword.get(Nola.name())
+ true -> Nola.name()
end
breadcrumb_title = Enum.map(Map.get(conn.assigns, :breadcrumbs)||[], fn({title, _href}) -> title end)