add handling +o/+v/-o/-v commands in channels

This commit is contained in:
tali 2024-01-25 18:55:03 -05:00
parent d66cd93152
commit c35c90fcb1
1 changed files with 21 additions and 4 deletions

View File

@ -175,12 +175,12 @@ let on_get_chan_mode chan _me =
] in ] in
Ok (List.flatten rpls) Ok (List.flatten rpls)
let on_set_chan_mode chan me modestr args = let on_set_chan_mode chan me modestr args ~router =
(* TODO: If <modestring> is given, the user sending the command MUST have appropriate (* TODO: If <modestring> is given, the user sending the command MUST have appropriate
channel privileges on the target channel to change the modes given. If a user does channel privileges on the target channel to change the modes given. If a user does
not have appropriate privileges to change modes on the target channel, the server not have appropriate privileges to change modes on the target channel, the server
MUST NOT process the message, and ERR_CHANOPRIVSNEEDED (482) numeric is returned. *) MUST NOT process the message, and ERR_CHANOPRIVSNEEDED (482) numeric is returned. *)
let _ = me, chan in _todo_validation_please ();
let* chg = try Ok (Mode.Parse.chan_modes modestr args) let* chg = try Ok (Mode.Parse.chan_modes modestr args)
with Mode.Parse.Error -> with Mode.Parse.Error ->
@ -193,7 +193,24 @@ let on_set_chan_mode chan me modestr args =
set_chan_mode chan ~from:me ~add:chg.chan_modes.add ~rem:chg.chan_modes.rem; set_chan_mode chan ~from:me ~add:chg.chan_modes.add ~rem:chg.chan_modes.rem;
Option.iter (set_chan_key chan ~from:me) chg.chan_key; Option.iter (set_chan_key chan ~from:me) chg.chan_key;
Option.iter (set_chan_limit chan ~from:me) chg.chan_limit; Option.iter (set_chan_limit chan ~from:me) chg.chan_limit;
(* TODO: ban/op/voice *)
List.iter
(fun (op, mode, nick) ->
try
let user = Router.find_user router nick in
let mem = Router.membership chan user in
let priv = match mode with `o -> Router.Operator | `v -> Voice in
match op with
| `add ->
set_member_priv mem priv ~from:me
| `rem ->
if mem.mem_priv = priv then
set_member_priv mem Normal ~from:me
with Not_found ->
())
chg.chan_privs;
(* TODO: ban (+b) *)
Ok [] Ok []
@ -207,7 +224,7 @@ let on_msg_mode t name args =
Ok (on_set_user_mode u, on_get_user_mode u) Ok (on_set_user_mode u, on_get_user_mode u)
| `chan -> | `chan ->
let c = Router.find_chan t.router name in let c = Router.find_chan t.router name in
Ok (on_set_chan_mode c, on_get_chan_mode c) Ok (on_set_chan_mode c ~router:t.router, on_get_chan_mode c)
| `invalid -> raise Not_found | `invalid -> raise Not_found
with Not_found -> with Not_found ->
Error (nosuchnick name) Error (nosuchnick name)