Added botsnack functionality to the irc application
authorMatt Mullins <mmullins@mmlx.us>
Sun, 22 May 2011 06:26:00 +0000 (01:26 -0500)
committerMatt Mullins <mmullins@mmlx.us>
Sun, 22 May 2011 06:26:00 +0000 (01:26 -0500)
irc/irc_conn.erl

index 8a062c6..f15cb8f 100644 (file)
@@ -79,12 +79,27 @@ do_line(Line, State) ->
             {_, _, _, _, Channels} = State#irc_state.config,
             lists:foreach(fun join_channel/1, Channels),
             State#irc_state{joined = true};
+        "PRIVMSG" ->
+            do_privmsg(Command),
+            State;
         _ ->
             % for now, just know that it happened
             error_logger:info_msg("Received a line ~p~n", [Line]),
             State
     end.
 
+do_privmsg(_Command = #irc_command{middles = Middles, trailing = Text}) ->
+    case Text of
+        "!botsnack" ++ _ ->
+            Choices = {"*chomp*", ":P", "yay", "meh", "\\o/"},
+            Index = random:uniform(size(Choices)),
+            NewCommand = #irc_command{command = "PRIVMSG",
+                                      middles = Middles,
+                                      trailing = element(Index, Choices)},
+            send_command(NewCommand);
+        _ -> ok
+    end.
+
 terminate(_Reason, _State) ->
     ok.