talircd/lib/server/user.ml

42 lines
946 B
OCaml

open! Import
include Router_types
type t = user
let make nick ~userinfo ~outbox =
{
outbox;
userinfo;
nick;
nick_key = string_ci nick;
user_mode = Irc.Mode.Set.empty;
away = None;
membership = Dllist.create ();
}
let outbox t = t.outbox
let nick t = t.nick
let mode t = t.user_mode
let set_mode t new_mode = t.user_mode <- new_mode
let away t = t.away
let set_away t status = t.away <- status
let set_nick t new_nick =
begin
t.nick <- new_nick;
t.nick_key <- string_ci new_nick;
end
let register t ~router = Hashtbl.add router.users t.nick_key t
let unregister t ~router = Hashtbl.remove router.users t.nick_key
let is_registered t ~router = Hashtbl.mem router.users t.nick_key
let prefix t =
Irc.Msg.User_prefix (t.nick, Some t.userinfo)
let membership t =
Dllist.fold_r (fun m xs -> m :: xs) t.membership []
let channels t =
Dllist.fold_r (fun m xs -> m.mem_chan :: xs) t.membership []