diff options
Diffstat (limited to 'lib/irc/client/command.ex')
-rw-r--r-- | lib/irc/client/command.ex | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/lib/irc/client/command.ex b/lib/irc/client/command.ex new file mode 100644 index 0000000..a84324f --- /dev/null +++ b/lib/irc/client/command.ex @@ -0,0 +1,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 |