summaryrefslogtreecommitdiff
path: root/lib/irc/client.ex
diff options
context:
space:
mode:
authorhref <href@random.sh>2021-01-11 15:53:02 +0100
committerhref <href@random.sh>2021-01-11 15:53:02 +0100
commit0f3f0e035b43eabd3f739c41964446962cf54208 (patch)
tree9279c54e100c92375c9d980e2031e0a153245025 /lib/irc/client.ex
parentSome fixes (diff)
Cont. wipmaster
Diffstat (limited to 'lib/irc/client.ex')
-rw-r--r--lib/irc/client.ex17
1 files changed, 10 insertions, 7 deletions
diff --git a/lib/irc/client.ex b/lib/irc/client.ex
index d8a7b77..b7b9fe0 100644
--- a/lib/irc/client.ex
+++ b/lib/irc/client.ex
@@ -1,5 +1,7 @@
defmodule Irc.Client do
+
@behaviour :gen_statem
+
require Logger
alias Irc.Parser.Line
alias Irc.Connection
@@ -35,6 +37,8 @@ defmodule Irc.Client do
def callback_mode, do: [:state_enter]
+ @type t :: nil
+
@type message :: {:irc_client, pid(), event}
@type event :: event_connected | event_nick | event_modes | event_line | event_down
@@ -51,7 +55,6 @@ defmodule Irc.Client do
@type event_line :: {:line, line :: Irc.Parser.Line.t}
@type event_down :: {:down, {Connection.error, delay :: integer}}
-
@type start_opt :: Connection.start_opt
| {:module, module() | Irc.Client}
| {:commands, [module()]}
@@ -117,7 +120,7 @@ defmodule Irc.Client do
end
def handle_event(:info, msg = {:irc_conn_up, _, info}, :disconnected, data) do
- data = run_handler_event({:connected, info}, data)
+ data = run_handler_event({:connected, info}, info)
{:next_state, :connected, %__MODULE__{data | nick: info.nick, info: info, modes: info.modes, error: nil}}
end
@@ -147,7 +150,7 @@ defmodule Irc.Client do
def handle_event(:info, {:irc_command, command, args}, :connected, data) do
if module = get_in(data, [:commands, :user, command]) do
- {next, actions} = case module.handle_command(command, args, data.info) do
+ {next, actions} = case module.handle_command(data.info, command, args) do
{next, next_arg} -> {{next, next_arg}, []}
{next, next_arg, actions} -> {{next, next_arg}, List.wrap(actions)}
next when is_atom(next) -> {{next, nil}, []}
@@ -188,7 +191,7 @@ defmodule Irc.Client do
#
def handle_event(:info, {:irc_conn_line, _, line}, {:buffer, module}, data) do
- {next, actions} = case module.handle_buffer(line, data.buffer, data.info) do
+ {next, actions} = case module.handle_buffer(data.info, line, data.buffer) do
{next, next_arg} -> {{next, next_arg}, []}
{next, next_arg, actions} -> {{next, next_arg}, List.wrap(actions)}
next when is_atom(next) -> {{next, nil}, []}
@@ -205,7 +208,7 @@ defmodule Irc.Client do
# TODO: Callback stop?
def handle_event(:internal, reason, :error, data) do
Logger.error "#{inspect data}: #{inspect reason}"
- data.module.stop(reason, data.modstate)
+ data.module.stop(data.info, reason)
{:stop, :normal}
end
@@ -230,7 +233,7 @@ defmodule Irc.Client do
end
defp run_handler_event(event, data) do
- case data.module.handle_event(event, data.modstate) do
+ case data.module.handle_event(data.info, event) do
{:ok, modstate} -> %__MODULE__{data | modstate: modstate}
:ok -> data
end
@@ -258,7 +261,7 @@ defmodule Irc.Client do
end)
end
- defimpl Inspect, for: __MODULE__ do
+ defimpl Inspect, for: Irc.Client do
import Inspect.Algebra
def inspect(struct, _opts) do
concat(["#Irc.Client<", inspect(self()), ">"])