mirror of
https://github.com/smogon/pokemon-showdown.git
synced 2026-04-26 18:57:15 -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
|
* @param {string} text
|
||||||
*/
|
*/
|
||||||
test(text) {
|
testCommand(text) {
|
||||||
const spaceIndex = text.indexOf(' ');
|
const spaceIndex = text.indexOf(' ');
|
||||||
if (this.fastElements.has(spaceIndex >= 0 ? text.slice(0, spaceIndex) : text)) {
|
if (this.fastElements.has(spaceIndex >= 0 ? text.slice(0, spaceIndex) : text)) {
|
||||||
return true;
|
return true;
|
||||||
|
|
@ -114,6 +114,23 @@ class PatternTester {
|
||||||
if (!this.regexp) return false;
|
if (!this.regexp) return false;
|
||||||
return this.regexp.test(text);
|
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();
|
Chat.multiLinePattern = new PatternTester();
|
||||||
|
|
|
||||||
|
|
@ -1653,8 +1653,9 @@ function socketReceive(worker, workerid, socketid, message) {
|
||||||
|
|
||||||
const room = Rooms(roomId);
|
const room = Rooms(roomId);
|
||||||
if (!room) return;
|
if (!room) return;
|
||||||
if (Chat.multiLinePattern.test(message)) {
|
const multilineMessage = Chat.multiLinePattern.test(message);
|
||||||
user.chat(message, room, connection);
|
if (multilineMessage) {
|
||||||
|
user.chat(multilineMessage, room, connection);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user