Initial IRC connection test
This commit is contained in:
parent
e6edcec903
commit
e1609f3e28
5 changed files with 82 additions and 19 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ nulform.sublime-workspace
|
||||||
/ebin
|
/ebin
|
||||||
/deps
|
/deps
|
||||||
erl_crash.dump
|
erl_crash.dump
|
||||||
|
mix.lock
|
||||||
|
|
|
@ -1,2 +1,8 @@
|
||||||
defmodule Nulform do
|
defmodule Nulform do
|
||||||
|
|
||||||
|
def run() do
|
||||||
|
{:ok, sock} = Nulform.Connection.connect('irc.quakenet.org', 6667)
|
||||||
|
Nulform.Connection.wait_on_socket(sock)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
54
lib/nulform/connection.ex
Normal file
54
lib/nulform/connection.ex
Normal file
|
@ -0,0 +1,54 @@
|
||||||
|
defmodule Nulform.Connection do
|
||||||
|
def connect(host, port) do
|
||||||
|
{:ok, sock} = :gen_tcp.connect host, port, [
|
||||||
|
{:active, :true}, :binary, :inet, {:packet, :line}
|
||||||
|
]
|
||||||
|
end
|
||||||
|
|
||||||
|
def wait_on_socket(sock) do
|
||||||
|
receive do
|
||||||
|
{:tcp, sock, msg} ->
|
||||||
|
stripped = String.rstrip msg
|
||||||
|
IO.puts stripped
|
||||||
|
|
||||||
|
|
||||||
|
case stripped do
|
||||||
|
"NOTICE AUTH :*** Looking up your hostname" ->
|
||||||
|
send sock, "NICK Nulform"
|
||||||
|
send sock, "USER nulform 8 * :␀form"
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
case String.split stripped, ":" do
|
||||||
|
["PING " | rest]
|
||||||
|
when is_binary rest ->
|
||||||
|
:ok = :gen_tcp.send sock, rest <> "\r\n"
|
||||||
|
|
||||||
|
["PING " | rest]
|
||||||
|
when is_list rest ->
|
||||||
|
concat_list = fn
|
||||||
|
f, list, sep when length(list) > 1 ->
|
||||||
|
[now | rest] = list
|
||||||
|
now <> sep <> f.(rest, sep)
|
||||||
|
_, list, _ ->
|
||||||
|
[last] = list
|
||||||
|
last
|
||||||
|
end
|
||||||
|
|
||||||
|
send sock, "PONG :" <> concat_list.(concat_list, rest, ":")
|
||||||
|
|
||||||
|
|
||||||
|
_ ->
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
wait_on_socket sock
|
||||||
|
end
|
||||||
|
|
||||||
|
def send(sock, msg) do
|
||||||
|
:ok = :gen_tcp.send sock, msg <> "\r\n"
|
||||||
|
IO.puts("<- " <> msg)
|
||||||
|
end
|
||||||
|
end
|
32
mix.exs
32
mix.exs
|
@ -1,20 +1,22 @@
|
||||||
defmodule Nulform.Mixfile do
|
defmodule Nulform.Mixfile do
|
||||||
use Mix.Project
|
use Mix.Project
|
||||||
|
|
||||||
def project do
|
def project do
|
||||||
[ app: :nulform,
|
[ app: :nulform,
|
||||||
version: "0.0.1",
|
version: "0.0.1",
|
||||||
deps: deps ]
|
deps: deps ]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Configuration for the OTP application
|
# Configuration for the OTP application
|
||||||
def application do
|
def application do
|
||||||
[]
|
[]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the list of dependencies in the format:
|
# Returns the list of dependencies in the format:
|
||||||
# { :foobar, "0.1", git: "https://github.com/elixir-lang/foobar.git" }
|
# { :foobar, "0.1", git: "https://github.com/elixir-lang/foobar.git" }
|
||||||
defp deps do
|
defp deps do
|
||||||
[]
|
[
|
||||||
end
|
{ :socket, "0.0.1", git: "https://github.com/meh/elixir-socket" }
|
||||||
|
]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
Code.require_file "test_helper.exs", __DIR__
|
Code.require_file "test_helper.exs", __DIR__
|
||||||
|
|
||||||
defmodule NulformTest do
|
defmodule NulformTest do
|
||||||
use ExUnit.Case
|
use ExUnit.Case
|
||||||
|
|
||||||
test "the truth" do
|
test "the truth" do
|
||||||
assert(true)
|
assert(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue