From 7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2 Mon Sep 17 00:00:00 2001 From: marzavec Date: Sat, 10 Mar 2018 22:41:17 -0800 Subject: stabilized modules and server cmd field --- server/src/commands/core/chat.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'server/src/commands/core/chat.js') diff --git a/server/src/commands/core/chat.js b/server/src/commands/core/chat.js index 4fe3b80..c086077 100644 --- a/server/src/commands/core/chat.js +++ b/server/src/commands/core/chat.js @@ -4,15 +4,23 @@ 'use strict'; -exports.run = async (core, server, socket, data) => { - // process text - let text = String(data.text); +function parseText(text) { + if (typeof text !== 'string') { + return false; + } + // strip newlines from beginning and end text = text.replace(/^\s*\n|^\s+$|\n\s*$/g, ''); // replace 3+ newlines with just 2 newlines text = text.replace(/\n{3,}/g, "\n\n"); + + return text; +} + +exports.run = async (core, server, socket, data) => { + let text = parseText(data.text); if (!text) { - // lets not send empty text? + // lets not send objects or empty text, yea? return; } -- cgit v1.2.1