talircd/lib/server/chan.ml

35 lines
820 B
OCaml

open! Import
include Router_types
type t = chan
let make ~name =
{
name;
name_key = string_ci name;
topic = None;
members = Dllist.create ();
chan_mode = Irc.Mode.Set.empty;
chan_limit = None;
chan_key = None;
}
let name t = t.name
let topic t = t.topic
let mode t = t.chan_mode
let set_mode t new_mode = t.chan_mode <- new_mode
let limit t = t.chan_limit
let set_limit t n = t.chan_limit <- n
let key t = t.chan_key
let set_key t k = t.chan_key <- k
let register t ~router = Hashtbl.replace router.channels t.name_key t
let unregister t ~router = Hashtbl.remove router.channels t.name_key
let is_registered t ~router = Hashtbl.mem router.channels t.name_key
let members t =
Dllist.fold_r (fun m xs -> m.mem_user :: xs) t.members []
let no_members t =
Dllist.is_empty t.members