Fixed text sanitisation issues.
This commit is contained in:
parent
c105b57488
commit
d01a1d454c
1 changed files with 20 additions and 5 deletions
|
@ -143,7 +143,16 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const unfuckText = text => text.replace(/ <br\/> /g, "\n");
|
const unfuckText = (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(/</g, '<')
|
||||||
|
.replace(/>/g, '>');
|
||||||
|
};
|
||||||
|
|
||||||
const onMessage = ev => {
|
const onMessage = ev => {
|
||||||
const args = ev.detail.data.split("\t");
|
const args = ev.detail.data.split("\t");
|
||||||
|
@ -249,7 +258,8 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
|
||||||
|
|
||||||
// message add
|
// message add
|
||||||
handlers['2'] = (timeStamp, userId, msgText, msgId, msgFlags) => {
|
handlers['2'] = (timeStamp, userId, msgText, msgId, msgFlags) => {
|
||||||
let mText = unfuckText(msgText);
|
const mFlags = parseMsgFlags(msgFlags);
|
||||||
|
let mText = unfuckText(msgText, mFlags.isAction);
|
||||||
let mChannelName = selfChannelName;
|
let mChannelName = selfChannelName;
|
||||||
|
|
||||||
if(msgFlags[4] !== '0') {
|
if(msgFlags[4] !== '0') {
|
||||||
|
@ -271,7 +281,7 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
|
||||||
id: userId,
|
id: userId,
|
||||||
self: userId === selfUserId,
|
self: userId === selfUserId,
|
||||||
},
|
},
|
||||||
flags: parseMsgFlags(msgFlags),
|
flags: mFlags,
|
||||||
flagsRaw: msgFlags,
|
flagsRaw: msgFlags,
|
||||||
isBot: userId === '-1',
|
isBot: userId === '-1',
|
||||||
text: mText,
|
text: mText,
|
||||||
|
@ -433,6 +443,7 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
|
||||||
|
|
||||||
// existing message
|
// existing message
|
||||||
handlers['7']['1'] = (timeStamp, userId, userName, userColour, userPerms, msgText, msgId, msgNotify, msgFlags) => {
|
handlers['7']['1'] = (timeStamp, userId, userName, userColour, userPerms, msgText, msgId, msgNotify, msgFlags) => {
|
||||||
|
const mFlags = parseMsgFlags(msgFlags);
|
||||||
const info = {
|
const info = {
|
||||||
msg: {
|
msg: {
|
||||||
id: msgId,
|
id: msgId,
|
||||||
|
@ -448,9 +459,9 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
|
||||||
},
|
},
|
||||||
isBot: userId === '-1',
|
isBot: userId === '-1',
|
||||||
silent: msgNotify === '0',
|
silent: msgNotify === '0',
|
||||||
flags: parseMsgFlags(msgFlags),
|
flags: mFlags,
|
||||||
flagsRaw: msgFlags,
|
flagsRaw: msgFlags,
|
||||||
text: unfuckText(msgText),
|
text: unfuckText(msgText, mFlags.isAction),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -465,6 +476,10 @@ Umi.Protocol.SockChat.Protocol = function(pingDuration) {
|
||||||
type: botParts[1],
|
type: botParts[1],
|
||||||
args: botParts.slice(2),
|
args: botParts.slice(2),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// i think this is more Inaccurate Behaviour on the server side
|
||||||
|
if(info.msg.botInfo.type === 'say')
|
||||||
|
info.msg.botInfo.args[0] = unfuckText(info.msg.botInfo.args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
eventTarget.dispatch('msg:add', info);
|
eventTarget.dispatch('msg:add', info);
|
||||||
|
|
Loading…
Reference in a new issue