aboutsummaryrefslogtreecommitdiff
path: root/lib/consumer.ex
blob: a5948466c92efff329fb48f2a9769b0d43cb1419 (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
26
require Logger

alias Nostrum.Struct.Message
alias Phoenix.PubSub

defmodule Thulani.DiscordConsumer do
  use Nostrum.Consumer

  @spec handle_event(Nostrum.Consumer.message_create()) :: nil
  def handle_event({
        :MESSAGE_CREATE,
        message = %Message{},
        _ws_state
      }) do
    case Thulani.Message.validate(message) do
      {:ok, command} ->
        Logger.debug(%{command: command})
        PubSub.broadcast!(:thulani_pubsub, "cmd", {:cmd, command, message})

      :ignore ->
        nil
    end
  end

  def handle_event(_event), do: :noop
end