aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2020-02-17 02:08:09 -0500
committerNathan Perry <np@nathanperry.dev>2020-02-17 02:08:09 -0500
commit19b6ba3153eb5f21b0b38c6a7889e0aef82356f4 (patch)
tree3c389216dbb4973fbc1289a2c979b50a173379f3
parent021108b2c9a34c05d2b1e3e7899c29d8de463e41 (diff)
rework a bunch of stuffelixir.prev.2
-rw-r--r--apps/thulani_bot/lib/thulani/bot/application.ex4
-rw-r--r--apps/thulani_bot/lib/thulani/bot/config.ex12
-rw-r--r--apps/thulani_bot/lib/thulani/bot/consumer.ex33
-rw-r--r--apps/thulani_bot/lib/thulani/bot/supervisor.ex1
-rw-r--r--apps/thulani_bot/mix.exs7
-rw-r--r--apps/util/lib/thulani/util.ex3
-rw-r--r--apps/util/lib/thulani/util/compose.ex4
-rw-r--r--apps/util/lib/thulani/util/curry.ex4
-rw-r--r--apps/util/mix.exs5
-rw-r--r--config/config.exs10
-rw-r--r--mix.exs10
-rw-r--r--mix.lock5
-rw-r--r--ttb_last_configbin0 -> 620 bytes
13 files changed, 68 insertions, 30 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
diff --git a/config/config.exs b/config/config.exs
index b19babd..dd8af65 100644
--- a/config/config.exs
+++ b/config/config.exs
@@ -4,6 +4,14 @@ config :thulani_bot,
env: Mix.env()
config :logger,
+ backends: [:console],
+ compile_time_purge_matching: [
+ [application: :nostrum, level_lower_than: :warn]
+ ],
level: :info
-import_config "#{Mix.env()}.exs"
+# handle_sasl_reports: true
+
+config :logger, :console, metadata: :all
+
+import_config("#{Mix.env()}.exs")
diff --git a/mix.exs b/mix.exs
index ada3618..d769ba0 100644
--- a/mix.exs
+++ b/mix.exs
@@ -13,29 +13,21 @@ defmodule Thulani.MixProject do
end
defp deps do
- [
- {:toml, "~> 0.6.1"}
- ]
+ []
end
defp releases do
- config_providers = [
- # {Toml.Provider, ["./config.toml", "/etc/thulani/config.toml"]}
- ]
-
applications = [thulani_bot: :permanent]
[
thulani_flex: [
include_executables_for: [:unix, :windows],
strip_beams: false,
- config_providers: config_providers,
applications: applications
],
thulani_prod: [
include_executables_for: [:unix],
strip_beams: true,
- config_providers: config_providers,
applications: applications
]
]
diff --git a/mix.lock b/mix.lock
index 93687d1..cd6f71d 100644
--- a/mix.lock
+++ b/mix.lock
@@ -1,11 +1,16 @@
%{
+ "bunt": {:hex, :bunt, "0.2.0", "951c6e801e8b1d2cbe58ebbd3e616a869061ddadcc4863d0a2182541acae9a38", [:mix], [], "hexpm"},
"certifi": {:hex, :certifi, "2.5.1", "867ce347f7c7d78563450a18a6a28a8090331e77fa02380b4a21962a65d36ee5", [:rebar3], [{:parse_trans, "~>3.3", [hex: :parse_trans, repo: "hexpm", optional: false]}], "hexpm"},
"cowlib": {:hex, :cowlib, "2.6.0", "8aa629f81a0fc189f261dc98a42243fa842625feea3c7ec56c48f4ccdb55490f", [:rebar3], [], "hexpm"},
+ "credo": {:hex, :credo, "1.2.2", "f57faf60e0a12b0ba9fd4bad07966057fde162b33496c509b95b027993494aab", [:mix], [{:bunt, "~> 0.2.0", [hex: :bunt, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}], "hexpm"},
+ "dialyxir": {:hex, :dialyxir, "1.0.0-rc.7", "6287f8f2cb45df8584317a4be1075b8c9b8a69de8eeb82b4d9e6c761cf2664cd", [:mix], [{:erlex, ">= 0.2.5", [hex: :erlex, repo: "hexpm", optional: false]}], "hexpm"},
+ "erlex": {:hex, :erlex, "0.2.5", "e51132f2f472e13d606d808f0574508eeea2030d487fc002b46ad97e738b0510", [:mix], [], "hexpm"},
"gen_stage": {:hex, :gen_stage, "0.14.3", "d0c66f1c87faa301c1a85a809a3ee9097a4264b2edf7644bf5c123237ef732bf", [:mix], [], "hexpm"},
"gun": {:hex, :gun, "1.3.1", "1489fd96018431b89f401041a9ce0b02b45265247f0fdcf71273bf087c64ea4f", [:rebar3], [{:cowlib, "~> 2.6.0", [hex: :cowlib, repo: "hexpm", optional: false]}], "hexpm"},
"hackney": {:hex, :hackney, "1.15.2", "07e33c794f8f8964ee86cebec1a8ed88db5070e52e904b8f12209773c1036085", [:rebar3], [{:certifi, "2.5.1", [hex: :certifi, repo: "hexpm", optional: false]}, {:idna, "6.0.0", [hex: :idna, repo: "hexpm", optional: false]}, {:metrics, "1.0.1", [hex: :metrics, repo: "hexpm", optional: false]}, {:mimerl, "~>1.1", [hex: :mimerl, repo: "hexpm", optional: false]}, {:ssl_verify_fun, "1.1.5", [hex: :ssl_verify_fun, repo: "hexpm", optional: false]}], "hexpm"},
"httpoison": {:hex, :httpoison, "1.6.2", "ace7c8d3a361cebccbed19c283c349b3d26991eff73a1eaaa8abae2e3c8089b6", [:mix], [{:hackney, "~> 1.15 and >= 1.15.2", [hex: :hackney, repo: "hexpm", optional: false]}], "hexpm"},
"idna": {:hex, :idna, "6.0.0", "689c46cbcdf3524c44d5f3dde8001f364cd7608a99556d8fbd8239a5798d4c10", [:rebar3], [{:unicode_util_compat, "0.4.1", [hex: :unicode_util_compat, repo: "hexpm", optional: false]}], "hexpm"},
+ "jason": {:hex, :jason, "1.1.2", "b03dedea67a99223a2eaf9f1264ce37154564de899fd3d8b9a21b1a6fd64afe7", [:mix], [{:decimal, "~> 1.0", [hex: :decimal, repo: "hexpm", optional: true]}], "hexpm"},
"metrics": {:hex, :metrics, "1.0.1", "25f094dea2cda98213cecc3aeff09e940299d950904393b2a29d191c346a8486", [:rebar3], [], "hexpm"},
"mimerl": {:hex, :mimerl, "1.2.0", "67e2d3f571088d5cfd3e550c383094b47159f3eee8ffa08e64106cdf5e981be3", [:rebar3], [], "hexpm"},
"nostrum": {:hex, :nostrum, "0.4.1", "da5f1ad98146117f6b7884e144c38fdc2b2a413d863d88a73297c67ef86fc863", [:mix], [{:gen_stage, "~> 0.11", [hex: :gen_stage, repo: "hexpm", optional: false]}, {:gun, "~> 1.3", [hex: :gun, repo: "hexpm", optional: false]}, {:httpoison, "~> 1.5", [hex: :httpoison, repo: "hexpm", optional: false]}, {:poison, "~> 3.0", [hex: :poison, repo: "hexpm", optional: false]}], "hexpm"},
diff --git a/ttb_last_config b/ttb_last_config
new file mode 100644
index 0000000..e43416a
--- /dev/null
+++ b/ttb_last_config
Binary files differ