mirror of
https://git.sr.ht/~emersion/gamja
synced 2024-11-14 19:25:26 -05:00
lib/irc: fix handling for prefixes without host
name!user is a valid prefix.
This commit is contained in:
parent
55361c5a2b
commit
be475026c8
1 changed files with 16 additions and 16 deletions
32
lib/irc.js
32
lib/irc.js
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue