add WHOIS command
This commit is contained in:
parent
65b3dc6672
commit
bfa22c6dbd
|
@ -61,7 +61,7 @@ let reply t (num, params) =
|
|||
| None -> "*"
|
||||
in
|
||||
let always_trailing = match num with
|
||||
| "301" | "332" | "353" -> true
|
||||
| "301" | "311" | "312" | "319" | "332" | "353" -> true
|
||||
| _ -> false
|
||||
in
|
||||
Outbox.send t.outbox
|
||||
|
@ -585,6 +585,49 @@ let on_msg_who t mask =
|
|||
reply t ("315", [mask; "End of WHO list"]);
|
||||
Ok ()
|
||||
|
||||
let list_whois t user =
|
||||
let nick = User.nick user in
|
||||
let { username; hostname; realname } = user.userinfo in
|
||||
begin
|
||||
reply t ("311", [nick; username; hostname; "*"; realname]);
|
||||
reply t ("312", [nick; t.server_info.hostname; t.server_info.hostname]);
|
||||
|
||||
(* RPL_WHOISOPERATOR (313) "<client> <nick> :is an IRC operator" *)
|
||||
(* RPL_WHOISIDLE (317) "<client> <nick> <secs> <signon> :seconds idle, signon time" *)
|
||||
|
||||
(* TODO: concat channel names until message becomes too long *)
|
||||
List.iter
|
||||
(fun (m : membership) ->
|
||||
let chan_str = Router.membership_prefix m.mem_priv ^ Chan.name m.mem_chan in
|
||||
reply t ("319", [nick; chan_str]))
|
||||
(User.membership user);
|
||||
|
||||
reply t ("320", [nick; "is a cat, meow :3"]);
|
||||
|
||||
reply t ("379", [nick; Fmt.str "is using modes +%s"
|
||||
(Mode.Set.to_string (User.mode user))]);
|
||||
|
||||
Option.iter
|
||||
(fun text ->
|
||||
reply t (away nick text))
|
||||
(User.away user);
|
||||
|
||||
reply t ("318", [nick; "End of /WHOIS list"]);
|
||||
end
|
||||
|
||||
let on_msg_whois t nick =
|
||||
let* _me = require_registered t in
|
||||
let* user =
|
||||
try
|
||||
match name_type nick with
|
||||
| `nick -> Ok (Router.find_user t.router nick)
|
||||
| `chan | `invalid -> raise Not_found
|
||||
with Not_found ->
|
||||
Error (nosuchnick nick)
|
||||
in
|
||||
list_whois t user;
|
||||
Ok ()
|
||||
|
||||
|
||||
(* welcome and quit *)
|
||||
|
||||
|
@ -784,6 +827,8 @@ let dispatch t = function
|
|||
| "AWAY", args -> on_msg_away t (concat_args args)
|
||||
| "MODE", tgt :: args when tgt <> "" -> on_msg_mode t tgt args
|
||||
| "WHO", mask :: _ when mask <> "" -> on_msg_who t mask
|
||||
| "WHOIS", ([] | [""] | (_ :: "" :: _)) -> Error nonicknamegiven
|
||||
| "WHOIS", ([nick] | (_ :: nick :: _)) -> on_msg_whois t nick
|
||||
| ("USER" | "JOIN" | "NAMES" | "PART" | "KICK" | "MODE" | "WHO") as cmd, _ ->
|
||||
Error (needmoreparams cmd)
|
||||
(* TODO: "LIST" *)
|
||||
|
@ -795,7 +840,6 @@ let dispatch t = function
|
|||
(* TODO: "HELP" *)
|
||||
(* TODO: "INFO" *)
|
||||
(* TODO: "NOTICE" *)
|
||||
(* TODO: "WHOIS" *)
|
||||
(* TODO: "WHOWAS" *)
|
||||
(* TODO: "KILL" *)
|
||||
(* TODO: "REHASH" *)
|
||||
|
|
Loading…
Reference in New Issue