summaryrefslogtreecommitdiff
path: root/lib/irc/parser/line.ex
diff options
context:
space:
mode:
Diffstat (limited to 'lib/irc/parser/line.ex')
-rw-r--r--lib/irc/parser/line.ex20
1 files changed, 16 insertions, 4 deletions
diff --git a/lib/irc/parser/line.ex b/lib/irc/parser/line.ex
index 17c381c..5aa5a9b 100644
--- a/lib/irc/parser/line.ex
+++ b/lib/irc/parser/line.ex
@@ -37,13 +37,25 @@ defmodule Irc.Parser.Line do
|> Enum.join(" ")
end
- def new(command, args \\ [], tags \\ %{}) do
+ def new(command) do
+ new(command, [])
+ end
+
+ def new(command, args) do
+ new(command, args, %{})
+ end
+
+ def new(command, arg, tags) when not is_list(arg) do
+ new(command, [arg], tags)
+ end
+
+ def new(command, args, tags) do
%__MODULE__{command: command, args: args, tags: tags, __private__: %{at: DateTime.utc_now()}}
end
@doc "Returns the line date (server time if sent, otherwise, parse time)"
@spec at(t()) :: DateTime.t()
- def at(%__MODULE__{__private__: %{at: at}, tags: %{"time" => server_time}}) do
+ def at(line = %__MODULE__{__private__: %{at: at}, tags: %{"time" => server_time}}) do
case DateTime.from_iso8601(server_time) do
{:ok, date} -> date
_ -> at
@@ -54,14 +66,14 @@ defmodule Irc.Parser.Line do
@spec to?(t(), Irc.Connection.t() | Irc.Mask.t() | Irc.User.t()) :: boolean
@doc "Returns true if the line is adressed to the connection."
- def to?(%__MODULE__{args: [nick | _]}, %{__struct__: s, nick: nick}) when s in [Irc.Connection, Irc.Mask, Irc.User] do
+ def to?(line = %__MODULE__{args: [nick | _]}, target = %{__struct__: s, nick: nick}) when s in [Irc.Connection, Irc.Mask, Irc.User] do
true
end
def to?(%__MODULE__{}, %{__struct__: s}) when s in [Irc.Connection, Irc.Mask, Irc.User], do: false
@spec self?(t(), Irc.Connection.t() | Irc.Mask.t() | Irc.User.t()) :: boolean
@doc "Returns true if the line source is the from the given connection/mask."
- def self?(%__MODULE__{source: %Irc.Mask{nick: nick}}, %Irc.Connection{nick: nick}) do
+ def self?(line = %__MODULE__{source: %Irc.Mask{nick: nick}}, target = %Irc.Connection{nick: nick}) do
true
end
def self?(%__MODULE__{source: mask = %Irc.Mask{}}, mask = %Irc.Mask{}) do