diff --git a/lib/irc/mode.ml b/lib/irc/mode.ml index c1a4991..22d83a2 100644 --- a/lib/irc/mode.ml +++ b/lib/irc/mode.ml @@ -148,6 +148,55 @@ module Parse = struct ~init:Set.{ add = empty; rem = empty } ~add:(fun ms m -> Set.{ add = add m ms.add; rem = remove m ms.rem }) ~rem:(fun ms m -> Set.{ add = remove m ms.add; rem = add m ms.rem }) + + type ('a, 'b) set_or_unset = + | Set of 'a + | Unset of 'b + + type chan_modes = { + chan_modes : Set.change; + chan_key : (string, string) set_or_unset option; + chan_limit : (int, unit) set_or_unset option; + chan_priv : (chan_b * (string, string) set_or_unset) list; + } + + let chan_modes_add (args, modes) = function + | #chan_a -> fail "TODO: + type A modes" + | #chan_b -> fail "TODO: + type B modes" + | #chan_c -> fail "TODO: + type C modes" + | #chan_d as m -> + let chan_modes = { + Set.add = Set.add m modes.chan_modes.add; + Set.rem = Set.remove m modes.chan_modes.rem; + } in + args, { modes with chan_modes } + + let chan_modes_rem (args, modes) = function + | #chan_a -> fail "TODO: - type A modes" + | #chan_b -> fail "TODO: - type B modes" + | #chan_c -> fail "TODO: - type C modes" + | #chan_d as m -> + let chan_modes = { + Set.add = Set.remove m modes.chan_modes.add; + Set.rem = Set.add m modes.chan_modes.rem; + } in + args, { modes with chan_modes } + + let chan_modes str args = + let modes = { + chan_modes = Set.no_change; + chan_key = None; + chan_limit = None; + chan_priv = []; + } in + let _, modes = + parse_mode_set str + ~of_char:of_char_chan + ~init:(args, modes) + ~add:chan_modes_add + ~rem:chan_modes_rem + in + { modes with chan_priv = List.rev modes.chan_priv } end diff --git a/lib/irc/mode.mli b/lib/irc/mode.mli index a5ee4c0..2adce0e 100644 --- a/lib/irc/mode.mli +++ b/lib/irc/mode.mli @@ -73,5 +73,17 @@ module Parse : sig type user_modes = Set.change + type ('a, 'b) set_or_unset = + | Set of 'a + | Unset of 'b + + type chan_modes = { + chan_modes : Set.change; + chan_key : (string, string) set_or_unset option; + chan_limit : (int, unit) set_or_unset option; + chan_priv : (chan_b * (string, string) set_or_unset) list; + } + val user_modes : string -> user_modes + val chan_modes : string -> string list -> chan_modes end