@@ -3,32 +3,32 @@ class Room {
3
3
this . users = { } ;
4
4
this . id = id ;
5
5
this . tournament = false ;
6
- this . pasttours = [ ] ;
6
+ this . pasttours = [ ] ;
7
7
this . lasttour = [ false , false ] ;
8
- this . loadSettings ( ) ;
8
+ this . loadSettings ( ) ;
9
9
}
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
+
30
30
send ( message ) {
31
- if ( this . settings . disabled ) return ;
31
+ if ( this . settings . disabled ) return ;
32
32
if ( typeof message === typeof { } ) {
33
33
for ( let i in message ) {
34
34
Send ( this . id , message [ i ] ) ;
@@ -38,19 +38,19 @@ class Room {
38
38
Send ( this . id , message ) ;
39
39
}
40
40
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
+ }
54
54
55
55
leave ( room ) {
56
56
for ( let u in this . users ) {
@@ -59,23 +59,23 @@ class Room {
59
59
}
60
60
bot . emit ( 'dereg' , 'room' , this . id ) ;
61
61
}
62
-
62
+
63
63
startTour ( settings ) {
64
64
this . tournament = new Tournament . Tournament ( this , settings ) ;
65
65
}
66
-
66
+
67
67
endTour ( data ) {
68
68
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 ( ) ;
77
77
}
78
-
78
+
79
79
rename ( oldname , newname ) {
80
80
let id = toId ( newname ) ;
81
81
let name = newname . substring ( 1 ) ;
@@ -85,19 +85,19 @@ class Room {
85
85
Users [ id ] . rename ( newname ) ;
86
86
}
87
87
Utils . ObjectRename ( this . users , oldname , id ) ;
88
- Users [ id ] . rooms [ this . id ] = rank ;
88
+ Users [ id ] . rooms [ this . id ] = rank ;
89
89
}
90
-
90
+
91
91
can ( user , rank ) {
92
92
if ( ! ( toId ( user ) in Users ) ) return false ;
93
93
return Users [ user ] . can ( this . id , rank ) ;
94
94
}
95
95
}
96
96
97
- Room . prototype . toString = function ( ) {
98
- return this . id ;
97
+ Room . prototype . toString = function ( ) {
98
+ return this . id ;
99
99
}
100
100
101
- exports . add = function ( id ) {
101
+ exports . add = function ( id ) {
102
102
this [ id ] = new Room ( id ) ;
103
- }
103
+ }
0 commit comments