add ADMIN command

This commit is contained in:
tali 2024-01-31 15:07:53 -05:00
parent b0e1b10868
commit 7534b2c4e7
2 changed files with 12 additions and 2 deletions

View File

@ -61,7 +61,7 @@ let reply t (num, params) =
| None -> "*" | None -> "*"
in in
let always_trailing = match num with let always_trailing = match num with
| "301" | "311" | "312" | "314" | "319" | "332" | "353" -> true | "256" | "301" | "311" | "312" | "314" | "319" | "332" | "353" -> true
| _ -> false | _ -> false
in in
Outbox.send t.outbox Outbox.send t.outbox
@ -690,6 +690,11 @@ let welcome t me =
motd t; motd t;
end end
let on_msg_admin t =
let* _me = require_registered t in
reply t ("256", [t.server_info.hostname; t.server_info.admin_info]);
Ok ()
let quit t me ~reason = let quit t me ~reason =
begin begin
let msg = Msg.make "QUIT" [User.nick me; reason] ~always_trailing:true in let msg = Msg.make "QUIT" [User.nick me; reason] ~always_trailing:true in
@ -839,11 +844,13 @@ let dispatch t = function
| "USER", unm :: _ :: _ :: rnm :: _ -> on_msg_user t unm rnm | "USER", unm :: _ :: _ :: rnm :: _ -> on_msg_user t unm rnm
| "QUIT", reason -> on_msg_quit t (concat_args reason) | "QUIT", reason -> on_msg_quit t (concat_args reason)
| "MOTD", _ -> on_msg_motd t | "MOTD", _ -> on_msg_motd t
| "ADMIN", _ -> on_msg_admin t
| "PING", args -> on_msg_ping t (concat_args args) | "PING", args -> on_msg_ping t (concat_args args)
| "PONG", args -> on_msg_pong t (concat_args args) | "PONG", args -> on_msg_pong t (concat_args args)
| "PRIVMSG", ([] | "" :: _) -> Error norecipient | "PRIVMSG", ([] | "" :: _) -> Error norecipient
| "PRIVMSG", ([_] | _ :: "" :: _) -> Error notexttosend | "PRIVMSG", ([_] | _ :: "" :: _) -> Error notexttosend
| "PRIVMSG", tgt :: msg :: _ -> on_msg_privmsg t tgt msg | "PRIVMSG", tgt :: msg :: _ -> on_msg_privmsg t tgt msg
(* TODO: "NOTICE" *)
| "JOIN", tgt :: _ when tgt <> "" -> on_msg_join t tgt | "JOIN", tgt :: _ when tgt <> "" -> on_msg_join t tgt
| "JOIN 0", _ -> (* hack; see split_command_params *) on_msg_join_0 t | "JOIN 0", _ -> (* hack; see split_command_params *) on_msg_join_0 t
| "NAMES", tgt :: _ when tgt <> "" -> on_msg_names t tgt | "NAMES", tgt :: _ when tgt <> "" -> on_msg_names t tgt
@ -869,7 +876,6 @@ let dispatch t = function
(* TODO: "STATS" *) (* TODO: "STATS" *)
(* TODO: "HELP" *) (* TODO: "HELP" *)
(* TODO: "INFO" *) (* TODO: "INFO" *)
(* TODO: "NOTICE" *)
(* TODO: "KILL" *) (* TODO: "KILL" *)
(* TODO: "REHASH" *) (* TODO: "REHASH" *)
(* TODO: "RESTART" *) (* TODO: "RESTART" *)

View File

@ -4,6 +4,7 @@ type t = {
version : string; version : string;
created : string; created : string;
hostname : string; hostname : string;
admin_info : string;
motd : string list; motd : string list;
conf : conf; conf : conf;
} }
@ -41,6 +42,9 @@ let make ~hostname = {
(* TODO: stringify timestamp *) (* TODO: stringify timestamp *)
"Sun Jan 7 09:58:24 PM EST 2024"; "Sun Jan 7 09:58:24 PM EST 2024";
hostname; hostname;
admin_info =
(* TODO: make configurable *)
"the admin of this server is @iitalics@octodon.social";
motd = [ motd = [
(* TODO: load from file *) (* TODO: load from file *)
"MEOW MEOW MEOW MEOW MEOW"; "MEOW MEOW MEOW MEOW MEOW";