Skip to content

Instantly share code, notes, and snippets.

@wrboyce
Created September 1, 2011 09:52
Show Gist options
  • Select an option

  • Save wrboyce/1185847 to your computer and use it in GitHub Desktop.

Select an option

Save wrboyce/1185847 to your computer and use it in GitHub Desktop.
erb module example
-module(helloworld).
-behaviour(gen_server).
-include("erb.hrl").
-export([start_link/1]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]).
-define(SERVER, ?MODULE).
start_link(Bot) ->
gen_server:start_link(?SERVER, ?MODULE, [Bot], []).
init([Bot]) ->
ok = gen_server:call(Bot#bot.router, {subscribeToCommand, hello}),
{ok, {}}.
handle_call(_Request, _From, State) ->
{noreply, State}.
handle_cast({hello, Data}, State) ->
[Nick|_] = string:tokens(Data#data.origin, "!@"),
Message = io_lib:format("Hello, ~s!", [Nick]),
ok = gen_server:cast((State#state.bot)#bot.dispatcher, {privmsg, Data#data.destination, Message}),
{noreply, State};
handle_cast(_Request, State) ->
{noreply, State}.
handle_info(_Reqest, State) ->
{noreply, State}.
terminate(_Reason, _State) ->
ok.
code_change(_OldVsn, State, _Extra) ->
{ok, State}.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment