Skip to content

Commit c8aa33a

Browse files
committed
Unify formatting
1 parent 25bbf42 commit c8aa33a

File tree

9 files changed

+188
-187
lines changed

9 files changed

+188
-187
lines changed

Room.js

+53-53
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,32 @@ class Room {
33
this.users = {};
44
this.id = id;
55
this.tournament = false;
6-
this.pasttours = [];
6+
this.pasttours = [];
77
this.lasttour = [false, false];
8-
this.loadSettings();
8+
this.loadSettings();
99
}
10-
11-
loadSettings() {
12-
const PATH = `./rooms/${this.id}.json`;
13-
if (!FS.existsSync(PATH)) FS.copyFileSync('./rooms/config-example.json', PATH);
14-
this.settings = JSON.parse(FS.readFileSync(PATH));
15-
this.repeat = this.settings.repeat;
16-
if (this.settings.pasttours) {
17-
this.pasttours = this.settings.pasttours;
18-
}
19-
}
20-
21-
saveSettings(load = false) {
22-
const PATH = `./rooms/${this.id}.json`;
23-
this.settings.repeat = this.repeat;
24-
this.settings.pasttours = this.pasttours;
25-
let settings = JSON.stringify(this.settings, null, 4);
26-
FS.writeFileSync(PATH, settings);
27-
if (load) this.loadSettings();
28-
}
29-
10+
11+
loadSettings() {
12+
const PATH = `./rooms/${this.id}.json`;
13+
if (!FS.existsSync(PATH)) FS.copyFileSync('./rooms/config-example.json', PATH);
14+
this.settings = JSON.parse(FS.readFileSync(PATH));
15+
this.repeat = this.settings.repeat;
16+
if (this.settings.pasttours) {
17+
this.pasttours = this.settings.pasttours;
18+
}
19+
}
20+
21+
saveSettings(load = false) {
22+
const PATH = `./rooms/${this.id}.json`;
23+
this.settings.repeat = this.repeat;
24+
this.settings.pasttours = this.pasttours;
25+
let settings = JSON.stringify(this.settings, null, 4);
26+
FS.writeFileSync(PATH, settings);
27+
if (load) this.loadSettings();
28+
}
29+
3030
send(message) {
31-
if (this.settings.disabled) return;
31+
if (this.settings.disabled) return;
3232
if (typeof message === typeof {}) {
3333
for (let i in message) {
3434
Send(this.id, message[i]);
@@ -38,19 +38,19 @@ class Room {
3838
Send(this.id, message);
3939
}
4040

41-
runChecks(message) {
42-
let now = Date.now();
43-
if (this.repeat) {
44-
let diff = (now - this.repeat.last) / 60000;
45-
this.repeat.msgs += 1;
46-
if (this.repeat.msgs >= this.repeat.minmsg && diff >= this.repeat.mintime) {
47-
this.repeat.last = now;
48-
this.repeat.msgs = 0;
49-
this.send(this.repeat.message);
50-
this.saveSettings()
51-
}
52-
}
53-
}
41+
runChecks(message) {
42+
let now = Date.now();
43+
if (this.repeat) {
44+
let diff = (now - this.repeat.last) / 60000;
45+
this.repeat.msgs += 1;
46+
if (this.repeat.msgs >= this.repeat.minmsg && diff >= this.repeat.mintime) {
47+
this.repeat.last = now;
48+
this.repeat.msgs = 0;
49+
this.send(this.repeat.message);
50+
this.saveSettings()
51+
}
52+
}
53+
}
5454

5555
leave(room) {
5656
for (let u in this.users) {
@@ -59,23 +59,23 @@ class Room {
5959
}
6060
bot.emit('dereg', 'room', this.id);
6161
}
62-
62+
6363
startTour(settings) {
6464
this.tournament = new Tournament.Tournament(this, settings);
6565
}
66-
66+
6767
endTour(data) {
6868
if (this.tournament) this.tournament.end(data);
69-
if (this.tournament.toString()) {
70-
this.pasttours.push(this.tournament.toString());
71-
this.lasttour[0] = Date.now();
72-
this.lasttour[1] = this.tournament.toString();
73-
}
74-
while (this.pasttours.join(', ').length > 250) this.pasttours.shift();
75-
this.tournament = false;
76-
this.saveSettings();
69+
if (this.tournament.toString()) {
70+
this.pasttours.push(this.tournament.toString());
71+
this.lasttour[0] = Date.now();
72+
this.lasttour[1] = this.tournament.toString();
73+
}
74+
while (this.pasttours.join(', ').length > 250) this.pasttours.shift();
75+
this.tournament = false;
76+
this.saveSettings();
7777
}
78-
78+
7979
rename(oldname, newname) {
8080
let id = toId(newname);
8181
let name = newname.substring(1);
@@ -85,19 +85,19 @@ class Room {
8585
Users[id].rename(newname);
8686
}
8787
Utils.ObjectRename(this.users, oldname, id);
88-
Users[id].rooms[this.id] = rank;
88+
Users[id].rooms[this.id] = rank;
8989
}
90-
90+
9191
can(user, rank) {
9292
if (!(toId(user) in Users)) return false;
9393
return Users[user].can(this.id, rank);
9494
}
9595
}
9696

97-
Room.prototype.toString = function() {
98-
return this.id;
97+
Room.prototype.toString = function () {
98+
return this.id;
9999
}
100100

101-
exports.add = function(id) {
101+
exports.add = function (id) {
102102
this[id] = new Room(id);
103-
}
103+
}

Tournament.js

+23-24
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,47 @@ class Tournament {
66
this.started = false;
77
this.players = {};
88
this.chill = type === 'chill';
9-
this.name = false;
10-
this.format = false;
9+
this.name = false;
10+
this.format = false;
1111
let tourcheck = room.id
1212
if (type === "late") {
1313
this.started = true;
14-
return;
15-
this.format = 'unknown';
16-
}
14+
return;
15+
this.format = 'unknown';
16+
}
1717
if (Config.tours[tourcheck]) {
1818
let t = Config.tours[tourcheck];
19-
if (t[0]) {
20-
this.room.send(`/tour autostart ${t[0]}`);
21-
this.room.send(`/tour autodq ${t[1]}`);
22-
}
19+
if (t[0]) {
20+
this.room.send(`/tour autostart ${t[0]}`);
21+
this.room.send(`/tour autodq ${t[1]}`);
22+
}
2323
if (t[2]) this.room.send('/tour scouting disallow');
24-
}
25-
else if (Config.tours[room.id]) {
24+
} else if (Config.tours[room.id]) {
2625
let t = Config.tours[room.id];
2726
this.room.send(`/tour autostart ${t[0]}`);
2827
this.room.send(`/tour autodq ${t[1]}`);
2928
if (t[2]) this.room.send('/tour scouting disallow');
3029
}
3130
if (this.chill) room.send('/modchat +');
3231
}
33-
32+
3433

3534
end(data) {
36-
if (data) {
37-
let dt = JSON.parse(data);
38-
if (dt.format && formats[dt.format]) this.name = formats[dt.format];
39-
else this.name = dt.format ? dt.format : this.name;
40-
}
35+
if (data) {
36+
let dt = JSON.parse(data);
37+
if (dt.format && formats[dt.format]) this.name = formats[dt.format];
38+
else this.name = dt.format ? dt.format : this.name;
39+
}
4140
if (this.chill) this.room.send('/modchat off');
4241
}
4342
}
4443

45-
Tournament.prototype.toString = function() {
46-
if (this.name) return this.name;
47-
if (this.format) return this.format === 'unknown' ? false : this.format;
48-
return false;
44+
Tournament.prototype.toString = function () {
45+
if (this.name) return this.name;
46+
if (this.format) return this.format === 'unknown' ? false : this.format;
47+
return false;
4948
}
5049
module.exports = {
51-
Tournament: Tournament,
52-
formats: formats
53-
}
50+
Tournament: Tournament,
51+
formats: formats
52+
}

User.js

+17-16
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class User {
55
this.id = toId(name);
66
this.checkmail();
77
}
8-
8+
99
send(message) {
1010
if (typeof message === typeof {}) {
1111
for (let i in message) {
@@ -15,17 +15,18 @@ class User {
1515
}
1616
Sendpm(this.name, message);
1717
}
18-
18+
1919
checkmail() {
2020
let self = this;
2121
FS.readFile(`mail/${self.id}.json`, (err, data) => {
2222
let maildata = [];
23-
if (err) { return; }
24-
25-
try {
26-
maildata = JSON.parse(data);
23+
if (err) {
24+
return;
2725
}
28-
catch (e) {
26+
27+
try {
28+
maildata = JSON.parse(data);
29+
} catch (e) {
2930
maildata = ["[mailerror] Your mail data crashed. Some mail may have gotten lost."];
3031
FS.unlinkSync(`mail/${self.id}.json`);
3132
}
@@ -39,26 +40,26 @@ class User {
3940
});
4041
});
4142
}
42-
43+
4344
join(room, name) {
4445
this.rooms[room] = name.charAt(0);
4546
Rooms[room].users[this.id] = this;
4647
}
47-
48+
4849
leave(room) {
4950
delete this.rooms[room];
5051
delete Rooms[room].users[this.id];
5152
if (!Object.keys(this.rooms).length) bot.emit('dereg', 'user', this.id);
5253
}
53-
54+
5455
rename(name) {
5556
this.id = toId(name);
5657
this.name = name.substring(1);
5758
this.checkmail();
5859
}
59-
60+
6061
can(room, rank) {
61-
if (this.id === "staff") return true;
62+
if (this.id === "staff") return true;
6263
if (!this.rooms[room] && room !== this) return false;
6364
if (Config.devs.indexOf(this.id) !== -1) return true;
6465
if (rank === "all") return false;
@@ -69,16 +70,16 @@ class User {
6970
}
7071
}
7172

72-
User.prototype.toString = function() {
73-
return this.id;
73+
User.prototype.toString = function () {
74+
return this.id;
7475
}
7576

76-
exports.add = function(name) {
77+
exports.add = function (name) {
7778
let id = toId(name);
7879
this[id] = new User(name);
7980
}
8081

8182
exports[toId(Config.username)] = new User(" " + Config.username);
8283
exports.self = exports[toId(Config.username)];
8384

84-
exports.staff = new User(" Staff");
85+
exports.staff = new User(" Staff");

0 commit comments

Comments
 (0)