Created
February 5, 2012 04:20
-
-
Save geoff-kruss/1742667 to your computer and use it in GitHub Desktop.
server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(talbot_server). | |
-author('geoff_kruss'). | |
-behaviour(gen_server). | |
-include("talbot.hrl"). | |
%% gen_server callbacks | |
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2, code_change/3]). | |
%% api functions | |
-export([start_link/0]). | |
-define(SERVER, ?MODULE). | |
%%%---- API Functions ---- | |
start_link() -> | |
gen_server:start_link({local, ?SERVER}, ?SERVER, [], []). | |
%%%---- gen_server callbacks ---- | |
init([]) -> | |
State = #bot{}, | |
{ok, State}. | |
%% Connect to an irc network %%% | |
handle_call({connect, [Server, Port, Nick]}, _From, State) -> | |
{ok, Sock} = gen_tcp:connect(Server, Port, ?TCP_OPTIONS), | |
gen_tcp:send(Sock, "NICK geoffreytest \r\n"), | |
gen_tcp:send(Sock, "USER geoffreytest 8 * : geoffreytest \r\n"), | |
NewState = State#bot{socket = Sock}, | |
{reply,{ok}, NewState}; | |
handle_call({join, [Channel]}, _From, State) -> | |
Sock = State#bot.socket, | |
gen_tcp:send(Sock, "JOIN #mytestchan \r\n"), | |
{reply,{ok}, State}; | |
handle_call({message, [Message]}, _From, State) -> | |
io:format('sending message...~n'), | |
Sock = State#bot.socket, | |
gen_tcp:send(Sock, "PRIVMSG #mytestchan :testing test \r\n"), | |
{reply,{ok}, State}; | |
handle_call(_Request, _From, State) -> | |
Reply = ok, | |
{reply, Reply, State}. | |
handle_cast(_Msg, State) -> | |
{noreply, State}. | |
handle_info({tcp, _, Data}, State) -> | |
io:format("~p~n", [Data]), | |
{noreply, State}; | |
handle_info(_Info, 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