mirror of https://github.com/nealey/irc-bot
Add AWAY, ERROR, and INFO commands
This commit is contained in:
parent
7b80acfbbe
commit
167105c661
25
client.ml
25
client.ml
|
@ -1,12 +1,11 @@
|
||||||
open Irc
|
open Irc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(* ==========================================
|
(* ==========================================
|
||||||
* Client stuff
|
* Client stuff
|
||||||
*)
|
*)
|
||||||
type t = {iobuf: Iobuf.t;
|
type t = {iobuf: Iobuf.t;
|
||||||
nick: string ref;
|
nick: string ref;
|
||||||
|
away: string option ref;
|
||||||
username: string;
|
username: string;
|
||||||
realname: string}
|
realname: string}
|
||||||
|
|
||||||
|
@ -113,7 +112,9 @@ let handle_command cli iobuf cmd =
|
||||||
| (None, "ADMIN", [], None) ->
|
| (None, "ADMIN", [], None) ->
|
||||||
()
|
()
|
||||||
| (None, "INFO", [], None) ->
|
| (None, "INFO", [], None) ->
|
||||||
()
|
reply cli "371" (Printf.sprintf "pgircd v%s" Irc.version);
|
||||||
|
reply cli "371" (Printf.sprintf "Running since %f" Irc.start_time);
|
||||||
|
reply cli "374" "End of INFO list"
|
||||||
| (None, "SERVLIST", [], None) ->
|
| (None, "SERVLIST", [], None) ->
|
||||||
()
|
()
|
||||||
| (None, "SQUERY", [servicename], Some text) ->
|
| (None, "SQUERY", [servicename], Some text) ->
|
||||||
|
@ -132,19 +133,18 @@ let handle_command cli iobuf cmd =
|
||||||
| (None, "PING", [text], None) ->
|
| (None, "PING", [text], None) ->
|
||||||
write cli (Some !(Irc.name)) "PONG" [!(Irc.name)] (Some text)
|
write cli (Some !(Irc.name)) "PONG" [!(Irc.name)] (Some text)
|
||||||
| (None, "PONG", [payload], None) ->
|
| (None, "PONG", [payload], None) ->
|
||||||
|
(* We do nothing. *)
|
||||||
()
|
()
|
||||||
| (None, "ERROR", [], Some message) ->
|
| (None, "ERROR", [], Some message) ->
|
||||||
()
|
write cli (Some !(Irc.name)) "NOTICE" [!(cli.nick)] (Some "Bummer.")
|
||||||
| (None, "AWAY", [], None) ->
|
| (None, "AWAY", [], None) ->
|
||||||
()
|
cli.away := None;
|
||||||
|
reply cli "305" "You are no longer marked as being away"
|
||||||
| (None, "AWAY", [], Some message) ->
|
| (None, "AWAY", [], Some message) ->
|
||||||
()
|
cli.away := Some message;
|
||||||
|
reply cli "306" "You have been marked as being away"
|
||||||
| (None, "REHASH", [], None) ->
|
| (None, "REHASH", [], None) ->
|
||||||
()
|
()
|
||||||
| (None, "DIE", [], None) ->
|
|
||||||
()
|
|
||||||
| (None, "RESTART", [], None) ->
|
|
||||||
()
|
|
||||||
| (None, "WALLOPS", [], Some text) ->
|
| (None, "WALLOPS", [], Some text) ->
|
||||||
()
|
()
|
||||||
| (None, "ISON", nicks, None) ->
|
| (None, "ISON", nicks, None) ->
|
||||||
|
@ -183,7 +183,8 @@ let rec handle_command_prereg (nick, username, realname, password) iobuf cmd =
|
||||||
reply cli "001" "Welcome to IRC.";
|
reply cli "001" "Welcome to IRC.";
|
||||||
reply cli "002" ("I am " ^ !(Irc.name) ^
|
reply cli "002" ("I am " ^ !(Irc.name) ^
|
||||||
" Running version " ^ Irc.version);
|
" Running version " ^ Irc.version);
|
||||||
reply cli "003" "This server was created sometime";
|
reply cli "003" ("This server was created " ^
|
||||||
|
(string_of_float Irc.start_time));
|
||||||
reply cli "004" (!(Irc.name) ^
|
reply cli "004" (!(Irc.name) ^
|
||||||
" " ^ Irc.version ^
|
" " ^ Irc.version ^
|
||||||
" " ^ modes ^
|
" " ^ modes ^
|
||||||
|
@ -196,6 +197,7 @@ let rec handle_command_prereg (nick, username, realname, password) iobuf cmd =
|
||||||
| (Some nick, Some username, Some realname, None) ->
|
| (Some nick, Some username, Some realname, None) ->
|
||||||
welcome {iobuf = iobuf;
|
welcome {iobuf = iobuf;
|
||||||
nick = ref nick;
|
nick = ref nick;
|
||||||
|
away = ref None;
|
||||||
username = username;
|
username = username;
|
||||||
realname = realname}
|
realname = realname}
|
||||||
| (Some nick, Some username, Some realname, Some password) ->
|
| (Some nick, Some username, Some realname, Some password) ->
|
||||||
|
@ -205,6 +207,7 @@ let rec handle_command_prereg (nick, username, realname, password) iobuf cmd =
|
||||||
(Some "*** Authentication unimplemented"));
|
(Some "*** Authentication unimplemented"));
|
||||||
welcome {iobuf = iobuf;
|
welcome {iobuf = iobuf;
|
||||||
nick = ref nick;
|
nick = ref nick;
|
||||||
|
away = ref None;
|
||||||
username = username;
|
username = username;
|
||||||
realname = realname}
|
realname = realname}
|
||||||
| _ ->
|
| _ ->
|
||||||
|
|
1
irc.ml
1
irc.ml
|
@ -1,5 +1,6 @@
|
||||||
let name = ref "irc.test"
|
let name = ref "irc.test"
|
||||||
let version = "0.1"
|
let version = "0.1"
|
||||||
|
let start_time = Unix.gettimeofday ()
|
||||||
|
|
||||||
let dbg msg a =
|
let dbg msg a =
|
||||||
prerr_endline ("[" ^ msg ^ "]");
|
prerr_endline ("[" ^ msg ^ "]");
|
||||||
|
|
1
irc.mli
1
irc.mli
|
@ -1,5 +1,6 @@
|
||||||
val name : string ref
|
val name : string ref
|
||||||
val version : string
|
val version : string
|
||||||
|
val start_time : float
|
||||||
|
|
||||||
val uppercase : string -> string
|
val uppercase : string -> string
|
||||||
val lowercase : string -> string
|
val lowercase : string -> string
|
||||||
|
|
15
tests.ml
15
tests.ml
|
@ -90,7 +90,7 @@ let chat d fd s =
|
||||||
(string_of_chat_event (List.hd !script)))
|
(string_of_chat_event (List.hd !script)))
|
||||||
in
|
in
|
||||||
let nomatch got =
|
let nomatch got =
|
||||||
failwith (Printf.sprintf "fd=%d expecting %s\n got %s"
|
failwith (Printf.sprintf "fd=%d\nexpecting %s\n got %s"
|
||||||
(int_of_file_descr fd)
|
(int_of_file_descr fd)
|
||||||
(string_of_chat_event (List.hd !script))
|
(string_of_chat_event (List.hd !script))
|
||||||
(String.escaped got))
|
(String.escaped got))
|
||||||
|
@ -339,7 +339,7 @@ let do_login nick =
|
||||||
Send ("NICK " ^ nick ^ "\r\n");
|
Send ("NICK " ^ nick ^ "\r\n");
|
||||||
Recv (":testserver.test 001 " ^ nick ^ " :Welcome to IRC.\r\n");
|
Recv (":testserver.test 001 " ^ nick ^ " :Welcome to IRC.\r\n");
|
||||||
Recv (":testserver.test 002 " ^ nick ^ " :I am testserver.test Running version " ^ Irc.version ^ "\r\n");
|
Recv (":testserver.test 002 " ^ nick ^ " :I am testserver.test Running version " ^ Irc.version ^ "\r\n");
|
||||||
Recv (":testserver.test 003 " ^ nick ^ " :This server was created sometime\r\n");
|
Recv (":testserver.test 003 " ^ nick ^ " :This server was created " ^ (string_of_float Irc.start_time) ^ "\r\n");
|
||||||
Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l t\r\n");
|
Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l t\r\n");
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -363,6 +363,7 @@ let regression_tests =
|
||||||
Recv ":testserver.test PONG testserver.test :snot\r\n";
|
Recv ":testserver.test PONG testserver.test :snot\r\n";
|
||||||
Send "PING :snot\r\n";
|
Send "PING :snot\r\n";
|
||||||
Recv ":testserver.test PONG testserver.test :snot\r\n";
|
Recv ":testserver.test PONG testserver.test :snot\r\n";
|
||||||
|
Send "PONG snot\r\n";
|
||||||
Send "ISON nick otherguy\r\n";
|
Send "ISON nick otherguy\r\n";
|
||||||
Recv ":testserver.test 303 nick :nick\r\n";
|
Recv ":testserver.test 303 nick :nick\r\n";
|
||||||
Send "ISON otherguy thirdguy\r\n";
|
Send "ISON otherguy thirdguy\r\n";
|
||||||
|
@ -373,6 +374,16 @@ let regression_tests =
|
||||||
Recv ":nick!nick@UDS NOTICE nick :hello\r\n";
|
Recv ":nick!nick@UDS NOTICE nick :hello\r\n";
|
||||||
Send "PRIVMSG otherguy :hello\r\n";
|
Send "PRIVMSG otherguy :hello\r\n";
|
||||||
Recv ":testserver.test 401 nick otherguy :No such nick/channel\r\n";
|
Recv ":testserver.test 401 nick otherguy :No such nick/channel\r\n";
|
||||||
|
Send "AWAY :eating biscuits\r\n";
|
||||||
|
Recv ":testserver.test 306 nick :You have been marked as being away\r\n";
|
||||||
|
Send "AWAY\r\n";
|
||||||
|
Recv ":testserver.test 305 nick :You are no longer marked as being away\r\n";
|
||||||
|
Send "ERROR :I peed my pants\r\n";
|
||||||
|
Recv ":testserver.test NOTICE nick :Bummer.\r\n";
|
||||||
|
Send "INFO\r\n";
|
||||||
|
Recv (":testserver.test 371 nick :pgircd v" ^ Irc.version ^ "\r\n");
|
||||||
|
Recv (Printf.sprintf ":testserver.test 371 nick :Running since %f\r\n" Irc.start_time);
|
||||||
|
Recv ":testserver.test 374 nick :End of INFO list\r\n";
|
||||||
]
|
]
|
||||||
in
|
in
|
||||||
let d = Dispatch.create 2 in
|
let d = Dispatch.create 2 in
|
||||||
|
|
Loading…
Reference in New Issue