blob: 46433512a09b6bc3f79716011660444bedba2c0d (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
defmodule SCLI do
def run() do
str = "say: " |> IO.gets |> String.trim
cond do
str == "/quit" ->
nil
String.slice(str, 0..0) == "/" ->
command = str |> String.slice(1..-1) |> String.split(" ")
handle_command(command)
run()
true ->
SApp.Chat.send(str)
run()
end
end
def handle_command(["connect", ipstr, portstr]) do
{:ok, ip} = :inet.parse_address (to_charlist ipstr)
{port, _} = Integer.parse portstr
SNet.TCPServer.add_peer(ip, port)
end
def handle_command(["nick", nick]) do
Shard.Identity.set_nickname nick
end
def handle_command(_cmd) do
IO.puts "Invalid command"
end
end
|