Commits

Anonymous committed 25bd369

Removed older source files

  • Participants
  • Parent commits e5e2d91

Comments (0)

Files changed (3)

File irc_event_manager.erl

--module(irc_event_manager).
--author("jrb").
-
--export([start_link/0, add_handler/1, notify/1]).
-
-%% Our external API
-
-start_link() ->
-
-	io:format("IRC Event Manager start_link called. ~n", []),
-	gen_event:start_link({local, ?MODULE}).
-
-add_handler(Module) ->
-	gen_event:add_handler(?MODULE, Module, []).
-
-notify(Event) ->
-	gen_event:notify(?MODULE, Event).
-
-

File irc_rawtext_handler.erl

--module(irc_rawtext_handler).
-
--behaviour(gen_event).
-
-%% API
-
-%% gen_event callbacks
--export([init/1, handle_event/2, handle_call/2,
-         handle_info/2, terminate/2, code_change/3]).
-
-%%====================================================================
-%% API
-%%====================================================================
-%%--------------------------------------------------------------------
-%%--------------------------------------------------------------------
-
-%%====================================================================
-%% gen_event callbacks
-%%====================================================================
-%%--------------------------------------------------------------------
-%% Function: init(Args) -> {ok, State}
-%% Description: Whenever a new event handler is added to an event manager,
-%% this function is called to initialize the event handler.
-%%--------------------------------------------------------------------
-init([]) ->
-  io:format("[o] rawtext_handler initialized~n", []),
-  {ok, 0}.
-
-%%--------------------------------------------------------------------
-%% Function:
-%% handle_event(Event, State) -> {ok, State} |
-%%                               {swap_handler, Args1, State1, Mod2, Args2} |
-%%                               remove_handler
-
-%% {parsed_msg, From, Operation, To, Options, Message}
-
-
-handle_event({parsed_msg, From, Operation, To, Options, Message}, State) ->
-	io:format("<~p> ~p~n", [From, Message]),
-	{ok, State};
-
-handle_event({raw_text, Data}, State) ->
-	io:format("Unparsed message received: ~p", [ Data ]),
-
-	{ok, State};
-handle_event(_Event, State) ->
-  {ok, State}.
-
-%%--------------------------------------------------------------------
-%% Function:
-%% handle_call(Request, State) -> {ok, Reply, State} |
-%%                                {swap_handler, Reply, Args1, State1,
-%%                                  Mod2, Args2} |
-%%                                {remove_handler, Reply}
-%% Description: Whenever an event manager receives a request sent using
-%% gen_event:call/3,4, this function is called for the specified event
-%% handler to handle the request.
-%%--------------------------------------------------------------------
-handle_call(_Request, State) ->
-  Reply = ok,
-  {reply, Reply, State}.
-
-%%--------------------------------------------------------------------
-%% Function:
-%% handle_info(Info, State) -> {ok, State} |
-%%                             {swap_handler, Args1, State1, Mod2, Args2} |
-%%                              remove_handler
-%% Description: This function is called for each installed event handler when
-%% an event manager receives any other message than an event or a synchronous
-%% request (or a system message).
-%%--------------------------------------------------------------------
-handle_info(_Info, State) ->
-  {ok, State}.
-
-%%--------------------------------------------------------------------
-%% Function: terminate(Reason, State) -> void()
-%% Description:Whenever an event handler is deleted from an event manager,
-%% this function is called. It should be the opposite of Module:init/1 and
-%% do any necessary cleaning up.
-%%--------------------------------------------------------------------
-terminate(_Reason, _State) ->
-  ok.
-
-%%--------------------------------------------------------------------
-%% Function: code_change(OldVsn, State, Extra) -> {ok, NewState}
-%% Description: Convert process state when code is changed
-%%--------------------------------------------------------------------
-code_change(_OldVsn, State, _Extra) ->
-  {ok, State}.

File ircbot_server.erl

--module(ircbot_server).
--author('begemanj@gmail.com').
-
--define(LINEFEED, "\r\n").
--define(TCP_OPTIONS, [binary, {packet, line}, {keepalive, true} ]).
-
-
-
--behaviour(gen_server).
-
--export([start_link/0, test/1, connect/4, join/1, say/2, start/0, pong/1]).
-
--export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
-         code_change/3]).
-%%--------------
-%%
-%% external API
-%%
-%%--------------
-
-
-start() ->
-   start_link(),
-   connect("irc.synirc.net", 6667, "neckbeard", "neckbeard").
-start_link() ->
-  irc_event_manager:start_link(),
-  irc_event_manager:add_handler(irc_rawtext_handler),
-  gen_server:start_link({local, ?MODULE}, ?MODULE, [], []).
-
-test(Msg) ->
-   gen_server:cast(?MODULE, {test, Msg}).
-
-connect(Server, Port, Nick, Real) ->
-	gen_server:call(?MODULE, {connect, [Server, Port, Nick, Real]}).
-
-join(Channel) ->
-	gen_server:call(?MODULE, {join, Channel}).
-
-
-say(Focus, Msg) ->
-	gen_server:call(?MODULE, {say, [Focus, Msg]}).
-
-pong(Server) ->
-	gen_server:call(?MODULE, {pong, Server}).
-
-%%------------------------------
-%%
-%% gen_server callback functions
-%% 
-%%------------------------------
-init(_Args) ->
-
-	{ok, none}.
-
-handle_call({connect, [Server, Port, Nick, Real]}, _From, _State) ->
-	{ok, Sock} = gen_tcp:connect(Server, Port, ?TCP_OPTIONS),
-
-        gen_tcp:send(Sock, ["NICK ", Nick, ?LINEFEED]),
-        gen_tcp:send(Sock, ["USER ", Nick, " 8 * :", Real, ?LINEFEED]),
-
-        { reply, ok, Sock };
-
-handle_call({disconnect, QuitMsg}, _From, State) ->
-	gen_tcp:send(State, ["QUIT ", QuitMsg]),
-	gen_tcp:close(State),
-	
-	{ reply, ok, none };
-
-handle_call({join, Channel }, _From, State) ->
-	gen_tcp:send(State, ["JOIN ", Channel, ?LINEFEED]),
-	{reply, ok, State };
-handle_call({pong, Server}, _From, State) ->
-	gen_tcp:send(State, ["PONG :", Server, ?LINEFEED]),
-	{reply, ok, State};
-
-handle_call({say, [Focus, Msg]}, _From, State) ->
-	gen_tcp:send(State, ["PRIVMSG ", Focus, " :",  Msg, ?LINEFEED]),
-	{reply, ok, State};
-
-
-handle_call({raw, String}, _From, State) ->
-	gen_tcp:send(State, String),
-	{reply, ok, State};
-
-handle_call(_Request, _From, State) ->
-  Reply = ok,
-  {reply, Reply, State}.
-
-
-%%--------------------------------------------------------------------
-%% Function: handle_cast(Msg, State) -> {noreply, State} |
-%%                                      {noreply, State, Timeout} |
-%%                                      {stop, Reason, State}
-%% Description: Handling cast messages
-%%--------------------------------------------------------------------
-handle_cast(_Msg, State) ->
-  {noreply, State}.
-
-
-
-handle_info({tcp, _Sock, <<$:, ServerBin/binary>>}, State) ->
-	ServerMessage = binary_to_list(ServerBin),
-	%% I copied this method of parsing server messages from manderlbot, it seems to be the easiest way.
-	%% props to mickael remond <3
-	
-	BodyPos = string:chr(ServerMessage, $:),
-
-	case BodyPos > 0 of
-		true ->
-			Command = string:tokens(string:substr(ServerMessage, 1, BodyPos - 2), " "),
-	
-			case length(Command) of
-				1 ->
-					From = lists:nth(1, Command),
-					Operation = none,
-					To = none,
-					Options = none;
-				2 ->
-					From = lists:nth(1, Command),
-					Operation = lists:nth(2, Command),
-					To = none,
-					Options = none;
-				
-				3 ->	
-					From = lists:nth(1, Command),
-					Operation = lists:nth(2, Command),
-					To = lists:nth(3, Command),
-					Options = none;
-	
-				Other ->
-                	                From = lists:nth(1, Command),
-                        	        Operation = lists:nth(2, Command),
-                                	To = lists:nth(3, Command),
-					Options = lists:nthtail(3, Command)
-		   	end,	
-
-
-		    Message = string:substr(ServerMessage, BodyPos + 1),
-
-		    irc_event_manager:notify({parsed_msg, From, Operation, To, Options, Message}),
-		    {noreply, State};
-
-		false ->
-			%% Our command has no accompanying message so just parse as is
-			Command = string:tokens(ServerMessage, " "),
-			Operation = lists:nth(2, Command),
-			From = lists:nth(1, Command),
-			To = lists:nth(3, Command),
-			irc_event_manager:notify({parsed_msg, From, Operation, To}),
-			{noreply, State}
-	end;	 
-handle_info({tcp, _Sock, <<"PING :",  FromBin/binary>>}, State) ->
-	From = binary_to_list(FromBin),
-	gen_server:call(?MODULE, {pong, From}),		
-
-
-	{noreply, State};
-
-handle_info({tcp, _Sock, Data}, State) ->
-
-	irc_event_manager:notify({raw_text,  Data}),
-	{noreply, State};
-		
-	
-handle_info(_Info, State) ->
-  {noreply, State}.
-
-
-terminate(_Reason, _State) ->
-	ok.
-
-code_change(_OldVsn, State, _Extra) ->
-  {ok, State}.