From 4a58aa67cab65320c7039abf28fb65f73c8a2913 Mon Sep 17 00:00:00 2001 From: Matt Mullins Date: Sun, 22 May 2011 01:26:00 -0500 Subject: [PATCH] Added botsnack functionality to the irc application --- irc/irc_conn.erl | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/irc/irc_conn.erl b/irc/irc_conn.erl index 8a062c6..f15cb8f 100644 --- a/irc/irc_conn.erl +++ b/irc/irc_conn.erl @@ -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. -- 2.11.0