Skip to content
gdamjan edited this page Sep 12, 2010 · 9 revisions

The plugin interface

Plugins are written as Erlang gen_event handlers.

As each message is received from the server, it will be parsed/splited to a list of:

[SenderNick, SenderFullNameServer, Command, CommandParam1.., Message]

The most used Command would be <<"PRIVMSG">> which has one CommandParam which is either the channel name (if i starts with a #) or the bot Nick if it’s a direct message.

This list is broadcast to all plugins, which can handle it in their handle_event/2 function:

handle_event(Msg, State) ->
   case Msg of
     {in, Ref, [Sender, _Name, <<"PRIVMSG">>, <<"#",Channel/binary>>, Message]} ->
      ... process the request ... 
        {ok, NewState}
     _ ->  %% catch all
       {ok, State}
    end.

If the plugin wants to reply to the request it can send a message to the master process via the Ref, i.e
Ref:privmsg(<<"#channel">>, "response").

The State variable is used for keeping some State in the handler. The state is initalized in the init/1 function in the module. As the handle_event/2 returns it should return witk the tuple {ok, NewState}.

Clone this wiki locally