talircd/lib/server/user.ml

36 lines
794 B
OCaml
Raw Normal View History

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;
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 set_nick t new_nick =
2024-01-22 17:48:44 +00:00
begin
t.nick <- new_nick;
2024-01-22 17:48:44 +00:00
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
2024-01-23 18:46:48 +00:00
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 channels t =
Dllist.fold_r (fun m xs -> m.mem_chan :: xs) t.membership []