Skip to content

Commit 18bbd5f

Browse files
committed
chore: Support opts.room for User#HTML; include secret rooms while determining HTML target
1 parent 8182b8e commit 18bbd5f

File tree

2 files changed

+24
-12
lines changed

2 files changed

+24
-12
lines changed

classes/common.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
1+
import Room from './room';
2+
13
export type HTMLopts = {
24
name?: string;
35
rank?: '+' | '%' | '*' | '@' | '#' | '§' | '&';
46
change?: boolean;
57
notransform?: boolean;
8+
// Only used for User#HTML methods.
9+
room?: string | Room;
610
};

classes/user.js

+20-12
Original file line numberDiff line numberDiff line change
@@ -21,27 +21,35 @@ class User {
2121
if (typeof opts === 'string') opts = { name: opts };
2222
if (!opts || typeof opts !== 'object') throw new TypeError('Options must be an object');
2323
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;
2833
}
29-
const room = rooms.public || rooms.hidden || rooms.private;
30-
if (!room) return '';
34+
if (!room) return false;
3135
const formatted = opts.notransform ? html : this.parent.opts.transformHTML(html, opts);
3236
room.send(`/pmuhtml${opts.change ? 'change' : ''} ${this.userid}, ${opts.name}, ${formatted}`);
3337
return formatted;
3438
}
3539
pageHTML(html, opts = {}) {
3640
if (!html) throw new Error('Missing HTML argument');
3741
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;
4251
}
43-
const room = rooms.public || rooms.hidden || rooms.private;
44-
if (!room) return '';
52+
if (!room) return false;
4553
const formatted = opts.notransform ? html : this.parent.opts.transformHTML(html, opts);
4654
room.send(`/sendhtmlpage ${this.userid}, ${opts.name}, ${formatted}`);
4755
return formatted;

0 commit comments

Comments
 (0)