aboutsummaryrefslogtreecommitdiffstats
path: root/server/src/commands/core/whisper.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/commands/core/whisper.js')
-rw-r--r--server/src/commands/core/whisper.js69
1 files changed, 36 insertions, 33 deletions
diff --git a/server/src/commands/core/whisper.js b/server/src/commands/core/whisper.js
index 109889d..1cfa157 100644
--- a/server/src/commands/core/whisper.js
+++ b/server/src/commands/core/whisper.js
@@ -11,36 +11,38 @@ const parseText = (text) => {
return false;
}
+ let sanitizedText = text;
+
// strip newlines from beginning and end
- text = text.replace(/^\s*\n|^\s+$|\n\s*$/g, '');
+ sanitizedText = sanitizedText.replace(/^\s*\n|^\s+$|\n\s*$/g, '');
// replace 3+ newlines with just 2 newlines
- text = text.replace(/\n{3,}/g, "\n\n");
+ sanitizedText = sanitizedText.replace(/\n{3,}/g, '\n\n');
- return text;
+ return sanitizedText;
};
// module main
-exports.run = async (core, server, socket, payload) => {
+export async function run(core, server, socket, payload) {
// check user input
- let text = parseText(payload.text);
+ const text = parseText(payload.text);
if (!text) {
// lets not send objects or empty text, yea?
- return server.police.frisk(socket.remoteAddress, 13);
+ return server.police.frisk(socket.address, 13);
}
// check for spam
- let score = text.length / 83 / 4;
- if (server.police.frisk(socket.remoteAddress, score)) {
+ const score = text.length / 83 / 4;
+ if (server.police.frisk(socket.address, score)) {
return server.reply({
cmd: 'warn',
- text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.'
+ text: 'You are sending too much text. Wait a moment and try again.\nPress the up arrow key to restore your last message.',
}, socket);
}
- let targetNick = payload.nick;
+ const targetNick = payload.nick;
if (!verifyNickname(targetNick)) {
- return;
+ return true;
}
// find target user
@@ -49,18 +51,18 @@ exports.run = async (core, server, socket, payload) => {
if (targetClient.length === 0) {
return server.reply({
cmd: 'warn',
- text: 'Could not find user in channel'
+ text: 'Could not find user in channel',
}, socket);
}
- targetClient = targetClient[0];
+ [targetClient] = targetClient;
server.reply({
cmd: 'info',
type: 'whisper',
from: socket.nick,
trip: socket.trip || 'null',
- text: `${socket.nick} whispered: ${text}`
+ text: `${socket.nick} whispered: ${text}`,
}, targetClient);
targetClient.whisperReply = socket.nick;
@@ -68,42 +70,44 @@ exports.run = async (core, server, socket, payload) => {
server.reply({
cmd: 'info',
type: 'whisper',
- text: `You whispered to @${targetNick}: ${text}`
+ text: `You whispered to @${targetNick}: ${text}`,
}, socket);
-};
+
+ return true;
+}
// module hook functions
-exports.initHooks = (server) => {
+export function initHooks(server) {
server.registerHook('in', 'chat', this.whisperCheck, 20);
-};
+}
// hooks chat commands checking for /whisper
-exports.whisperCheck = (core, server, socket, payload) => {
+export function whisperCheck(core, server, socket, payload) {
if (typeof payload.text !== 'string') {
return false;
}
if (payload.text.startsWith('/whisper')) {
- let input = payload.text.split(' ');
+ const input = payload.text.split(' ');
// If there is no nickname target parameter
if (input[1] === undefined) {
server.reply({
cmd: 'warn',
- text: 'Refer to `/help whisper` for instructions on how to use this command.'
+ text: 'Refer to `/help whisper` for instructions on how to use this command.',
}, socket);
return false;
}
- let target = input[1].replace(/@/g, '');
+ const target = input[1].replace(/@/g, '');
input.splice(0, 2);
- let whisperText = input.join(' ');
+ const whisperText = input.join(' ');
this.run(core, server, socket, {
cmd: 'whisper',
nick: target,
- text: whisperText
+ text: whisperText,
});
return false;
@@ -113,35 +117,34 @@ exports.whisperCheck = (core, server, socket, payload) => {
if (typeof socket.whisperReply === 'undefined') {
server.reply({
cmd: 'warn',
- text: 'Cannot reply to nobody'
+ text: 'Cannot reply to nobody',
}, socket);
return false;
}
- let input = payload.text.split(' ');
+ const input = payload.text.split(' ');
input.splice(0, 1);
- let whisperText = input.join(' ');
+ const whisperText = input.join(' ');
this.run(core, server, socket, {
cmd: 'whisper',
nick: socket.whisperReply,
- text: whisperText
+ text: whisperText,
});
return false;
}
return payload;
-};
+}
-// module meta
-exports.requiredData = ['nick', 'text'];
-exports.info = {
+export const requiredData = ['nick', 'text'];
+export const info = {
name: 'whisper',
description: 'Display text on targets screen that only they can see',
usage: `
API: { cmd: 'whisper', nick: '<target name>', text: '<text to whisper>' }
Text: /whisper <target name> <text to whisper>
- Alt Text: /r <text to whisper, this will auto reply to the last person who whispered to you>`
+ Alt Text: /r <text to whisper, this will auto reply to the last person who whispered to you>`,
};