From d2e41666adeef985a082e9371d33bb64d82cfd8e Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Thu, 10 Jun 2021 11:53:53 +0200 Subject: [PATCH] lib/client: set a default server prefix Set the default server prefix to "*". This allows the rest of the code to assume all messages always have a prefix. --- lib/client.js | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/client.js b/lib/client.js index a5ec935..743f2db 100644 --- a/lib/client.js +++ b/lib/client.js @@ -32,7 +32,7 @@ export default class Client extends EventTarget { }; status = Client.Status.DISCONNECTED; - serverPrefix = null; + serverPrefix = { name: "*" }; nick = null; availableCaps = {}; enabledCaps = {}; @@ -158,14 +158,6 @@ export default class Client extends EventTarget { if (!msg.prefix) { msg.prefix = this.serverPrefix; } - // Some servers send e.g. NOTICE messages before RPL_WELCOME - if (!msg.prefix) { - msg.prefix = { - name: null, - user: null, - host: null, - }; - } var msgBatch = null; if (msg.tags["batch"]) { @@ -185,9 +177,12 @@ export default class Client extends EventTarget { return; } + if (msg.prefix) { + this.serverPrefix = msg.prefix; + } + console.log("Registration complete"); this.setStatus(Client.Status.REGISTERED); - this.serverPrefix = msg.prefix; break; case irc.RPL_ISUPPORT: var tokens = msg.params.slice(1, -1); @@ -477,16 +472,10 @@ export default class Client extends EventTarget { } isMyNick(nick) { - if (!nick) { - return false; - } return this.cm(nick) == this.cm(this.nick); } isChannel(name) { - if (!name) { - return false; - } var chanTypes = this.isupport.get("CHANTYPES") || irc.STD_CHANTYPES; return chanTypes.indexOf(name[0]) >= 0; }