summaryrefslogtreecommitdiff
path: root/lib/irc/client/command.ex
blob: a84324febb21c8b12d98e92876ef30bca68e23d0 (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
49
50
defmodule Irc.Client.Command do

  @moduledoc """
  Implementations of IRC protocol commands and capabilities.

  The Capabs modules are used by the BaseClient to implement everything.

  Capabs modules are mostly stateless, except when they enter the buffering FSM state.

  It is recommended that event names matches the command name, to help awaiting response.
  """

  @doc """
  Returns which server-initiated and client-initiated commands the module supports, and IRCv3 capabs to be requested to the server.
  """
  @callback init(Keyword.t) :: {commands :: [String.t],
    client_commands :: [atom],
    capabs :: [String.t]}

  @type buffer :: any()
  @type event :: {client_command :: atom | atom, any()}

  @type buffer_ret :: :buffer | {:buffer, buffer()}
  @type line_return :: :ok | {:ok, [action]} | {:error, any()} | buffer_ret
  @type buffer_return :: buffer_ret | line_return | :postpone

  @type send_action :: {:send, Line.t()}
  @type event_action :: {:event, event()}
  @type action :: send_action | event_action

  @doc """
  Handles an incoming line.
  """
  @callback handle_line(Irc.Line.t(), Irc.Connection.t()) :: line_return

  @doc """
  Handles an incoming line when in buffering state.

  Returning anything else than `:buffer` or `:postpone` will exit the buffering state.

  Postponed lines will be treated as usual (per their respective module) once the buffering state exits.
  """
  @callback handle_buffer(Irc.Line.t(), buffer, Irc.Connection.t()) :: buffer_return

  @doc """
  Handles a user requested command.
  """
  @callback handle_command(client_command :: atom, args :: list, Irc.Connection.t()) :: line_return

end