From a761dfaa8e29e36677526768db778ea81cea3501 Mon Sep 17 00:00:00 2001 From: Stubenhocker1399 Date: Thu, 5 Sep 2019 19:50:31 +0200 Subject: [PATCH] Remove word filtering of expressions via command When used as a command, eg. `/bob` or `/e bob`, the word filters are disabled. --- src/ts/common/expressionUtils.ts | 24 ++++++++++++------------ src/ts/server/chat.ts | 2 +- src/ts/server/commands.ts | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/ts/common/expressionUtils.ts b/src/ts/common/expressionUtils.ts index 4a8e3e1..4cc39f3 100644 --- a/src/ts/common/expressionUtils.ts +++ b/src/ts/common/expressionUtils.ts @@ -178,9 +178,9 @@ const verticalLeftRegex = new RegExp(`^${any(muzzlesLeft)}-?${tears}${any(vertic const horizontalRegex = new RegExp(`^${any(horizontalEyesRight)}(//)?${any(horizontalMuzzles)}(//)?${any(horizontalEyesLeft)}$`); function matchVertical( - text: string, regex: RegExp, flip: boolean, muzzleMap: Dict, eyesMap: Dict + text: string, regex: RegExp, flip: boolean, muzzleMap: Dict, eyesMap: Dict, command: boolean = false ): Expression | undefined { - if (/^([|]{2,}|BS|8x|x8|x-?x|\d+)$/i.test(text)) + if (!command && /^([|]{2,}|BS|8x|x8|x-?x|\d+)$/i.test(text)) return undefined; const match = regex.exec(text); @@ -205,15 +205,15 @@ function matchVertical( return { right, left, muzzle, rightIris, leftIris, extra }; } -function matchHorizontal(text: string): Expression | undefined { - if (/\.\.|--|vv|uu|qq|pp|nn|^\d+$/i.test(text)) { +function matchHorizontal(text: string, command: boolean = false): Expression | undefined { + if (!command && /\.\.|--|vv|uu|qq|pp|nn|^\d+$/i.test(text)) { return undefined; } if (/[a-zA-Z][a-z][a-z]|[A-Z]{3}/.test(text)) { const clear = text.replace(/[^a-z]/ig, '').toLowerCase(); - if (clear.length === 3 && threeLetterWords.test(clear)) { + if (clear.length === 3 && (!command && threeLetterWords.test(clear))) { return undefined; } } @@ -221,7 +221,7 @@ function matchHorizontal(text: string): Expression | undefined { if (/[a-z][a-z][.,*-]/i.test(text)) { const clear = text.replace(/[^a-z]/ig, '').toLowerCase(); - if (clear.length === 2 && twoLetterWords.test(clear)) { + if (clear.length === 2 && (!command && twoLetterWords.test(clear))) { return undefined; } } @@ -297,7 +297,7 @@ function matchOther(text: string): Expression | undefined { } } -export function matchExpression(text: string): Expression | undefined { +export function matchExpression(text: string, command: boolean = false): Expression | undefined { if (/тот/ui.test(text)) { return undefined; } @@ -307,16 +307,16 @@ export function matchExpression(text: string): Expression | undefined { .replace(/\\/g, '/') .replace(/\/{3,}/g, '//'); - return matchVertical(text, verticalRightRegex, false, muzzlesRight, verticalEyesRight) - || matchVertical(text, verticalLeftRegex, true, muzzlesLeft, verticalEyesLeft) - || matchHorizontal(text) + return matchVertical(text, verticalRightRegex, false, muzzlesRight, verticalEyesRight, command) + || matchVertical(text, verticalLeftRegex, true, muzzlesLeft, verticalEyesLeft, command) + || matchHorizontal(text, command) || matchOther(text); } -export function parseExpression(text: string): Expression | undefined { +export function parseExpression(text: string, command = false): Expression | undefined { const emoteMatch = /(?:^| )(\S+)\s*$/.exec(text); const emote = emoteMatch && emoteMatch[1].trim(); - return emote ? matchExpression(emote) : undefined; + return emote ? matchExpression(emote, command) : undefined; } function createMap(values: any[][]): Dict { diff --git a/src/ts/server/chat.ts b/src/ts/server/chat.ts index db2c3b3..cdb1300 100644 --- a/src/ts/server/chat.ts +++ b/src/ts/server/chat.ts @@ -121,7 +121,7 @@ export const createSay = } } } else { - const expression = parseExpression(text.substr(1)); + const expression = parseExpression(text.substr(1), true); if (expression) { setEntityExpression(client.pony, expression); diff --git a/src/ts/server/commands.ts b/src/ts/server/commands.ts index e302e5a..3a29117 100644 --- a/src/ts/server/commands.ts +++ b/src/ts/server/commands.ts @@ -197,7 +197,7 @@ export function createCommands(world: World): Command[] { command(['w', 'whisper'], '/w - whisper to player', '', shouldNotBeCalled), command(['r', 'reply'], '/r - reply to whisper', '', shouldNotBeCalled), command(['e'], '/e - set permanent expression', '', ({ }, { pony }, message) => { - pony.exprPermanent = parseExpression(message); + pony.exprPermanent = parseExpression(message, true); setEntityExpression(pony, undefined, 0); }), @@ -206,7 +206,7 @@ export function createCommands(world: World): Command[] { execAction(client, Action.TurnHead, settings); }), command(['boop', ')'], '/boop or /) - a boop', '', ({ }, client, message, _, __, settings) => { - const expression = parseExpression(message); + const expression = parseExpression(message, true); if (expression) { setEntityExpression(client.pony, expression, 800);