mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-03-21 17:25:10 -05:00
Support multiline commands in PM
This is a huge hack... :[
This commit is contained in:
parent
df4d16cc20
commit
f286746d9f
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user