diff options
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/thulani_bot/lib/thulani/bot/application.ex | 4 | ||||
| -rw-r--r-- | apps/thulani_bot/lib/thulani/bot/config.ex | 12 | ||||
| -rw-r--r-- | apps/thulani_bot/lib/thulani/bot/consumer.ex | 33 | ||||
| -rw-r--r-- | apps/thulani_bot/lib/thulani/bot/supervisor.ex | 1 | ||||
| -rw-r--r-- | apps/thulani_bot/mix.exs | 7 | ||||
| -rw-r--r-- | apps/util/lib/thulani/util.ex | 3 | ||||
| -rw-r--r-- | apps/util/lib/thulani/util/compose.ex | 4 | ||||
| -rw-r--r-- | apps/util/lib/thulani/util/curry.ex | 4 | ||||
| -rw-r--r-- | apps/util/mix.exs | 5 |
9 files changed, 53 insertions, 20 deletions
diff --git a/apps/thulani_bot/lib/thulani/bot/application.ex b/apps/thulani_bot/lib/thulani/bot/application.ex index cdbe2eb..13e245c 100644 --- a/apps/thulani_bot/lib/thulani/bot/application.ex +++ b/apps/thulani_bot/lib/thulani/bot/application.ex @@ -1,4 +1,8 @@ defmodule Thulani.Bot.Application do + @moduledoc """ + Thulani bot application. + """ + use Application alias Thulani.Bot.Config diff --git a/apps/thulani_bot/lib/thulani/bot/config.ex b/apps/thulani_bot/lib/thulani/bot/config.ex index e57dbe2..41479fd 100644 --- a/apps/thulani_bot/lib/thulani/bot/config.ex +++ b/apps/thulani_bot/lib/thulani/bot/config.ex @@ -1,9 +1,13 @@ defmodule Thulani.Bot.Config do - # note: we actively don't want to use a config provider, since it only works in a release. - # we want to be able to *always* assume the config is going to be found in the environment and parse it - # ourselves. kind of sucks that we have to start all the applications we want to run ourselves, but that's just - # the way it has to be. + @moduledoc """ + Module handling config loading. + We actively don't want to use a config provider, since they only work (automatically) in release contexts. We want to + *always* be able to assume that the config is going to be found in the environment and parse it ourselves, here. + + Kind of sucks that this means we need to start all applications we need to configure dynamically ourselves, but this + is just the way it has to be, and it's not too much of a pain. + """ @env_vars %{ database_url: nil, spreadsheet_id: nil, diff --git a/apps/thulani_bot/lib/thulani/bot/consumer.ex b/apps/thulani_bot/lib/thulani/bot/consumer.ex index 5e43296..771272b 100644 --- a/apps/thulani_bot/lib/thulani/bot/consumer.ex +++ b/apps/thulani_bot/lib/thulani/bot/consumer.ex @@ -1,27 +1,36 @@ defmodule Thulani.Bot.Consumer do + @moduledoc """ + The main Nostrum.Consumer implementation. Ingestion-point for all messages from the Discord API. + """ + use Nostrum.Consumer - alias Nostrum.Api + alias Nostrum.{ + Api, + Struct.Message + } + require Logger def start_link do Consumer.start_link(__MODULE__) end - def handle_event({:MESSAGE_CREATE, {msg}, _ws_state}, state) do - case IO.inspect(msg.content) do - "!thulani " <> command -> Logger.debug("got command", command: command) - _ -> :ignore - end + @impl Nostrum.Consumer + def handle_event({ + :MESSAGE_CREATE, + %Message{content: "!thulani " <> message}, + _ws_state + }) do + Logger.debug("received message", message: message) - {:ok, _} = Api.create_message(msg.channel.id, "sup") + # Api.create_message!(msg.channel_id, content: "sup") |> IO.inspect() - {:ok, state} + :ok end - def handle_event(msg, state) do - IO.inspect(msg) - - {:ok, state} + @impl Nostrum.Consumer + def handle_event(event) do + Logger.warn("unknown event", event: elem(event, 0)) end end diff --git a/apps/thulani_bot/lib/thulani/bot/supervisor.ex b/apps/thulani_bot/lib/thulani/bot/supervisor.ex index ac0e65b..d859689 100644 --- a/apps/thulani_bot/lib/thulani/bot/supervisor.ex +++ b/apps/thulani_bot/lib/thulani/bot/supervisor.ex @@ -7,6 +7,7 @@ defmodule Thulani.Bot.Supervisor do Supervisor.start_link(__MODULE__, arg, name: __MODULE__) end + @impl Supervisor def init(_arg) do children = [ {Thulani.Bot.Consumer, []} diff --git a/apps/thulani_bot/mix.exs b/apps/thulani_bot/mix.exs index 9338bb1..25e8373 100644 --- a/apps/thulani_bot/mix.exs +++ b/apps/thulani_bot/mix.exs @@ -18,7 +18,8 @@ defmodule Thulani.Bot.MixProject do def application do [ extra_applications: [ - :logger + :logger, + :sasl ], mod: {Thulani.Bot.Application, []} ] @@ -26,8 +27,10 @@ defmodule Thulani.Bot.MixProject do defp deps do [ + {:util, in_umbrella: true}, {:nostrum, "~> 0.4", runtime: false}, - {:util, in_umbrella: true} + {:dialyxir, "~>1.0.0-rc.7", only: [:dev], runtime: false}, + {:credo, "~> 1.2", only: [:dev, :test], runtime: false} ] end end diff --git a/apps/util/lib/thulani/util.ex b/apps/util/lib/thulani/util.ex index fad5e39..137b515 100644 --- a/apps/util/lib/thulani/util.ex +++ b/apps/util/lib/thulani/util.ex @@ -1,2 +1,5 @@ defmodule Thulani.Util do + @moduledoc """ + Module for utility functions. + """ end diff --git a/apps/util/lib/thulani/util/compose.ex b/apps/util/lib/thulani/util/compose.ex index cd4435e..a5ee88c 100644 --- a/apps/util/lib/thulani/util/compose.ex +++ b/apps/util/lib/thulani/util/compose.ex @@ -1,4 +1,8 @@ defmodule Thulani.Util.Compose do + @moduledoc """ + Implements infix function composition operator. + """ + import Thulani.Util.Curry def f <|> g, do: compose(f, g) diff --git a/apps/util/lib/thulani/util/curry.ex b/apps/util/lib/thulani/util/curry.ex index b03afab..b5aee88 100644 --- a/apps/util/lib/thulani/util/curry.ex +++ b/apps/util/lib/thulani/util/curry.ex @@ -1,5 +1,7 @@ defmodule Thulani.Util.Curry do - @moduledoc false + @moduledoc """ + Implements explicit currying. + """ def curry(f) do {_, arity} = :erlang.fun_info(f, :arity) diff --git a/apps/util/mix.exs b/apps/util/mix.exs index a0caff9..ce9c72b 100644 --- a/apps/util/mix.exs +++ b/apps/util/mix.exs @@ -22,6 +22,9 @@ defmodule Thulani.Util.MixProject do end defp deps do - [] + [ + {:dialyxir, "~>1.0.0-rc.7", only: [:dev], runtime: false}, + {:credo, "~> 1.2", only: [:dev, :test], runtime: false} + ] end end |
