add TIME command
This commit is contained in:
parent
34bc83e12b
commit
051f1659a3
|
@ -712,6 +712,14 @@ let on_msg_help t topic =
|
|||
let topic = Option.value topic ~default:"*" in
|
||||
Error ("524", [topic; "No help available on this topic"])
|
||||
|
||||
let on_msg_time t =
|
||||
let* _me = require_registered t in
|
||||
let time = Ptime_clock.now () in
|
||||
let time_unix = Fmt.str "%a" pp_unixtime time in
|
||||
let time_human = Fmt.str "%a" Server_info.pp_time time in
|
||||
reply t ("391", [t.server_info.hostname; time_unix; time_human]);
|
||||
Ok ()
|
||||
|
||||
let quit t me ~reason =
|
||||
begin
|
||||
let msg = Msg.make "QUIT" [User.nick me; reason] ~always_trailing:true in
|
||||
|
@ -863,6 +871,7 @@ let dispatch t = function
|
|||
| "MOTD", _ -> on_msg_motd t
|
||||
| "ADMIN", _ -> on_msg_admin t
|
||||
| "INFO", _ -> on_msg_info t
|
||||
| "TIME", _ -> on_msg_time t
|
||||
| "HELP", args -> on_msg_help t (concat_args args)
|
||||
| "PING", args -> on_msg_ping t (concat_args args)
|
||||
| "PONG", args -> on_msg_pong t (concat_args args)
|
||||
|
@ -891,7 +900,6 @@ let dispatch t = function
|
|||
Error noprivileges
|
||||
(* TODO: "LIST" *)
|
||||
(* TODO: "LUSERS" *)
|
||||
(* TODO: "TIME" *)
|
||||
(* TODO: "LINKS" *)
|
||||
(* TODO: "USERHOST" *)
|
||||
| cmd, _ ->
|
||||
|
|
|
@ -1,5 +1,8 @@
|
|||
open! Import
|
||||
|
||||
let tz_offset_s = Ptime_clock.current_tz_offset_s ()
|
||||
let pp_time = Ptime.pp_human () ?tz_offset_s
|
||||
|
||||
type t = {
|
||||
version : string;
|
||||
created : string;
|
||||
|
@ -38,13 +41,7 @@ let make ~hostname = {
|
|||
version =
|
||||
(* TODO: generate version string at build time? *)
|
||||
"0.0.0";
|
||||
created =
|
||||
begin
|
||||
let ts = Ptime_clock.now () in
|
||||
let tz_offset_s = Ptime_clock.current_tz_offset_s () in
|
||||
let pp = Ptime.pp_human () ?tz_offset_s in
|
||||
Fmt.str "%a" pp ts
|
||||
end;
|
||||
created = Fmt.str "%a" pp_time (Ptime_clock.now ());
|
||||
hostname;
|
||||
admin_info =
|
||||
(* TODO: make configurable *)
|
||||
|
|
Loading…
Reference in New Issue