Skip to content

Commit e2ee8ab

Browse files
committed
chore: Add null checks to this.status while sending messages
1 parent fa082a0 commit e2ee8ab

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

client.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class Client extends EventEmitter {
6868
// Websocket
6969
connect(retry) {
7070
if (retry) this.debug('Retrying...');
71-
if (this.status.connected) return this.handle('Already connected');
71+
if (this.status?.connected) return this.handle('Already connected');
7272
this.closed = false;
7373

7474
this.rooms = new Map();
@@ -205,7 +205,7 @@ class Client extends EventEmitter {
205205
this.connection.send(text);
206206
}
207207
sendQueue(text, sent, fail) {
208-
if (!this.status.connected) return fail?.({ cause: 'Not connected.', message: text });
208+
if (!this.status?.connected) return fail?.({ cause: 'Not connected.', message: text });
209209
const multiTest = text.match(/^([a-z0-9-]*?\|(?:\/pm [^,]*?, ?)?)[^/!].*?\n/);
210210
if (multiTest) {
211211
// Multi-line messages
@@ -414,7 +414,7 @@ class Client extends EventEmitter {
414414
}
415415
});
416416
mssg.target._waits = mssg.target._waits.filter(wait => !resolved.includes(wait.id));
417-
if (mssg.author.userid === this.status.userid && !isIntro) {
417+
if (mssg.author.userid === this.status?.userid && !isIntro) {
418418
const checkVal = `${room}|${value}`;
419419
if (this._queued.some(msg => msg.content === checkVal)) {
420420
while (this._queued.length) {
@@ -438,7 +438,7 @@ class Client extends EventEmitter {
438438
let value = args.slice(4).join('|');
439439
const isHidden = value.startsWith('/botmsg ');
440440
if (isHidden) value = value.replace(/^\/botmsg /, '');
441-
const chatWith = by.substr(1) === this.status.username ? to : by,
441+
const chatWith = by.substr(1) === this.status?.username ? to : by,
442442
comp = `|/pm ${Tools.toID(to)},${value}`;
443443
const mssg = new Message({
444444
by: by,
@@ -461,7 +461,7 @@ class Client extends EventEmitter {
461461
}
462462
});
463463
mssg.target._waits = mssg.target._waits.filter(wait => !resolved.includes(wait.id));
464-
if (!isIntro && by.substr(1) === this.status.username && this._queued.map(msg => msg.content).includes(comp)) {
464+
if (!isIntro && by.substr(1) === this.status?.username && this._queued.map(msg => msg.content).includes(comp)) {
465465
while (this._queued.length) {
466466
const msg = this._queued.shift();
467467
if (msg.content === comp) {
@@ -603,7 +603,7 @@ class Client extends EventEmitter {
603603
}
604604

605605
[customInspectSymbol](depth, options, inspect) {
606-
if (depth < 1) return options.stylize(`${this.status.username || '-'} [PS-Client]`, 'special');
606+
if (depth < 1) return options.stylize(`${this.status?.username || '-'} [PS-Client]`, 'special');
607607
const outKeys = ['opts', 'status', 'rooms', 'users', 'isTrusted', 'closed'];
608608
const logObj = {};
609609
outKeys.forEach(key => (logObj[key] = this[key]));

0 commit comments

Comments
 (0)