diff options
author | Josh Adams <josh.rubyist@gmail.com> | 2016-09-12 12:27:55 -0500 |
---|---|---|
committer | Paul Schoenfelder <paulschoenfelder@gmail.com> | 2016-09-12 12:27:59 -0500 |
commit | daf1bef3a4dca08fdd589d2980a52a09883251f2 (patch) | |
tree | e6c64bf3610a54d88df692fcb9befcc3150ef1de | |
parent | Add case clause for RPL_TOPIC when no topic was set. See #52 (diff) |
Convert RPL_TOPIC with no topic to RPL_NOTOPIC. See #52
-rw-r--r-- | lib/exirc/utils.ex | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/exirc/utils.ex b/lib/exirc/utils.ex index 5f01af5..41686ad 100644 --- a/lib/exirc/utils.ex +++ b/lib/exirc/utils.ex @@ -75,26 +75,34 @@ defmodule ExIrc.Utils do defp get_args([], msg) do args = msg.args |> Enum.reverse - |> Enum.filter(fn(arg) -> arg != [] end) + |> Enum.filter(fn arg -> arg != [] end) |> Enum.map(&trim_crlf/1) |> Enum.map(&List.to_string/1) - %{msg | args: args} + post_process(%{msg | args: args}) end defp get_args([[?: | first_arg] | rest], msg) do args = (for arg <- [first_arg | rest], do: ' ' ++ trim_crlf(arg)) |> List.flatten case args do [_] -> - get_args [], %{msg | args: [msg.args]} + get_args([], %{msg | args: msg.args}) [_ | full_trail] -> - get_args [], %{msg | args: [full_trail | msg.args]} + get_args([], %{msg | args: [full_trail | msg.args]}) end end defp get_args([arg | rest], msg) do - get_args rest, %{msg | args: [arg | msg.args]} + get_args(rest, %{msg | args: [arg | msg.args]}) end + # This function allows us to handle special case messages which are not RFC + # compliant, before passing it to the client. + defp post_process(%IrcMessage{cmd: "332", args: [nick, channel]} = msg) do + # Handle malformed RPL_TOPIC messages which contain no topic + %{msg | :cmd => "331", :args => [channel, "No topic is set"], :nick => nick} + end + defp post_process(msg), do: msg + ############################ # Parse RPL_ISUPPORT (005) ############################ |