clean up set_chan_* functions

This commit is contained in:
tali 2024-01-24 12:53:39 -05:00
parent 7d8807318b
commit 8e711970e7
1 changed files with 22 additions and 35 deletions

View File

@ -97,41 +97,29 @@ let set_chan_mode ~from ?(add = Mode.Set.empty) ?(rem = Mode.Set.empty) chan =
if chg <> Mode.Set.no_change then
let modestr = Fmt.str "%a" Mode.Set.pp_change chg in
let msg = Msg.make "MODE" [Chan.name chan; modestr] in
begin
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_mode chan mode;
end
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_mode chan mode
let set_chan_key chan ~from = function
| `set key ->
let msg = Msg.make "MODE" [Chan.name chan; "+k"; key] ~always_trailing:true in
begin
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_key chan (Some key);
end
| `unset ->
if Chan.key chan <> None then
let msg = Msg.make "MODE" [Chan.name chan; "-k"; "*"] in
begin
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_key chan None;
end
let set_chan_key chan ~from chg =
let key, args = match chg with
| `set k -> Some k, ["+k"; k]
| `unset -> None, ["-k"]
in
if key <> Chan.key chan then
let always_trailing = Option.is_some key in
let msg = Msg.make "MODE" (Chan.name chan :: args) ~always_trailing in
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_key chan key
let set_chan_limit chan ~from = function
| `set lim ->
if Chan.limit chan <> Some lim then
let msg = Msg.make "MODE" [Chan.name chan; "+l"; string_of_int lim] in
begin
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_limit chan (Some lim);
end
| `unset ->
if Chan.limit chan <> None then
let msg = Msg.make "MODE" [Chan.name chan; "-l"] in
begin
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_limit chan None;
end
let set_chan_limit chan ~from chg =
let limit, args = match chg with
| `set l -> Some l, ["+l"; string_of_int l]
| `unset -> None, ["-l"]
in
if limit <> Chan.limit chan then
let msg = Msg.make "MODE" (Chan.name chan :: args) in
Router.relay msg ~from [`to_chan chan; `to_self];
Chan.set_limit chan limit
let on_get_user_mode user me =
let* () = if user != me then Error usersdontmatch_get else Ok () in
@ -160,9 +148,8 @@ let on_get_chan_mode chan _me =
| None -> []
end;
_todo_validation_please [];
(* TODO: only display key if priveledged enough to see it *)
_todo_validation_please [];
begin match Chan.key chan with
| Some key -> ["324", [Chan.name chan; "+k"; key]]
| None -> []