-
Notifications
You must be signed in to change notification settings - Fork 0
/
UserCache.js
58 lines (49 loc) · 1.11 KB
/
UserCache.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
module.exports = class {
constructor(sock) {
this.log = require('./newLog')(`@${sock.name}-usercache`);
this.store = new Map();
}
clear() {
this.store = {};
}
cleanup() {
for (let nick in this.store) {
let u = this.store[nick];
if (u.chans.size == 0) { delete this.store[nick]; }
}
}
getUser(nick) {
return this.store[nick] || { nick: nick, chans: new Set() };
}
setUser(nick, u) {
this.store[nick] = u;
}
removeUser(nick) {
delete this.store[nick];
}
joinUser(nick, user, host, chan) {
let u = this.getUser(nick);
u.user = user;
u.host = host;
u.chans.add(chan);
this.setUser(nick, u);
}
partUser(nick, user, host, chan) {
let u = this.getUser(nick);
u.user = user;
u.host = host;
u.chans.delete(chan);
if (u.chans.size == 0) {
this.removeUser(nick);
}
this.setUser(nick, u);
}
nickUser(nick, user, host, newNick) {
this.store[newNick] = this.store[nick];
delete this.store[nick];
this.store[newNick].nick = newNick;
}
quitUser(nick, user, host) {
this.removeUser(nick);
}
}