Remove word filtering of expressions via command

When used as a command, eg. `/bob` or `/e bob`,
the word filters are disabled.
This commit is contained in:
Stubenhocker1399
2019-09-06 11:39:19 -05:00
committed by Eliot Partridge
parent 829fa3c957
commit a761dfaa8e
3 changed files with 15 additions and 15 deletions
+12 -12
View File
@@ -178,9 +178,9 @@ const verticalLeftRegex = new RegExp(`^${any(muzzlesLeft)}-?${tears}${any(vertic
const horizontalRegex = new RegExp(`^${any(horizontalEyesRight)}(//)?${any(horizontalMuzzles)}(//)?${any(horizontalEyesLeft)}$`); const horizontalRegex = new RegExp(`^${any(horizontalEyesRight)}(//)?${any(horizontalMuzzles)}(//)?${any(horizontalEyesLeft)}$`);
function matchVertical( function matchVertical(
text: string, regex: RegExp, flip: boolean, muzzleMap: Dict<Muzzle>, eyesMap: Dict<Eye> text: string, regex: RegExp, flip: boolean, muzzleMap: Dict<Muzzle>, eyesMap: Dict<Eye>, command: boolean = false
): Expression | undefined { ): 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; return undefined;
const match = regex.exec(text); const match = regex.exec(text);
@@ -205,15 +205,15 @@ function matchVertical(
return { right, left, muzzle, rightIris, leftIris, extra }; return { right, left, muzzle, rightIris, leftIris, extra };
} }
function matchHorizontal(text: string): Expression | undefined { function matchHorizontal(text: string, command: boolean = false): Expression | undefined {
if (/\.\.|--|vv|uu|qq|pp|nn|^\d+$/i.test(text)) { if (!command && /\.\.|--|vv|uu|qq|pp|nn|^\d+$/i.test(text)) {
return undefined; return undefined;
} }
if (/[a-zA-Z][a-z][a-z]|[A-Z]{3}/.test(text)) { if (/[a-zA-Z][a-z][a-z]|[A-Z]{3}/.test(text)) {
const clear = text.replace(/[^a-z]/ig, '').toLowerCase(); 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; return undefined;
} }
} }
@@ -221,7 +221,7 @@ function matchHorizontal(text: string): Expression | undefined {
if (/[a-z][a-z][.,*-]/i.test(text)) { if (/[a-z][a-z][.,*-]/i.test(text)) {
const clear = text.replace(/[^a-z]/ig, '').toLowerCase(); 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; 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)) { if (/тот/ui.test(text)) {
return undefined; return undefined;
} }
@@ -307,16 +307,16 @@ export function matchExpression(text: string): Expression | undefined {
.replace(/\\/g, '/') .replace(/\\/g, '/')
.replace(/\/{3,}/g, '//'); .replace(/\/{3,}/g, '//');
return matchVertical(text, verticalRightRegex, false, muzzlesRight, verticalEyesRight) return matchVertical(text, verticalRightRegex, false, muzzlesRight, verticalEyesRight, command)
|| matchVertical(text, verticalLeftRegex, true, muzzlesLeft, verticalEyesLeft) || matchVertical(text, verticalLeftRegex, true, muzzlesLeft, verticalEyesLeft, command)
|| matchHorizontal(text) || matchHorizontal(text, command)
|| matchOther(text); || 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 emoteMatch = /(?:^| )(\S+)\s*$/.exec(text);
const emote = emoteMatch && emoteMatch[1].trim(); const emote = emoteMatch && emoteMatch[1].trim();
return emote ? matchExpression(emote) : undefined; return emote ? matchExpression(emote, command) : undefined;
} }
function createMap<T>(values: any[][]): Dict<T> { function createMap<T>(values: any[][]): Dict<T> {
+1 -1
View File
@@ -121,7 +121,7 @@ export const createSay =
} }
} }
} else { } else {
const expression = parseExpression(text.substr(1)); const expression = parseExpression(text.substr(1), true);
if (expression) { if (expression) {
setEntityExpression(client.pony, expression); setEntityExpression(client.pony, expression);
+2 -2
View File
@@ -197,7 +197,7 @@ export function createCommands(world: World): Command[] {
command(['w', 'whisper'], '/w <name> - whisper to player', '', shouldNotBeCalled), command(['w', 'whisper'], '/w <name> - whisper to player', '', shouldNotBeCalled),
command(['r', 'reply'], '/r - reply to whisper', '', shouldNotBeCalled), command(['r', 'reply'], '/r - reply to whisper', '', shouldNotBeCalled),
command(['e'], '/e - set permanent expression', '', ({ }, { pony }, message) => { command(['e'], '/e - set permanent expression', '', ({ }, { pony }, message) => {
pony.exprPermanent = parseExpression(message); pony.exprPermanent = parseExpression(message, true);
setEntityExpression(pony, undefined, 0); setEntityExpression(pony, undefined, 0);
}), }),
@@ -206,7 +206,7 @@ export function createCommands(world: World): Command[] {
execAction(client, Action.TurnHead, settings); execAction(client, Action.TurnHead, settings);
}), }),
command(['boop', ')'], '/boop or /) - a boop', '', ({ }, client, message, _, __, settings) => { command(['boop', ')'], '/boop or /) - a boop', '', ({ }, client, message, _, __, settings) => {
const expression = parseExpression(message); const expression = parseExpression(message, true);
if (expression) { if (expression) {
setEntityExpression(client.pony, expression, 800); setEntityExpression(client.pony, expression, 800);