parse priv (+o, +v) modes in chan mode strings
This commit is contained in:
parent
2bea08d04f
commit
d66cd93152
|
@ -1,3 +1,5 @@
|
||||||
|
open Types
|
||||||
|
|
||||||
type user = [`i | `o | `w]
|
type user = [`i | `o | `w]
|
||||||
type chan_a = [`b]
|
type chan_a = [`b]
|
||||||
type chan_b = [`k | `o | `v]
|
type chan_b = [`k | `o | `v]
|
||||||
|
@ -166,24 +168,41 @@ module Parse = struct
|
||||||
| `unset
|
| `unset
|
||||||
]
|
]
|
||||||
|
|
||||||
|
type add_or_rem = [
|
||||||
|
| `add
|
||||||
|
| `rem
|
||||||
|
]
|
||||||
|
|
||||||
|
type priv = [`o | `v]
|
||||||
|
|
||||||
type chan_modes = {
|
type chan_modes = {
|
||||||
chan_modes : Set.change;
|
chan_modes : Set.change;
|
||||||
chan_key : string set_or_unset option;
|
chan_key : string set_or_unset option;
|
||||||
chan_limit : int set_or_unset option;
|
chan_limit : int set_or_unset option;
|
||||||
|
chan_privs : (add_or_rem * priv * name) list;
|
||||||
}
|
}
|
||||||
|
|
||||||
let chan_modes_add (args, modes) = function
|
let chan_modes_add (args, modes) = function
|
||||||
|
| `b ->
|
||||||
|
(* type A *)
|
||||||
|
(* TODO: ban *)
|
||||||
|
let args = match args with [] -> [] | _ :: args -> args in
|
||||||
|
args, modes
|
||||||
| `k ->
|
| `k ->
|
||||||
(* type B *)
|
(* type B *)
|
||||||
let key, args = take args in
|
let key, args = take args in
|
||||||
let chan_key = Some (`set key) in
|
let chan_key = Some (`set key) in
|
||||||
args, { modes with chan_key }
|
args, { modes with chan_key }
|
||||||
|
| (`o | `v) as priv ->
|
||||||
|
(* type B *)
|
||||||
|
let nick, args = take args in
|
||||||
|
let chan_privs = (`add, priv, nick) :: modes.chan_privs in
|
||||||
|
args, { modes with chan_privs }
|
||||||
| `l ->
|
| `l ->
|
||||||
(* type C *)
|
(* type C *)
|
||||||
let limit, args = take_int args in
|
let limit, args = take_int args in
|
||||||
let chan_limit = Some (`set limit) in
|
let chan_limit = Some (`set limit) in
|
||||||
args, { modes with chan_limit }
|
args, { modes with chan_limit }
|
||||||
| `b | `o | `v -> fail "TODO: + ban/op/voice"
|
|
||||||
| #chan_d as m ->
|
| #chan_d as m ->
|
||||||
let chan_modes = {
|
let chan_modes = {
|
||||||
Set.add = Set.add m modes.chan_modes.add;
|
Set.add = Set.add m modes.chan_modes.add;
|
||||||
|
@ -192,6 +211,11 @@ module Parse = struct
|
||||||
args, { modes with chan_modes }
|
args, { modes with chan_modes }
|
||||||
|
|
||||||
let chan_modes_rem (args, modes) = function
|
let chan_modes_rem (args, modes) = function
|
||||||
|
| `b ->
|
||||||
|
(* type A *)
|
||||||
|
(* TODO: ban *)
|
||||||
|
let args = match args with [] -> [] | _ :: args -> args in
|
||||||
|
args, modes
|
||||||
| `k ->
|
| `k ->
|
||||||
(* type B *)
|
(* type B *)
|
||||||
let _key, args = take args in
|
let _key, args = take args in
|
||||||
|
@ -201,7 +225,11 @@ module Parse = struct
|
||||||
(* type C *)
|
(* type C *)
|
||||||
let chan_limit = Some `unset in
|
let chan_limit = Some `unset in
|
||||||
args, { modes with chan_limit }
|
args, { modes with chan_limit }
|
||||||
| `b | `o | `v -> fail "TODO: - ban/op/voice"
|
| (`o | `v) as priv ->
|
||||||
|
(* type B *)
|
||||||
|
let nick, args = take args in
|
||||||
|
let chan_privs = (`rem, priv, nick) :: modes.chan_privs in
|
||||||
|
args, { modes with chan_privs }
|
||||||
| #chan_d as m ->
|
| #chan_d as m ->
|
||||||
let chan_modes = {
|
let chan_modes = {
|
||||||
Set.add = Set.remove m modes.chan_modes.add;
|
Set.add = Set.remove m modes.chan_modes.add;
|
||||||
|
@ -214,6 +242,7 @@ module Parse = struct
|
||||||
chan_modes = Set.no_change;
|
chan_modes = Set.no_change;
|
||||||
chan_key = None;
|
chan_key = None;
|
||||||
chan_limit = None;
|
chan_limit = None;
|
||||||
|
chan_privs = []
|
||||||
} in
|
} in
|
||||||
let _, modes =
|
let _, modes =
|
||||||
parse_mode_set str
|
parse_mode_set str
|
||||||
|
@ -222,7 +251,7 @@ module Parse = struct
|
||||||
~add:chan_modes_add
|
~add:chan_modes_add
|
||||||
~rem:chan_modes_rem
|
~rem:chan_modes_rem
|
||||||
in
|
in
|
||||||
modes
|
{ modes with chan_privs = List.rev modes.chan_privs }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -292,6 +321,13 @@ let%expect_test _ =
|
||||||
| Some `unset -> Format.printf " -k"
|
| Some `unset -> Format.printf " -k"
|
||||||
| None -> ()
|
| None -> ()
|
||||||
end;
|
end;
|
||||||
|
List.iter
|
||||||
|
(fun (add_rem, mode, nick) ->
|
||||||
|
Format.printf " %c%c:%s"
|
||||||
|
(match add_rem with `add -> '+' | `rem -> '-')
|
||||||
|
(to_char mode)
|
||||||
|
nick)
|
||||||
|
m.chan_privs;
|
||||||
Format.printf "]\n@."
|
Format.printf "]\n@."
|
||||||
in
|
in
|
||||||
|
|
||||||
|
@ -303,3 +339,9 @@ let%expect_test _ =
|
||||||
|
|
||||||
print_chan_modes (Parse.chan_modes "+k-k+k" ["a"; "b"; "c"]);
|
print_chan_modes (Parse.chan_modes "+k-k+k" ["a"; "b"; "c"]);
|
||||||
[%expect {| [+ +k:"c"] |}];
|
[%expect {| [+ +k:"c"] |}];
|
||||||
|
|
||||||
|
print_chan_modes (Parse.chan_modes "+o+v" ["aaa"; "bbb"]);
|
||||||
|
[%expect {| [+ +o:aaa +v:bbb] |}];
|
||||||
|
|
||||||
|
print_chan_modes (Parse.chan_modes "+o-v" ["aaa"; "bbb"]);
|
||||||
|
[%expect {| [+ +o:aaa -v:bbb] |}];
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
open Types
|
||||||
|
|
||||||
(*
|
(*
|
||||||
User Modes:
|
User Modes:
|
||||||
+i Invisible User Mode
|
+i Invisible User Mode
|
||||||
|
@ -78,11 +80,18 @@ module Parse : sig
|
||||||
| `unset
|
| `unset
|
||||||
]
|
]
|
||||||
|
|
||||||
|
type add_or_rem = [
|
||||||
|
| `add
|
||||||
|
| `rem
|
||||||
|
]
|
||||||
|
|
||||||
|
type priv = [`o | `v]
|
||||||
|
|
||||||
type chan_modes = {
|
type chan_modes = {
|
||||||
chan_modes : Set.change;
|
chan_modes : Set.change;
|
||||||
chan_key : string set_or_unset option;
|
chan_key : string set_or_unset option;
|
||||||
chan_limit : int set_or_unset option;
|
chan_limit : int set_or_unset option;
|
||||||
(* TODO: ban, op, voice *)
|
chan_privs : (add_or_rem * priv * name) list;
|
||||||
}
|
}
|
||||||
|
|
||||||
val user_modes : string -> user_modes
|
val user_modes : string -> user_modes
|
||||||
|
|
Loading…
Reference in New Issue