Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F665141
connection_handler.ex
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1 KB
Subscribers
None
connection_handler.ex
View Options
defmodule
ConnectionHandler
do
defmodule
State
do
defstruct
host
:
"chat.freenode.net"
,
port
:
6667
,
pass
:
"ohaipassword"
,
nick
:
"ohaibot"
,
user
:
"ohaibot"
,
name
:
"ohaibot welcomes you"
,
client
:
nil
end
def
start_link
(
client
,
state
\\
%
State
{})
do
GenServer
.
start_link
(
__MODULE__
,
[%{
state
|
client
:
client
}])
end
def
init
([
state
])
do
ExIrc.Client
.
add_handler
state
.
client
,
self
ExIrc.Client
.
connect!
state
.
client
,
state
.
host
,
state
.
port
{
:ok
,
state
}
end
def
handle_info
({
:connected
,
server
,
port
},
state
)
do
debug
"Connected to
#{
server
}
:
#{
port
}
"
ExIrc.Client
.
logon
state
.
client
,
state
.
pass
,
state
.
nick
,
state
.
user
,
state
.
name
{
:noreply
,
state
}
end
# Catch-all for messages you don't care about
def
handle_info
(
msg
,
state
)
do
debug
"Received unknown messsage:"
IO
.
inspect
msg
{
:noreply
,
state
}
end
defp
debug
(
msg
)
do
IO
.
puts
IO.ANSI
.
yellow
()
<>
msg
<>
IO.ANSI
.
reset
()
end
end
File Metadata
Details
Attached
Mime Type
text/x-ruby
Expires
Fri, Feb 27, 11:03 AM (1 d, 22 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
87175
Default Alt Text
connection_handler.ex (1 KB)
Attached To
rEXIRC ExIRC Fork
Event Timeline
Log In to Comment