aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/chat.js
diff options
context:
space:
mode:
authormarzavec <admin@marzavec.com>2018-03-11 07:41:17 +0100
committermarzavec <admin@marzavec.com>2018-03-11 07:41:26 +0100
commit7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2 (patch)
treec73d26f8d6e3b2c7af23e4afcd55ea7ceccf3596 /server/src/commands/core/chat.js
parentMerge pull request #1 from MinusGix/master (diff)
downloadhackchat-7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2.tar.gz
hackchat-7d8220d838f82f7ad1ffedbcbd3b955aef6d71a2.zip
stabilized modules and server cmd field
Diffstat (limited to 'server/src/commands/core/chat.js')
-rw-r--r--server/src/commands/core/chat.js16
1 files changed, 12 insertions, 4 deletions
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;
}