diff --git a/server/chat.js b/server/chat.js index ede4e5a395..7e5ade8c06 100644 --- a/server/chat.js +++ b/server/chat.js @@ -106,7 +106,7 @@ class PatternTester { /** * @param {string} text */ - test(text) { + testCommand(text) { const spaceIndex = text.indexOf(' '); if (this.fastElements.has(spaceIndex >= 0 ? text.slice(0, spaceIndex) : text)) { return true; @@ -114,6 +114,23 @@ class PatternTester { if (!this.regexp) return false; return this.regexp.test(text); } + /** + * @param {string} text + */ + test(text) { + if (!text.includes('\n')) return null; + if (this.testCommand(text)) return text; + // The PM matching is a huge mess, and really needs to be replaced with + // the new multiline command system soon. + const pmMatches = /^(\/(?:pm|w|whisper|msg) [^,]*, ?)(.*)/i.exec(text); + if (pmMatches && this.testCommand(pmMatches[2])) { + if (text.split('\n').every(line => line.startsWith(pmMatches[1]))) { + return text.replace(/\n\/(?:pm|w|whisper|msg) [^,]*, ?/g, '\n'); + } + return text; + } + return null; + } } Chat.multiLinePattern = new PatternTester(); diff --git a/server/users.js b/server/users.js index 78d945c360..14efc3b4c3 100644 --- a/server/users.js +++ b/server/users.js @@ -1653,8 +1653,9 @@ function socketReceive(worker, workerid, socketid, message) { const room = Rooms(roomId); if (!room) return; - if (Chat.multiLinePattern.test(message)) { - user.chat(message, room, connection); + const multilineMessage = Chat.multiLinePattern.test(message); + if (multilineMessage) { + user.chat(multilineMessage, room, connection); return; }