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.
This commit is contained in:
Simon Ser 2021-06-10 11:53:53 +02:00
parent e28769216a
commit d2e41666ad

View File

@ -32,7 +32,7 @@ export default class Client extends EventTarget {
}; };
status = Client.Status.DISCONNECTED; status = Client.Status.DISCONNECTED;
serverPrefix = null; serverPrefix = { name: "*" };
nick = null; nick = null;
availableCaps = {}; availableCaps = {};
enabledCaps = {}; enabledCaps = {};
@ -158,14 +158,6 @@ export default class Client extends EventTarget {
if (!msg.prefix) { if (!msg.prefix) {
msg.prefix = this.serverPrefix; 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; var msgBatch = null;
if (msg.tags["batch"]) { if (msg.tags["batch"]) {
@ -185,9 +177,12 @@ export default class Client extends EventTarget {
return; return;
} }
if (msg.prefix) {
this.serverPrefix = msg.prefix;
}
console.log("Registration complete"); console.log("Registration complete");
this.setStatus(Client.Status.REGISTERED); this.setStatus(Client.Status.REGISTERED);
this.serverPrefix = msg.prefix;
break; break;
case irc.RPL_ISUPPORT: case irc.RPL_ISUPPORT:
var tokens = msg.params.slice(1, -1); var tokens = msg.params.slice(1, -1);
@ -477,16 +472,10 @@ export default class Client extends EventTarget {
} }
isMyNick(nick) { isMyNick(nick) {
if (!nick) {
return false;
}
return this.cm(nick) == this.cm(this.nick); return this.cm(nick) == this.cm(this.nick);
} }
isChannel(name) { isChannel(name) {
if (!name) {
return false;
}
var chanTypes = this.isupport.get("CHANTYPES") || irc.STD_CHANTYPES; var chanTypes = this.isupport.get("CHANTYPES") || irc.STD_CHANTYPES;
return chanTypes.indexOf(name[0]) >= 0; return chanTypes.indexOf(name[0]) >= 0;
} }