lib/irc: fix handling for prefixes without host

name!user is a valid prefix.
This commit is contained in:
Simon Ser 2021-11-15 16:05:51 +01:00
parent 55361c5a2b
commit be475026c8

View file

@ -122,32 +122,32 @@ export function parsePrefix(s) {
host: null,
};
let host = null;
let i = s.indexOf("@");
if (i < 0) {
prefix.name = s;
return prefix;
if (i > 0) {
host = s.slice(i + 1);
s = s.slice(0, i);
}
prefix.host = s.slice(i + 1);
s = s.slice(0, i);
let user = null;
i = s.indexOf("!");
if (i < 0) {
prefix.name = s;
return prefix;
if (i > 0) {
user = s.slice(i + 1);
s = s.slice(0, i);
}
prefix.name = s.slice(0, i);
prefix.user = s.slice(i + 1);
return prefix;
return { name: s, user, host };
}
function formatPrefix(prefix) {
if (!prefix.host) {
return prefix.name;
let s = prefix.name;
if (prefix.user) {
s += "!" + prefix.user;
}
if (!prefix.user) {
return prefix.name + "@" + prefix.host;
if (prefix.host) {
s += "@" + prefix.host;
}
return prefix.name + "!" + prefix.user + "@" + prefix.host;
return s;
}
export function parseMessage(s) {