58 lines
1.3 KiB
OCaml
58 lines
1.3 KiB
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 =
|
|
begin
|
|
Hashtbl.add router.users t.nick_key t;
|
|
Cache.add router.whowas t.nick_key (t.nick, t.userinfo);
|
|
end
|
|
|
|
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 []
|
|
|
|
let highest_membership_priv t =
|
|
Dllist.fold_r (fun m p -> max m.mem_priv p) t.membership Normal
|
|
|
|
let is_member t chan =
|
|
Dllist.exists (fun m -> m.mem_chan == chan)
|
|
t.membership
|
|
|
|
let find_common_channel t1 t2 =
|
|
let mem = Dllist.find (fun m -> is_member t2 m.mem_chan) t1.membership in
|
|
mem.mem_chan
|