add cringe USERHOST command

This commit is contained in:
tali 2024-01-31 17:22:19 -05:00
parent 7d204b98b6
commit 41bf46b8dc
1 changed files with 25 additions and 2 deletions

View File

@ -61,7 +61,8 @@ let reply t (num, params) =
| None -> "*"
in
let always_trailing = match num with
| "256" | "301" | "311" | "312" | "314" | "319" | "332" | "353" -> true
| "256" | "301" | "302" | "311" | "312" | "314" | "319" | "332"
| "353" -> true
| _ -> false
in
Outbox.send t.outbox
@ -660,6 +661,28 @@ let on_msg_whowas t nick count =
list_whowas t nick limit;
Ok ()
let on_msg_userhost t nicks =
let* _me = require_registered t in
let results =
List.filter_map
(fun nick ->
try
let user = match name_type nick with
| `nick -> Router.find_user t.router nick
| `chan | `invalid -> raise Not_found
in
let isaway = match User.away user with
| Some _ -> '-'
| None -> '+'
in
Some (Fmt.str "%s=%c%s" (User.nick user) isaway user.userinfo.hostname)
with Not_found ->
None)
nicks
in
reply t ("302", [String.concat " " results]);
Ok ()
(* welcome and quit *)
@ -916,12 +939,12 @@ let dispatch t = function
| "WHOWAS", ([] | "" :: _) -> Error nonicknamegiven
| "WHOWAS", [nick] -> on_msg_whowas t nick ""
| "WHOWAS", nick :: count :: _ -> on_msg_whowas t nick count
| "USERHOST", nicks -> on_msg_userhost t nicks
| ("USER" | "JOIN" | "NAMES" | "PART" | "KICK" | "MODE" | "WHO") as cmd, _ ->
Error (needmoreparams cmd)
| ("CONNECT" | "KILL" | "REHASH" | "RESTART" | "STATS" | "SQUIT" | "WALLOPS"), _ ->
Error noprivileges
(* TODO: "LIST" *)
(* TODO: "USERHOST" *)
| cmd, _ ->
Error (unknowncommand cmd)