diff options
author | Jeff Weiss <jeff.weiss@puppetlabs.com> | 2016-03-29 22:40:07 -0700 |
---|---|---|
committer | Jeff Weiss <jeff.weiss@puppetlabs.com> | 2016-03-29 22:40:07 -0700 |
commit | 1ca809736246fc25ce07f45bcbd3eeb787e2adf6 (patch) | |
tree | 049bfe413427c90cf36beaa82eaf8031f8318801 /lib/exirc | |
parent | prefer Elixir module variants over Erlang ones (diff) |
Prefer Keyword list syntax for Map key-value pairs
Prior to this commit exirc had inconsistent formatting for Map key-value
pairs, some cases used the Keyword list style (`key: value`), while
other used the traditional Map fat arrow style (`:key => value`). This
commit standardizes the codebase on the Keyword list style because 1)
all the Map/struct keys are atoms enabling use of the Keyword list
style, and 2) the Keyword list style is more compact.
Diffstat (limited to 'lib/exirc')
-rw-r--r-- | lib/exirc/channels.ex | 14 | ||||
-rw-r--r-- | lib/exirc/client.ex | 132 | ||||
-rw-r--r-- | lib/exirc/example_handler.ex | 8 | ||||
-rw-r--r-- | lib/exirc/utils.ex | 34 |
4 files changed, 94 insertions, 94 deletions
diff --git a/lib/exirc/channels.ex b/lib/exirc/channels.ex index a96cb2e..b7a6d4c 100644 --- a/lib/exirc/channels.ex +++ b/lib/exirc/channels.ex @@ -62,7 +62,7 @@ defmodule ExIrc.Channels do name = downcase(channel_name) case :gb_trees.lookup(name, channel_tree) do {:value, channel} -> - :gb_trees.enter(name, %{channel | :topic => topic}, channel_tree) + :gb_trees.enter(name, %{channel | topic: topic}, channel_tree) :none -> channel_tree end @@ -83,7 +83,7 @@ defmodule ExIrc.Channels do '*' -> :private '=' -> :public end - :gb_trees.enter(name, %{channel | :type => type}, channel_tree) + :gb_trees.enter(name, %{channel | type: type}, channel_tree) :none -> channel_tree end @@ -150,14 +150,14 @@ defmodule ExIrc.Channels do Get a list of all users in a tracked channel """ def channel_users(channel_tree, channel_name) do - get_attr(channel_tree, channel_name, fn(%Channel{:users => users}) -> users end) |> Enum.reverse + get_attr(channel_tree, channel_name, fn(%Channel{users: users}) -> users end) |> Enum.reverse end @doc """ Get the current topic for a tracked channel """ def channel_topic(channel_tree, channel_name) do - case get_attr(channel_tree, channel_name, fn(%Channel{:topic => topic}) -> topic end) do + case get_attr(channel_tree, channel_name, fn(%Channel{topic: topic}) -> topic end) do [] -> "No topic" topic -> topic end @@ -167,7 +167,7 @@ defmodule ExIrc.Channels do Get the type of a tracked channel """ def channel_type(channel_tree, channel_name) do - case get_attr(channel_tree, channel_name, fn(%Channel{:type => type}) -> type end) do + case get_attr(channel_tree, channel_name, fn(%Channel{type: type}) -> type end) do [] -> :unknown type -> type end @@ -177,7 +177,7 @@ defmodule ExIrc.Channels do Determine if a user is present in a tracked channel """ def channel_has_user?(channel_tree, channel_name, nick) do - get_attr(channel_tree, channel_name, fn(%Channel{:users => users}) -> :lists.member(nick, users) end) + get_attr(channel_tree, channel_name, fn(%Channel{users: users}) -> :lists.member(nick, users) end) end @doc """ @@ -201,7 +201,7 @@ defmodule ExIrc.Channels do case :gb_trees.lookup(name, channel_tree) do {:value, channel} -> channel_list = manipfn.(channel.users) - :gb_trees.enter(channel_name, %{channel | :users => channel_list}, channel_tree) + :gb_trees.enter(channel_name, %{channel | users: channel_list}, channel_tree) :none -> channel_tree end diff --git a/lib/exirc/client.ex b/lib/exirc/client.ex index 0bfaf37..0ef50cc 100644 --- a/lib/exirc/client.ex +++ b/lib/exirc/client.ex @@ -304,17 +304,17 @@ defmodule ExIrc.Client do def handle_call(:stop, _from, state) do # Ensure the socket connection is closed if stop is called while still connected to the server if state.connected?, do: Transport.close(state) - {:stop, :normal, :ok, %{state | :connected? => false, :logged_on? => false, :socket => nil}} + {:stop, :normal, :ok, %{state | connected?: false, logged_on?: false, socket: nil}} end # Handles call to add a new event handler process def handle_call({:add_handler, pid}, _from, state) do handlers = do_add_handler(pid, state.event_handlers) - {:reply, :ok, %{state | :event_handlers => handlers}} + {:reply, :ok, %{state | event_handlers: handlers}} end # Handles call to remove an event handler process def handle_call({:remove_handler, pid}, _from, state) do handlers = do_remove_handler(pid, state.event_handlers) - {:reply, :ok, %{state | :event_handlers => handlers}} + {:reply, :ok, %{state | event_handlers: handlers}} end # Handle call to connect to an IRC server def handle_call({:connect, server, port, options, ssl}, _from, state) do @@ -326,7 +326,7 @@ defmodule ExIrc.Client do case Transport.connect(state, String.to_char_list(server), port, [:list, {:packet, :line}, {:keepalive, true}] ++ options) do {:ok, socket} -> send_event {:connected, server, port}, state - {:reply, :ok, %{state | :connected? => true, :server => server, :port => port, :socket => socket}} + {:reply, :ok, %{state | connected?: true, server: server, port: port, socket: socket}} error -> {:reply, error, state} end @@ -335,25 +335,25 @@ defmodule ExIrc.Client do def handle_call(:is_connected?, _from, state), do: {:reply, state.connected?, state} # Prevents any of the following messages from being handled if the client is not connected to a server. # Instead, it returns {:error, :not_connected}. - def handle_call(_, _from, %ClientState{:connected? => false} = state), do: {:reply, {:error, :not_connected}, state} + def handle_call(_, _from, %ClientState{connected?: false} = state), do: {:reply, {:error, :not_connected}, state} # Handle call to login to the connected IRC server - def handle_call({:logon, pass, nick, user, name}, _from, %ClientState{:logged_on? => false} = state) do + def handle_call({:logon, pass, nick, user, name}, _from, %ClientState{logged_on?: false} = state) do Transport.send state, pass!(pass) Transport.send state, nick!(nick) Transport.send state, user!(user, name) - {:reply, :ok, %{state | :pass => pass, :nick => nick, :user => user, :name => name} } + {:reply, :ok, %{state | pass: pass, nick: nick, user: user, name: name} } end # Handles call to change the client's nick. - def handle_call({:nick, new_nick}, _from, %ClientState{:logged_on? => false} = state) do + def handle_call({:nick, new_nick}, _from, %ClientState{logged_on?: false} = state) do Transport.send state, nick!(new_nick) # Since we've not yet logged on, we won't get a nick change message, so we have to remember the nick here. - {:reply, :ok, %{state | :nick => new_nick}} + {:reply, :ok, %{state | nick: new_nick}} end # Handle call to determine if client is logged on to a server def handle_call(:is_logged_on?, _from, state), do: {:reply, state.logged_on?, state} # Prevents any of the following messages from being handled if the client is not logged on to a server. # Instead, it returns {:error, :not_logged_in}. - def handle_call(_, _from, %ClientState{:logged_on? => false} = state), do: {:reply, {:error, :not_logged_in}, state} + def handle_call(_, _from, %ClientState{logged_on?: false} = state), do: {:reply, {:error, :not_logged_in}, state} # Handles call to send a message def handle_call({:msg, type, nick, msg}, _from, state) do data = case type do @@ -407,7 +407,7 @@ defmodule ExIrc.Client do send_event :disconnected, state Transport.close state end - {:reply, :ok, %{state | :connected? => false, :logged_on? => false, :socket => nil}} + {:reply, :ok, %{state | connected?: false, logged_on?: false, socket: nil}} end # Handles call to change the client's nick def handle_call({:nick, new_nick}, _from, state) do Transport.send(state, nick!(new_nick)); {:reply, :ok, state} end @@ -428,7 +428,7 @@ defmodule ExIrc.Client do # Handles message to add a new event handler process asynchronously def handle_cast({:add_handler, pid}, state) do handlers = do_add_handler(pid, state.event_handlers) - {:noreply, %{state | :event_handlers => handlers}} + {:noreply, %{state | event_handlers: handlers}} end @doc """ Handles asynchronous messages from the external API. Not recommended to call these directly. @@ -436,20 +436,20 @@ defmodule ExIrc.Client do # Handles message to remove an event handler process asynchronously def handle_cast({:remove_handler, pid}, state) do handlers = do_remove_handler(pid, state.event_handlers) - {:noreply, %{state | :event_handlers => handlers}} + {:noreply, %{state | event_handlers: handlers}} end @doc """ Handle messages from the TCP socket connection. """ # Handles the client's socket connection 'closed' event - def handle_info({:tcp_closed, _socket}, %ClientState{:server => server, :port => port} = state) do + def handle_info({:tcp_closed, _socket}, %ClientState{server: server, port: port} = state) do info "Connection to #{server}:#{port} closed!" send_event :disconnected, state new_state = %{state | - :socket => nil, - :connected? => false, - :logged_on? => false, - :channels => Channels.init() + socket: nil, + connected?: false, + logged_on?: false, + channels: Channels.init() } {:noreply, new_state} end @@ -461,13 +461,13 @@ defmodule ExIrc.Client do handle_info({:tcp_closed, socket}, state) end # Handles any TCP errors in the client's socket connection - def handle_info({:tcp_error, socket, reason}, %ClientState{:server => server, :port => port} = state) do + def handle_info({:tcp_error, socket, reason}, %ClientState{server: server, port: port} = state) do error "TCP error in connection to #{server}:#{port}:\r\n#{reason}\r\nClient connection closed." new_state = %{state | - :socket => nil, - :connected? => false, - :logged_on? => false, - :channels => Channels.init() + socket: nil, + connected?: false, + logged_on?: false, + channels: Channels.init() } {:stop, {:tcp_error, socket}, new_state} end @@ -479,12 +479,12 @@ defmodule ExIrc.Client do def handle_info({:tcp, _, data}, state) do debug? = state.debug? case Utils.parse(data) do - %IrcMessage{:ctcp => true} = msg -> + %IrcMessage{ctcp: true} = msg -> handle_data msg, state {:noreply, state} - %IrcMessage{:ctcp => false} = msg -> + %IrcMessage{ctcp: false} = msg -> handle_data msg, state - %IrcMessage{:ctcp => :invalid} = msg when debug? -> + %IrcMessage{ctcp: :invalid} = msg when debug? -> send_event msg, state {:noreply, state} _ -> @@ -498,7 +498,7 @@ defmodule ExIrc.Client do # If an event handler process dies, remove it from the list of event handlers def handle_info({:DOWN, _, _, pid, _}, state) do handlers = do_remove_handler(pid, state.event_handlers) - {:noreply, %{state | :event_handlers => handlers}} + {:noreply, %{state | event_handlers: handlers}} end # Catch-all for unrecognized messages (do nothing) def handle_info(_, state) do @@ -510,7 +510,7 @@ defmodule ExIrc.Client do def terminate(_reason, state) do if state.socket != nil do Transport.close state - %{state | :socket => nil} + %{state | socket: nil} end :ok end @@ -527,39 +527,39 @@ defmodule ExIrc.Client do Handle IrcMessages received from the server. """ # Called upon successful login - def handle_data(%IrcMessage{:cmd => @rpl_welcome}, %ClientState{:logged_on? => false} = state) do + def handle_data(%IrcMessage{cmd: @rpl_welcome}, %ClientState{logged_on?: false} = state) do if state.debug?, do: debug "SUCCESFULLY LOGGED ON" - new_state = %{state | :logged_on? => true, :login_time => :erlang.timestamp()} + new_state = %{state | logged_on?: true, login_time: :erlang.timestamp()} send_event :logged_in, new_state {:noreply, new_state} end # Called when the server sends it's current capabilities - def handle_data(%IrcMessage{:cmd => @rpl_isupport} = msg, state) do + def handle_data(%IrcMessage{cmd: @rpl_isupport} = msg, state) do if state.debug?, do: debug "RECEIVING SERVER CAPABILITIES" {:noreply, Utils.isup(msg.args, state)} end # Called when the client enters a channel - def handle_data(%IrcMessage{:nick => nick, :cmd => "JOIN"} = msg, %ClientState{:nick => nick} = state) do + def handle_data(%IrcMessage{nick: nick, cmd: "JOIN"} = msg, %ClientState{nick: nick} = state) do channel = msg.args |> List.first |> String.strip if state.debug?, do: debug "JOINED A CHANNEL #{channel}" channels = Channels.join(state.channels, channel) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:joined, channel}, new_state {:noreply, new_state} end # Called when another user joins a channel the client is in - def handle_data(%IrcMessage{:nick => user_nick, :cmd => "JOIN"} = msg, state) do + def handle_data(%IrcMessage{nick: user_nick, cmd: "JOIN"} = msg, state) do channel = msg.args |> List.first |> String.strip if state.debug?, do: debug "ANOTHER USER JOINED A CHANNEL: #{channel} - #{user_nick}" channels = Channels.user_join(state.channels, channel, user_nick) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:joined, channel, user_nick}, new_state {:noreply, new_state} end # Called on joining a channel, to tell us the channel topic # Message with three arguments is not RFC compliant but very common # Message with two arguments is RFC compliant - def handle_data(%IrcMessage{:cmd => @rpl_topic} = msg, state) do + def handle_data(%IrcMessage{cmd: @rpl_topic} = msg, state) do {channel, topic} = case msg.args do [_nick, channel, topic] -> {channel, topic} [channel, topic] -> {channel, topic} @@ -569,20 +569,20 @@ defmodule ExIrc.Client do debug "1. TOPIC SET FOR #{channel} TO #{topic}" end channels = Channels.set_topic(state.channels, channel, topic) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:topic_changed, channel, topic}, new_state {:noreply, new_state} end # Called when the topic changes while we're in the channel - def handle_data(%IrcMessage{:cmd => "TOPIC", :args => [channel, topic]}, state) do + def handle_data(%IrcMessage{cmd: "TOPIC", args: [channel, topic]}, state) do if state.debug?, do: debug "TOPIC CHANGED FOR #{channel} TO #{topic}" channels = Channels.set_topic(state.channels, channel, topic) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:topic_changed, channel, topic}, new_state {:noreply, new_state} end # Called when joining a channel with the list of current users in that channel, or when the NAMES command is sent - def handle_data(%IrcMessage{:cmd => @rpl_namereply} = msg, state) do + def handle_data(%IrcMessage{cmd: @rpl_namereply} = msg, state) do if state.debug?, do: debug "NAMES LIST RECEIVED" {_nick, channel_type, channel, names} = case msg.args do [nick, channel_type, channel, names] -> {nick, channel_type, channel, names} @@ -595,53 +595,53 @@ defmodule ExIrc.Client do send_event({:names_list, channel, names}, state) - {:noreply, %{state | :channels => channels}} + {:noreply, %{state | channels: channels}} end # Called when our nick has succesfully changed - def handle_data(%IrcMessage{:cmd => "NICK", :nick => nick, :args => [new_nick]}, %ClientState{:nick => nick} = state) do + def handle_data(%IrcMessage{cmd: "NICK", nick: nick, args: [new_nick]}, %ClientState{nick: nick} = state) do if state.debug?, do: debug "NICK CHANGED FROM #{nick} TO #{new_nick}" - new_state = %{state | :nick => new_nick} + new_state = %{state | nick: new_nick} send_event {:nick_changed, new_nick}, new_state {:noreply, new_state} end # Called when someone visible to us changes their nick - def handle_data(%IrcMessage{:cmd => "NICK", :nick => nick, :args => [new_nick]}, state) do + def handle_data(%IrcMessage{cmd: "NICK", nick: nick, args: [new_nick]}, state) do if state.debug?, do: debug "#{nick} CHANGED THEIR NICK TO #{new_nick}" channels = Channels.user_rename(state.channels, nick, new_nick) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:nick_changed, nick, new_nick}, new_state {:noreply, new_state} end # Called upon mode change - def handle_data(%IrcMessage{:cmd => "MODE", args: [channel, op, user]}, state) do + def handle_data(%IrcMessage{cmd: "MODE", args: [channel, op, user]}, state) do if state.debug?, do: debug "MODE #{channel} #{op} #{user}" send_event {:mode, [channel, op, user]}, state {:noreply, state} end # Called when we leave a channel - def handle_data(%IrcMessage{:cmd => "PART", :nick => nick} = msg, %ClientState{:nick => nick} = state) do + def handle_data(%IrcMessage{cmd: "PART", nick: nick} = msg, %ClientState{nick: nick} = state) do channel = msg.args |> List.first |> String.strip if state.debug?, do: debug "WE LEFT A CHANNEL: #{channel}" channels = Channels.part(state.channels, channel) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:parted, channel}, new_state {:noreply, new_state} end # Called when someone else in our channel leaves - def handle_data(%IrcMessage{:cmd => "PART", :nick => from, :host => host, :user => user} = msg, state) do - sender = %SenderInfo{:nick => from, :host => host, :user => user} + def handle_data(%IrcMessage{cmd: "PART", nick: from, host: host, user: user} = msg, state) do + sender = %SenderInfo{nick: from, host: host, user: user} channel = msg.args |> List.first |> String.strip if state.debug?, do: debug "#{from} LEFT A CHANNEL: #{channel}" channels = Channels.user_part(state.channels, channel, from) - new_state = %{state | :channels => channels} + new_state = %{state | channels: channels} send_event {:parted, channel, sender}, new_state {:noreply, new_state} end # Called when we receive a PING - def handle_data(%IrcMessage{:cmd => "PING"} = msg, %ClientState{:autoping => true} = state) do + def handle_data(%IrcMessage{cmd: "PING"} = msg, %ClientState{autoping: true} = state) do if state.debug?, do: debug "RECEIVED A PING!" case msg do - %IrcMessage{:args => [from]} -> + %IrcMessage{args: [from]} -> if state.debug?, do: debug("SENT PONG2") Transport.send(state, pong2!(from, msg.server)) _ -> @@ -651,36 +651,36 @@ defmodule ExIrc.Client do {:noreply, state}; end # Called when we are invited to a channel - def handle_data(%IrcMessage{:cmd => "INVITE", :args => [nick, channel], :nick => by, :host => host, :user => user} = msg, %ClientState{:nick => nick} = state) do - sender = %SenderInfo{:nick => by, :host => host, :user => user} + def handle_data(%IrcMessage{cmd: "INVITE", args: [nick, channel], nick: by, host: host, user: user} = msg, %ClientState{nick: nick} = state) do + sender = %SenderInfo{nick: by, host: host, user: user} if state.debug?, do: debug "RECEIVED AN INVITE: #{msg.args |> Enum.join(" ")}" send_event {:invited, sender, channel}, state {:noreply, state} end # Called when we are kicked from a channel - def handle_data(%IrcMessage{:cmd => "KICK", :args => [channel, nick], :nick => by, :host => host, :user => user} = _msg, %ClientState{:nick => nick} = state) do - sender = %SenderInfo{:nick => by, :host => host, :user => user} + def handle_data(%IrcMessage{cmd: "KICK", args: [channel, nick], nick: by, host: host, user: user} = _msg, %ClientState{nick: nick} = state) do + sender = %SenderInfo{nick: by, host: host, user: user} if state.debug?, do: debug "WE WERE KICKED FROM #{channel} BY #{by}" send_event {:kicked, sender, channel}, state {:noreply, state} end # Called when someone else was kicked from a channel - def handle_data(%IrcMessage{:cmd => "KICK", :args => [channel, nick], :nick => by, :host => host, :user => user} = _msg, state) do - sender = %SenderInfo{:nick => by, :host => host, :user => user} + def handle_data(%IrcMessage{cmd: "KICK", args: [channel, nick], nick: by, host: host, user: user} = _msg, state) do + sender = %SenderInfo{nick: by, host: host, user: user} if state.debug?, do: debug "#{nick} WAS KICKED FROM #{channel} BY #{by}" send_event {:kicked, nick, sender, channel}, state {:noreply, state} end # Called when someone sends us a message - def handle_data(%IrcMessage{:nick => from, :cmd => "PRIVMSG", :args => [nick, message], :host => host, :user => user} = _msg, %ClientState{:nick => nick} = state) do - sender = %SenderInfo{:nick => from, :host => host, :user => user} + def handle_data(%IrcMessage{nick: from, cmd: "PRIVMSG", args: [nick, message], host: host, user: user} = _msg, %ClientState{nick: nick} = state) do + sender = %SenderInfo{nick: from, host: host, user: user} if state.debug?, do: debug "#{from} SENT US #{message}" send_event {:received, message, sender}, state {:noreply, state} end # Called when someone sends a message to a channel we're in, or a list of users - def handle_data(%IrcMessage{:nick => from, :cmd => "PRIVMSG", :args => [to, message], :host => host, :user => user} = _msg, %ClientState{:nick => nick} = state) do - sender = %SenderInfo{:nick => from, :host => host, :user => user} + def handle_data(%IrcMessage{nick: from, cmd: "PRIVMSG", args: [to, message], host: host, user: user} = _msg, %ClientState{nick: nick} = state) do + sender = %SenderInfo{nick: from, host: host, user: user} if state.debug?, do: debug "#{from} SENT #{message} TO #{to}" send_event {:received, message, sender, to}, state # If we were mentioned, fire that event as well @@ -688,8 +688,8 @@ defmodule ExIrc.Client do {:noreply, state} end # Called when someone uses ACTION, i.e. `/me dies` - def handle_data(%IrcMessage{:nick => from, :cmd => "ACTION", :args => [channel, message], :host => host, :user => user} = _msg, state) do - sender = %SenderInfo{:nick => from, :host => host, :user => user} + def handle_data(%IrcMessage{nick: from, cmd: "ACTION", args: [channel, message], host: host, user: user} = _msg, state) do + sender = %SenderInfo{nick: from, host: host, user: user} if state.debug?, do: debug "* #{from} #{message} in #{channel}" send_event {:me, message, sender, channel}, state {:noreply, state} @@ -704,7 +704,7 @@ defmodule ExIrc.Client do ############### # Internal API ############### - defp send_event(msg, %ClientState{:event_handlers => handlers}) when is_list(handlers) do + defp send_event(msg, %ClientState{event_handlers: handlers}) when is_list(handlers) do Enum.each(handlers, fn({pid, _}) -> Kernel.send(pid, msg) end) end diff --git a/lib/exirc/example_handler.ex b/lib/exirc/example_handler.ex index 251afaf..48774fd 100644 --- a/lib/exirc/example_handler.ex +++ b/lib/exirc/example_handler.ex @@ -27,10 +27,10 @@ defmodule ExampleHandler do def handle_info(:logged_in, _state) do IO.puts "Logged in!" end - def handle_info(%IrcMessage{:nick => from, :cmd => "PRIVMSG", :args => ["mynick", msg]}, _state) do + def handle_info(%IrcMessage{nick: from, cmd: "PRIVMSG", args: ["mynick", msg]}, _state) do IO.puts "Received a private message from \#{from}: \#{msg}" end - def handle_info(%IrcMessage{:nick => from, :cmd => "PRIVMSG", :args => [to, msg]}, _state) do + def handle_info(%IrcMessage{nick: from, cmd: "PRIVMSG", args: [to, msg]}, _state) do IO.puts "Received a message in \#{to} from \#{from}: \#{msg}" end """ @@ -111,11 +111,11 @@ defmodule ExampleHandler do {:noreply, nil} end # This is an example of how you can manually catch commands if ExIrc.Client doesn't send a specific message for it - def handle_info(%IrcMessage{:nick => from, :cmd => "PRIVMSG", :args => ["testnick", msg]}, _state) do + def handle_info(%IrcMessage{nick: from, cmd: "PRIVMSG", args: ["testnick", msg]}, _state) do debug "Received a private message from #{from}: #{msg}" {:noreply, nil} end - def handle_info(%IrcMessage{:nick => from, :cmd => "PRIVMSG", :args => [to, msg]}, _state) do + def handle_info(%IrcMessage{nick: from, cmd: "PRIVMSG", args: [to, msg]}, _state) do debug "Received a message in #{to} from #{from}: #{msg}" {:noreply, nil} end diff --git a/lib/exirc/utils.ex b/lib/exirc/utils.ex index 076a497..2293972 100644 --- a/lib/exirc/utils.ex +++ b/lib/exirc/utils.ex @@ -34,14 +34,14 @@ defmodule ExIrc.Utils do woven = weave(splits, parts) case woven do [nick, "!", user, "@" | host] -> - %{msg | :nick => nick, :user => user, :host => Enum.join(host)} + %{msg | nick: nick, user: user, host: Enum.join(host)} [nick, "@" | host] -> - %{msg | :nick => nick, :host => Enum.join(host)} + %{msg | nick: nick, host: Enum.join(host)} [_, "." | _] -> # from is probably a server name - %{msg | :server => to_string(from)} + %{msg | server: to_string(from)} [nick] -> - %{msg | :nick => nick} + %{msg | nick: nick} end end @@ -57,17 +57,17 @@ defmodule ExIrc.Utils do case args do args when args != [] -> %{msg | - :cmd => to_string(ctcp_cmd), - :args => [to_string(target), args |> Enum.join(" ")], - :ctcp => true + cmd: to_string(ctcp_cmd), + args: [to_string(target), args |> Enum.join(" ")], + ctcp: true } _ -> - %{msg | :cmd => to_string(cmd), :ctcp => :invalid} + %{msg | cmd: to_string(cmd), ctcp: :invalid} end end defp get_cmd([cmd | rest], msg) do - get_args(rest, %{msg | :cmd => to_string(cmd)}) + get_args(rest, %{msg | cmd: to_string(cmd)}) end @@ -78,25 +78,25 @@ defmodule ExIrc.Utils do |> Enum.filter(fn(arg) -> arg != [] end) |> Enum.map(&trim_crlf/1) |> Enum.map(&List.to_string/1) - %{msg | :args => args} + %{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 | []], msg) do - get_args [], %{msg | :args => [arg | msg.args]} + get_args [], %{msg | args: [arg | msg.args]} 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 ############################ @@ -121,16 +121,16 @@ defmodule ExIrc.Utils do defp isup_param("CHANTYPES=" <> channel_prefixes, state) do prefixes = channel_prefixes |> String.split("", trim: true) - %{state | :channel_prefixes => prefixes} + %{state | channel_prefixes: prefixes} end defp isup_param("NETWORK=" <> network, state) do - %{state | :network => network} + %{state | network: network} end defp isup_param("PREFIX=" <> user_prefixes, state) do prefixes = Regex.run(~r/\((.*)\)(.*)/, user_prefixes, capture: :all_but_first) |> Enum.map(&String.to_char_list/1) |> List.zip - %{state | :user_prefixes => prefixes} + %{state | user_prefixes: prefixes} end defp isup_param(_, state) do state |