summaryrefslogtreecommitdiff
path: root/lib/irc/client.ex
blob: 1c4b0c55a9807d11ecaa92a5733e7e9dd42634e4 (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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
defmodule Irc.Client do
  alias Irc.BaseClient
  @behaviour Irc.BaseClient
  require Logger

  @moduledoc """
  Fully-featured IRC client.

  The client uses message passing.

  """

  @type message :: Irc.BaseClient.event
  @type start_ret :: BaseClient.start_ret

  @spec start(Irc.Connection.nick, Irc.Connection.host, [BaseClient.start_opt], [:gen_statem.start_opt]) :: start_ret
  def start(nick, host, opts \\ [], start_opts \\ []) do
    :gen_statem.start(__MODULE__, [nick, host, prepare_args(opts)], start_opts)
  end

  @spec start_link(Irc.Connection.nick, Irc.Connection.host, [BaseClient.start_opt], [:gen_statem.start_opt]) :: start_ret
  def start_link(nick, host, opts \\ [], start_opts \\ []) do
    :gen_statem.start_link(__MODULE__, [nick, host, prepare_args(opts)], start_opts)
  end

  @doc false
  def init(_) do
    Logger.debug("CLIENT initiated")
    {:ok, %{process: nil}}
  end

  @doc false
  def handle_event(event, state) do
    Logger.debug("CLIENT EVENT: #{inspect event}")
    :ok
  end

  @doc false
  def stop(reason, state) do
    Logger.debug("CLIENT: Stopping, #{inspect reason}")
  end

  defp prepare_args(opts) do
    opts
    |> Keyword.put_new(:module, __MODULE__)
  end
end