-
Notifications
You must be signed in to change notification settings - Fork 22
Plugins
gdamjan edited this page Aug 31, 2010
·
9 revisions
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 {Ref, {match, [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:send_data([..,..])
.
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}.