add basic parsing of channel mode flags

This commit is contained in:
tali 2024-01-18 13:28:23 -05:00
parent 8db310e2b0
commit f58de239fa
2 changed files with 61 additions and 0 deletions

View File

@ -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

View File

@ -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