Skip to content

Commit

Permalink
Merge pull request bitwalker#10 from jeffweiss/update_for_elixir-0.15.0
Browse files Browse the repository at this point in the history
(maint) Update for Elixir 0.15.0
  • Loading branch information
bitwalker committed Aug 7, 2014
2 parents 31ecdb5 + c775f80 commit f2bb9b1
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions lib/exirc/utils.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,19 @@ defmodule ExIrc.Utils do
end

defp parse_from(from, msg) do
case Regex.split(~r/(!|@|\.)/, IO.iodata_to_binary(from)) do
[nick, "!", user, "@" | host] ->
%{msg | :nick => nick, :user => user, :host => Enum.join(host)}
[nick, "@" | host] ->
%{msg | :nick => nick, :host => Enum.join(host)}
[_, "." | _] ->
# from is probably a server name
binary_from = IO.iodata_to_binary(from)
fully_qualified_regex = ~r/(?<nick>.*)!(?<user>.*)@(?<host>.*)/
missing_user_regex = ~r/(?<nick>.*)@(?<host>.*)/
host_only_regex = ~r/.+\..+/
cond do
captures = Regex.named_captures fully_qualified_regex, binary_from ->
%{msg | :nick => captures[:nick], :user => captures[:user], :host => captures[:host]}
captures = Regex.named_captures missing_user_regex, binary_from ->
%{msg | :nick => captures[:nick], :host => captures[:host]}
Regex.match? host_only_regex, binary_from ->
%{msg | :server => to_string(from)}
[nick] ->
%{msg | :nick => nick}
true ->
%{msg | :nick => to_string(from)}
end
end

Expand Down

0 comments on commit f2bb9b1

Please sign in to comment.