diff --git a/lib/nola/application.ex b/lib/nola/application.ex index d56d4cb..fc51c2c 100644 --- a/lib/nola/application.ex +++ b/lib/nola/application.ex @@ -1,57 +1,60 @@ defmodule Nola.Application do use Application def start(_type, _args) do import Supervisor.Spec - Logger.add_backend(Sentry.LoggerBackend) - Nola.Plugins.setup() :ok = Nola.Matrix.setup() :ok = Nola.TelegramRoom.setup() # Define workers and child supervisors to be supervised - children = [ - supervisor(NolaWeb.Endpoint, []), - worker(Registry, [[keys: :duplicate, name: Nola.BroadcastRegistry]], id: :registry_broadcast), - worker(Nola.IcecastAgent, []), - worker(Nola.Token, []), - worker(Nola.AuthToken, []), - Nola.Subnet, - {GenMagic.Pool, [name: Nola.GenMagic, pool_size: 2]}, - worker(Registry, [[keys: :duplicate, name: Nola.PubSub]], id: :registry_nola_pubsub), - worker(Nola.Membership, []), - worker(Nola.Account, []), - worker(Nola.UserTrack.Storage, []), - worker(Nola.Plugins.Account, []), - supervisor(Nola.Plugins.Supervisor, [], [name: Nola.Plugins.Supervisor]), - ] ++ Nola.Irc.application_childs - ++ Nola.Matrix.application_childs + children = + [ + supervisor(NolaWeb.Endpoint, []), + worker(Registry, [[keys: :duplicate, name: Nola.BroadcastRegistry]], + id: :registry_broadcast + ), + worker(Nola.IcecastAgent, []), + worker(Nola.Token, []), + worker(Nola.AuthToken, []), + Nola.Subnet, + {GenMagic.Pool, [name: Nola.GenMagic, pool_size: 2]}, + worker(Registry, [[keys: :duplicate, name: Nola.PubSub]], id: :registry_nola_pubsub), + worker(Nola.Membership, []), + worker(Nola.Account, []), + worker(Nola.UserTrack.Storage, []), + worker(Nola.Plugins.Account, []), + supervisor(Nola.Plugins.Supervisor, [], name: Nola.Plugins.Supervisor) + ] ++ + Nola.Irc.application_childs() ++ + Nola.Matrix.application_childs() opts = [strategy: :one_for_one, name: Nola.Supervisor] sup = Supervisor.start_link(children, opts) - + start_telegram() Nola.Plugins.start_all() - spawn_link(fn() -> Nola.Irc.after_start() end) - spawn_link(fn() -> Nola.Matrix.after_start() end) - spawn_link(fn() -> Nola.TelegramRoom.after_start() end) + spawn_link(fn -> Nola.Irc.after_start() end) + spawn_link(fn -> Nola.Matrix.after_start() end) + spawn_link(fn -> Nola.TelegramRoom.after_start() end) sup end def config_change(changed, _new, removed) do NolaWeb.Endpoint.config_change(changed, removed) :ok end defp start_telegram() do token = Keyword.get(Application.get_env(:nola, :telegram, []), :key) + options = [ username: Keyword.get(Application.get_env(:nola, :telegram, []), :nick, "beauttebot"), purge: false ] + telegram = Telegram.Bot.ChatBot.Supervisor.start_link({Nola.Telegram, token, options}) end - end diff --git a/lib/web/endpoint.ex b/lib/web/endpoint.ex index a401f54..b54458d 100644 --- a/lib/web/endpoint.ex +++ b/lib/web/endpoint.ex @@ -1,62 +1,60 @@ defmodule NolaWeb.Endpoint do - use Sentry.PlugCapture use Phoenix.Endpoint, otp_app: :nola # Serve at "/" the static files from "priv/static" directory. # # You should set gzip to true if you are running phoenix.digest # when deploying your static files in production. - plug Plug.Static, - at: "/", from: :nola, gzip: false, + plug(Plug.Static, + at: "/", + from: :nola, + gzip: false, only: ~w(assets css js fonts images favicon.ico robots.txt) + ) # Code reloading can be explicitly enabled under the # :code_reloader configuration of your endpoint. - if 42==43 && code_reloading? do - socket "/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket - plug Phoenix.LiveReloader - plug Phoenix.CodeReloader + if 42 == 43 && code_reloading? do + socket("/phoenix/live_reload/socket", Phoenix.LiveReloader.Socket) + plug(Phoenix.LiveReloader) + plug(Phoenix.CodeReloader) end - plug Plug.RequestId - plug Plug.Logger + plug(Plug.RequestId) + plug(Plug.Logger) - plug Plug.Parsers, + plug(Plug.Parsers, parsers: [:urlencoded, :multipart, :json], pass: ["*/*"], json_decoder: Jason + ) - plug Sentry.PlugContext - plug Plug.MethodOverride - plug Plug.Head + plug(Plug.MethodOverride) + plug(Plug.Head) - @session_options [store: :cookie, - key: "_nola_key", - signing_salt: "+p7K3wrj"] + @session_options [store: :cookie, key: "_nola_key", signing_salt: "+p7K3wrj"] - - socket "/live", Phoenix.LiveView.Socket, - websocket: [connect_info: [session: @session_options]] + socket("/live", Phoenix.LiveView.Socket, websocket: [connect_info: [session: @session_options]]) # The session will be stored in the cookie and signed, # this means its contents can be read but not tampered with. # Set :encryption_salt if you would also like to encrypt it. - plug Plug.Session, @session_options + plug(Plug.Session, @session_options) - plug NolaWeb.Router + plug(NolaWeb.Router) @doc """ Callback invoked for dynamically configuring the endpoint. It receives the endpoint configuration and checks if configuration should be loaded from the system environment. """ def init(_key, config) do if config[:load_from_system_env] do port = System.get_env("PORT") || raise "expected the PORT environment variable to be set" {:ok, Keyword.put(config, :http, [:inet6, port: port])} else {:ok, config} end end end diff --git a/mix.exs b/mix.exs index 2ff7670..d2fbcea 100644 --- a/mix.exs +++ b/mix.exs @@ -1,105 +1,109 @@ defmodule Nola.Mixfile do use Mix.Project def project do [ app: :nola, version: version("0.2.7"), elixir: "~> 1.4", - elixirc_paths: elixirc_paths(Mix.env), - compilers: [:phoenix, :gettext] ++ Mix.compilers, - start_permanent: Mix.env == :prod, + elixirc_paths: elixirc_paths(Mix.env()), + compilers: [:phoenix, :gettext] ++ Mix.compilers(), + start_permanent: Mix.env() == :prod, deps: deps() ] end def application do [ mod: {Nola.Application, []}, extra_applications: [:logger, :runtime_tools] ] end defp elixirc_paths(:test), do: ["lib", "test/support"] - defp elixirc_paths(_), do: ["lib"] + defp elixirc_paths(_), do: ["lib"] defp aliases do [ "assets.deploy": ["make -C assets", "phx.digest"] ] end defp deps do [ {:phoenix, "~> 1.6.0-rc.0", override: true}, {:phoenix_pubsub, "~> 2.0"}, {:phoenix_live_reload, "~> 1.0", only: :dev}, {:phoenix_html, "~> 3.0"}, {:phoenix_live_view, "~> 0.16.0"}, {:phoenix_live_dashboard, "~> 0.5"}, {:telemetry, "~> 1.0.0", override: true}, {:telemetry_metrics, "~> 0.6"}, {:telemetry_poller, "~> 0.5"}, {:plug_cowboy, "~> 2.0"}, {:cowlib, "~> 2.9.1", override: true}, {:plug, "~> 1.7"}, {:gettext, "~> 0.11"}, {:httpoison, "~> 1.8", override: true}, {:jason, "~> 1.0"}, {:poison, "~> 4.0", override: true}, {:floki, "~> 0.19.3"}, {:ecto, "~> 3.4"}, {:exirc, git: "https://git.random.sh/ircbot/exirc.git", branch: "fix-who-nick"}, {:distillery, "~> 2.0"}, {:earmark, "~> 1.2"}, {:oauther, "~> 1.1"}, {:extwitter, "~> 0.14.0"}, {:entropy_string, "~> 1.0.0"}, {:abacus, "~> 0.3.3"}, {:timex, "~> 3.6"}, {:muontrap, "~> 0.5.1"}, {:tzdata, "~> 1.0"}, {:nimble_csv, "~> 0.7.0"}, {:backoff, git: "https://github.com/ferd/backoff", branch: "master"}, {:telegram, git: "https://github.com/hrefhref/telegram.git", branch: "master"}, {:ex_aws, "~> 2.0"}, {:ex_aws_s3, "~> 2.0"}, {:gen_magic, git: "https://github.com/hrefhref/gen_magic", branch: "develop"}, {:liquex, "~> 0.3"}, {:html_entities, "0.4.0", override: true}, {:file_size, "~> 3.0"}, {:ex2ms, "~> 1.0"}, - {:polyjuice_client, git: "https://git.random.sh/ircbot/polyjuice_client.git", branch: "master", override: true}, - {:matrix_app_service, git: "https://git.random.sh/ircbot/matrix_app_service.ex.git", branch: "master"}, - {:sentry, "~> 8.0.5"}, + {:polyjuice_client, + git: "https://git.random.sh/ircbot/polyjuice_client.git", branch: "master", override: true}, + {:matrix_app_service, + git: "https://git.random.sh/ircbot/matrix_app_service.ex.git", branch: "master"}, {:logger_json, "~> 4.3"}, {:oauth2, "~> 2.0"}, {:powerdnsex, git: "https://git.random.sh/ircbot/powerdnsex.git", branch: "master"}, {:pfx, "~> 0.7.0"}, - {:flake_id, "~> 0.1.0"}, + {:flake_id, "~> 0.1.0"} ] end defp version(v) do {describe, 0} = System.cmd("git", ~w(describe --dirty --broken --all --tags --long)) [_, rest] = String.split(describe, "/", parts: 2) - info = rest - |> String.trim() - |> String.replace("/", "-") - env = cond do - Mix.env() == :prod -> "" - true -> "." <> to_string(Mix.env()) - end + info = + rest + |> String.trim() + |> String.replace("/", "-") - build_timestamp = DateTime.utc_now() - |> DateTime.to_unix() - |> to_string() + env = + cond do + Mix.env() == :prod -> "" + true -> "." <> to_string(Mix.env()) + end + + build_timestamp = + DateTime.utc_now() + |> DateTime.to_unix() + |> to_string() build_date_tag = ".build" <> build_timestamp v <> "+" <> info <> env <> build_date_tag end - end