From 021108b2c9a34c05d2b1e3e7899c29d8de463e41 Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Tue, 28 Jan 2020 22:34:43 -0500 Subject: maybe we're somewhat close to things working? --- apps/thulani_bot/lib/thulani/bot/application.ex | 13 +++++++------ apps/thulani_bot/lib/thulani/bot/consumer.ex | 10 +++++++--- apps/thulani_bot/lib/thulani/bot/supervisor.ex | 17 +++++++++++++++++ apps/thulani_bot/mix.exs | 4 +++- config/dev.exs | 3 --- 5 files changed, 34 insertions(+), 13 deletions(-) create mode 100644 apps/thulani_bot/lib/thulani/bot/supervisor.ex diff --git a/apps/thulani_bot/lib/thulani/bot/application.ex b/apps/thulani_bot/lib/thulani/bot/application.ex index 7507eb8..cdbe2eb 100644 --- a/apps/thulani_bot/lib/thulani/bot/application.ex +++ b/apps/thulani_bot/lib/thulani/bot/application.ex @@ -1,19 +1,20 @@ defmodule Thulani.Bot.Application do - alias Thulani.Bot.Config use Application + alias Thulani.Bot.Config + @applications [ :nostrum ] def start(_type, _args) do Config.init!() + Enum.each(@applications, fn a -> {:ok, _} = Application.ensure_all_started(a) end) - Enum.each(@applications, fn a -> Application.start(a) end) - - children = [] + children = [ + Thulani.Bot.Supervisor + ] - opts = [strategy: :one_for_one, name: Thulani.Bot.Supervisor] - Supervisor.start_link(children, opts) + Supervisor.start_link(children, strategy: :one_for_one) end end diff --git a/apps/thulani_bot/lib/thulani/bot/consumer.ex b/apps/thulani_bot/lib/thulani/bot/consumer.ex index f5deec6..5e43296 100644 --- a/apps/thulani_bot/lib/thulani/bot/consumer.ex +++ b/apps/thulani_bot/lib/thulani/bot/consumer.ex @@ -8,16 +8,20 @@ defmodule Thulani.Bot.Consumer do Consumer.start_link(__MODULE__) end - def handle_event({:MESSAGE_CREATE, {msg}, ws_state}, state) do - case msg.content do + 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 + {:ok, _} = Api.create_message(msg.channel.id, "sup") + {:ok, state} end - def handle_event(_, state) do + def handle_event(msg, state) do + IO.inspect(msg) + {:ok, state} end end diff --git a/apps/thulani_bot/lib/thulani/bot/supervisor.ex b/apps/thulani_bot/lib/thulani/bot/supervisor.ex new file mode 100644 index 0000000..ac0e65b --- /dev/null +++ b/apps/thulani_bot/lib/thulani/bot/supervisor.ex @@ -0,0 +1,17 @@ +defmodule Thulani.Bot.Supervisor do + @moduledoc false + + use Supervisor + + def start_link(arg) do + Supervisor.start_link(__MODULE__, arg, name: __MODULE__) + end + + def init(_arg) do + children = [ + {Thulani.Bot.Consumer, []} + ] + + Supervisor.init(children, strategy: :one_for_one) + end +end diff --git a/apps/thulani_bot/mix.exs b/apps/thulani_bot/mix.exs index 9d3b6ae..9338bb1 100644 --- a/apps/thulani_bot/mix.exs +++ b/apps/thulani_bot/mix.exs @@ -17,7 +17,9 @@ defmodule Thulani.Bot.MixProject do def application do [ - extra_applications: [:logger], + extra_applications: [ + :logger + ], mod: {Thulani.Bot.Application, []} ] end diff --git a/config/dev.exs b/config/dev.exs index c1414e2..6c36055 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -3,9 +3,6 @@ import Config config :logger, level: :debug -config :nostrum, - dev: true - import_config "dotenv.exs" Thulani.Config.Dotenv.load_dotenv!() -- cgit v1.3.1