talircd/lib/server/user.ml

42 lines
946 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;
2024-01-31 02:30:54 +00:00
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
2024-01-31 02:30:54 +00:00
let away t = t.away
let set_away t status = t.away <- status
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 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 []