Skip to content

Commit

Permalink
Implement on_server_notice which triggers when a server sends a notice
Browse files Browse the repository at this point in the history
  • Loading branch information
mazenharake committed Apr 18, 2011
1 parent bb112ae commit 36222d1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
15 changes: 10 additions & 5 deletions src/eirc_example_bot.erl
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@

-include("eirc.hrl").

-export([init/2, on_connect/3, on_logon/5, on_logon/1, on_text/4, on_notice/4,
on_join/3, on_part/3, on_ctcp/4, on_mode/5, on_topic/4, on_ping/1,
on_nick/3, on_raw/3, on_kick/5, on_quit/3, handle_call/3,
terminate/2]).
-export([init/2, on_connect/3, on_logon/5, on_logon/1, on_text/4,
on_server_notice/3, on_notice/4, on_join/3, on_part/3, on_ctcp/4,
on_mode/5, on_topic/4, on_ping/1, on_nick/3, on_raw/3, on_kick/5,
on_quit/3, handle_call/3, terminate/2]).

-compile(export_all).

Expand Down Expand Up @@ -94,7 +94,12 @@ on_text(From, To, Text, State) ->
io:format("TEXT: From (~p) To (~p) - ~p ~n", [From, To, Text]),
{ok, State}.

%% Like on_text but triggers on NOTICE messages instead
%% Triggers when the server sends us a message and not another user
on_server_notice(ServerName, Msg, State) ->
io:format("NOTICE (~p): ~1000p~n", [ServerName, Msg]),
{ok, State}.

%% Like on_text but triggers on NOTICE messages instead, sent by a user
on_notice(From, To, Text, State) ->
io:format("NOTICE: From (~p) To (~p) - ~p ~n", [From, To, Text]),
{ok, State}.
Expand Down
13 changes: 9 additions & 4 deletions src/gen_eircbot.erl
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ get_call_tuple(#ircmsg{ cmd = "PRIVMSG" } = IrcMsg, State) ->
FromNick = IrcMsg#ircmsg.nick,
[ToNick|Msg] = IrcMsg#ircmsg.args,
{State, on_text, [FromNick, ToNick, lists:flatten(Msg)]};
get_call_tuple(#ircmsg{ cmd = "NOTICE", nick = undefined } = IrcMsg, State) ->
Server = IrcMsg#ircmsg.server,
[_|Msg] = IrcMsg#ircmsg.args,
{State, on_server_notice, [Server, Msg]};
get_call_tuple(#ircmsg{ cmd = "NOTICE" } = IrcMsg, State) ->
FromNick = IrcMsg#ircmsg.nick,
[ToNick|Msg] = IrcMsg#ircmsg.args,
Expand Down Expand Up @@ -238,7 +242,8 @@ callback({State, CBFunction, Args}) ->
%% Behaviour API
%% =============================================================================
behaviour_info(callbacks) ->
[{init, 2}, {on_connect, 3}, {on_logon, 5}, {on_logon, 1}, {on_text, 4}, {on_notice, 4},
{on_join, 3}, {on_part, 3}, {on_ctcp, 4}, {on_mode, 5}, {on_topic, 4},
{on_ping, 1}, {on_kick, 5}, {on_nick, 3}, {on_quit, 3}, {on_ctcp, 4},
{on_raw, 3}, {handle_call, 3}, {terminate, 2}].
[{init, 2}, {on_connect, 3}, {on_logon, 5}, {on_logon, 1}, {on_text, 4},
{on_server_notice, 3}, {on_notice, 4}, {on_join, 3}, {on_part, 3},
{on_ctcp, 4}, {on_mode, 5}, {on_topic, 4}, {on_ping, 1}, {on_kick, 5},
{on_nick, 3}, {on_quit, 3}, {on_ctcp, 4}, {on_raw, 3}, {handle_call, 3},
{terminate, 2}].

0 comments on commit 36222d1

Please sign in to comment.