-
Notifications
You must be signed in to change notification settings - Fork 4
/
Room.js
83 lines (73 loc) · 2.21 KB
/
Room.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Room {
constructor(id) {
this.users = {};
this.id = id;
this.tournament = false;
}
send(message) {
if (typeof message === typeof {}) {
for (let i in message) {
Send(this.id, message[i])
}
return;
}
Send(this.id, message);
}
leave(room) {
for (let u in this.users) {
let user = this.users[u];
user.leave(this.id);
}
bot.emit('dereg', 'room', this.id);
}
startTour(settings) {
this.tournament = new Tournament(this, settings);
}
endTour() {
if (this.tournament) this.tournament.end();
this.tournament = false;
}
updateTourRules() {
if (!this.tournament) throw new Error("This shouldn't happen but bot tried to update tour rules without a tour running");
this.send(this.tournament.buildRules());
}
rename(oldname, newname) {
console.log(oldname + ", " + newname + ", " + Object.keys(Users))
let id = toId(newname);
if (id.startsWith("guest")) return;
let name = newname.substring(1);
let rank = newname.charAt(0);
if (!(id in Users)) {
Utils.ObjectRename(Users, oldname, id);
Users[id].rename(newname);
}
Utils.ObjectRename(this.users, oldname, id);
Users[id].rooms[this.id] = rank;
}
can(user, rank) {
if (!(toId(user) in Users)) return false;
return Users[user].can(this.id, rank);
}
is(type) {
type = type.toLowerCase();
if (type === "zero") {
return this.id === "groupchat-icekyubs-zero";
}
if (type === "gc") {
return (this.id.startsWith("groupchat-battledome") || this.id.startsWith("groupchat-icekyubs"));
}
if (type === "bd" || type === "battledome") {
return (this.id === "battledome");
}
if (type === "game" || type === "bd+" || type === "game+") {
return (this.id === "battledome" || this.id.startsWith("groupchat-battledome") || this.id.startsWith("groupchat-icekyubs"));
}
return false;
}
}
Room.prototype.toString = function() {
return this.id;
}
exports.add = function(id) {
this[id] = new Room(id);
}