@@ -21,27 +21,35 @@ class User {
21
21
if ( typeof opts === 'string' ) opts = { name : opts } ;
22
22
if ( ! opts || typeof opts !== 'object' ) throw new TypeError ( 'Options must be an object' ) ;
23
23
if ( ! opts . name ) opts . name = this . parent . status . username + Date . now ( ) . toString ( 36 ) ;
24
- const rooms = { } ;
25
- for ( const room of this . parent . rooms . values ( ) ) {
26
- if ( room . auth ?. [ '*' ] ?. includes ( this . parent . status . userid ) || room . auth ?. [ '#' ] ?. includes ( this . parent . status . userid ) )
27
- rooms [ room . visibility ] = room ;
24
+ let room ;
25
+ if ( opts . room ) room = typeof opts . room === 'string' ? this . parent . getRoom ( opts . room ) : opts . room ;
26
+ else {
27
+ const rooms = { } ;
28
+ for ( const room of this . parent . rooms . values ( ) ) {
29
+ if ( room . auth ?. [ '*' ] ?. includes ( this . parent . status . userid ) || room . auth ?. [ '#' ] ?. includes ( this . parent . status . userid ) )
30
+ rooms [ room . visibility ] = room ;
31
+ }
32
+ room = rooms . public || rooms . hidden || rooms . secret || rooms . private ;
28
33
}
29
- const room = rooms . public || rooms . hidden || rooms . private ;
30
- if ( ! room ) return '' ;
34
+ if ( ! room ) return false ;
31
35
const formatted = opts . notransform ? html : this . parent . opts . transformHTML ( html , opts ) ;
32
36
room . send ( `/pmuhtml${ opts . change ? 'change' : '' } ${ this . userid } , ${ opts . name } , ${ formatted } ` ) ;
33
37
return formatted ;
34
38
}
35
39
pageHTML ( html , opts = { } ) {
36
40
if ( ! html ) throw new Error ( 'Missing HTML argument' ) ;
37
41
if ( ! opts . name ) opts . name = this . parent . status . username + Date . now ( ) . toString ( 36 ) ;
38
- const rooms = { } ;
39
- for ( const room of this . parent . rooms . values ( ) ) {
40
- if ( room . auth ?. [ '*' ] ?. includes ( this . parent . status . userid ) || room . auth ?. [ '#' ] ?. includes ( this . parent . status . userid ) )
41
- rooms [ room . visibility ] = room ;
42
+ let room ;
43
+ if ( opts . room ) room = typeof opts . room === 'string' ? this . parent . getRoom ( opts . room ) : opts . room ;
44
+ else {
45
+ const rooms = { } ;
46
+ for ( const room of this . parent . rooms . values ( ) ) {
47
+ if ( room . auth ?. [ '*' ] ?. includes ( this . parent . status . userid ) || room . auth ?. [ '#' ] ?. includes ( this . parent . status . userid ) )
48
+ rooms [ room . visibility ] = room ;
49
+ }
50
+ room = rooms . public || rooms . hidden || rooms . secret || rooms . private ;
42
51
}
43
- const room = rooms . public || rooms . hidden || rooms . private ;
44
- if ( ! room ) return '' ;
52
+ if ( ! room ) return false ;
45
53
const formatted = opts . notransform ? html : this . parent . opts . transformHTML ( html , opts ) ;
46
54
room . send ( `/sendhtmlpage ${ this . userid } , ${ opts . name } , ${ formatted } ` ) ;
47
55
return formatted ;
0 commit comments