mirror of https://github.com/nealey/irc-bot
PING and PONG
This commit is contained in:
parent
ac369d30c2
commit
4d9ed389a2
|
@ -116,9 +116,10 @@ let handle_command cli iobuf cmd =
|
|||
()
|
||||
| (None, "KILL", [nickname; comment], None) ->
|
||||
()
|
||||
| (None, "PING", [server], None) ->
|
||||
()
|
||||
| (None, "PONG", [server], None) ->
|
||||
| (None, "PING", [], Some text)
|
||||
| (None, "PING", [text], None) ->
|
||||
write cli (Command.create (Some !(Irc.name)) "PONG" [!(Irc.name)] (Some text))
|
||||
| (None, "PONG", [payload], None) ->
|
||||
()
|
||||
| (None, "ERROR", [], Some message) ->
|
||||
()
|
||||
|
|
|
@ -45,7 +45,7 @@ let rec from_string line =
|
|||
match (c, acc) with
|
||||
| (None, name :: args) ->
|
||||
(* End of line, no text part *)
|
||||
create sender name args None
|
||||
create sender (String.uppercase name) args None
|
||||
| (None, []) ->
|
||||
(* End of line, no text part, no args, no command *)
|
||||
raise (Failure "No command, eh?")
|
||||
|
@ -55,7 +55,7 @@ let rec from_string line =
|
|||
loop (Some (Str.string_after word 1)) acc rest
|
||||
| (Some ':', name :: args) ->
|
||||
(* Not first word, starts with ':' *)
|
||||
create sender name args (Some (Str.string_after line 1))
|
||||
create sender (String.uppercase name) args (Some (Str.string_after line 1))
|
||||
| (Some _, _) ->
|
||||
(* Argument *)
|
||||
let (word, rest) = extract_word line in
|
||||
|
|
11
tests.ml
11
tests.ml
|
@ -20,6 +20,10 @@ let unit_tests =
|
|||
~printer:Command.as_string
|
||||
(Command.create None "NICK" ["name"] None)
|
||||
(Command.from_string "NICK name");
|
||||
assert_equal
|
||||
~printer:Command.as_string
|
||||
(Command.create None "NICK" ["name"] None)
|
||||
(Command.from_string "nick name");
|
||||
assert_equal
|
||||
~printer:Command.as_string
|
||||
(Command.create (Some "foo") "NICK" ["name"] None)
|
||||
|
@ -48,7 +52,8 @@ let regression_tests =
|
|||
[
|
||||
"Simple connection" >::
|
||||
(do_chat ((do_login "nick") @
|
||||
[Send "BLARGH\r\n";
|
||||
[
|
||||
Send "BLARGH\r\n";
|
||||
Recv ":testserver.test 421 nick BLARGH :Unknown or misconstructed command\r\n";
|
||||
Send "MOTD\r\n";
|
||||
Recv ":testserver.test 422 nick :MOTD File is missing\r\n";
|
||||
|
@ -56,6 +61,10 @@ let regression_tests =
|
|||
Regex ":testserver\\.test 391 nick testserver\\.test :[-0-9]+T[:0-9]+Z\r\n";
|
||||
Send "VERSION\r\n";
|
||||
Recv ":testserver.test 351 nick 0.1 testserver.test :\r\n";
|
||||
Send "PING snot\r\n";
|
||||
Recv ":testserver.test PONG testserver.test :snot\r\n";
|
||||
Send "PING :snot\r\n";
|
||||
Recv ":testserver.test PONG testserver.test :snot\r\n";
|
||||
]));
|
||||
]
|
||||
|
||||
|
|
Loading…
Reference in New Issue