mami/src/proto.js/sockchat/utils.js
flash cf71bab92d Rewrote connection handling.
This has been in the works for over a month and might break things because it's a very radical change.
If it causes you to be unable to join chat, report it on the forum or try joining using the legacy chat on https://sockchat.flashii.net.
2024-04-17 15:42:50 +00:00

56 lines
1.4 KiB
JavaScript

const SockChatUnfuckText = (text, isAction) => {
// P7.1 doesn't wrap in <i>, likely a bug in SharpChat
// check if this is the case with the PHPChat impl
if(isAction && text.startsWith('<i>'))
text = text.slice(3, -4);
return text.replace(/ <br\/> /g, "\n")
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>');
};
const SockChatParseUserColour = str => {
// todo
return str;
};
const SockChatParseUserPerms = str => {
const parts = str.split(str.includes("\f") ? "\f" : ' ');
return {
rank: parseInt(parts[0] ?? '0'),
kick: parts[1] !== undefined && parts[1] !== '0',
nick: parts[3] !== undefined && parts[3] !== '0',
chan: parts[4] !== undefined && parts[4] !== '0',
};
};
const SockChatParseMsgFlags = str => {
return {
nameBold: str[0] !== '0',
nameItalics: str[1] !== '0',
nameUnderline: str[2] !== '0',
showColon: str[3] !== '0',
isPM: str[4] !== '0',
isAction: str[1] !== '0' && str[3] === '0',
};
};
const SockChatParseStatusInfo = name => {
const isAway = name.startsWith('&lt;');
let message;
if(isAway) {
const index = name.indexOf('&gt;_');
message = name.substring(4, index);
name = name.substring(index + 5);
}
return {
name: name,
status: {
isAway: isAway,
message: message,
},
};
};