aboutsummaryrefslogtreecommitdiff
path: root/lib/consumer.ex
blob: ace0ba857724a6b4d564701103b4c5e77af1d0c3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
require Logger
require OK

alias Nostrum.Api

defmodule Thulani.Consumer do
  use Nostrum.Consumer

  def start_link do
    Logger.info('starting consumer')
    Nostrum.Consumer.start_link(__MODULE__)
  end

  @spec handle_event(Nostrum.Consumer.message_create()) :: nil
  def handle_event({:MESSAGE_CREATE, message, _ws_state}) do
    case Thulani.Message.message(message) do
      {:ok, content} -> Api.create_message!(message.channel_id, content)
      :ignore -> nil
    end

    nil
  end

  def handle_event(_event), do: :noop
end