From c719020e17cb1c98da55be6cc7efe0e50ab51ffa Mon Sep 17 00:00:00 2001 From: marzavec Date: Sat, 29 Sep 2018 23:44:36 -0700 Subject: Added hooks, modules and cleaned up code --- server/src/commands/core/invite.js | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'server/src/commands/core/invite.js') diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js index d616193..f44779b 100644 --- a/server/src/commands/core/invite.js +++ b/server/src/commands/core/invite.js @@ -2,17 +2,17 @@ Description: Generates a semi-unique channel name then broadcasts it to each client */ +// module support functions const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick); +// module main exports.run = async (core, server, socket, data) => { // check for spam if (server._police.frisk(socket.remoteAddress, 2)) { - server.reply({ + return server.reply({ cmd: 'warn', text: 'You are sending invites too fast. Wait a moment before trying again.' }, socket); - - return; } // verify user input @@ -34,16 +34,15 @@ exports.run = async (core, server, socket, data) => { invite: channel, text: `${socket.nick} invited you to ?${channel}` }; + let inviteSent = server.broadcast( payload, { channel: socket.channel, nick: data.nick }); // server indicates the user was not found if (!inviteSent) { - server.reply({ + return server.reply({ cmd: 'warn', text: 'Could not find user in channel' }, socket); - - return; } // reply with common channel @@ -56,10 +55,11 @@ exports.run = async (core, server, socket, data) => { core.managers.stats.increment('invites-sent'); }; +// module meta exports.requiredData = ['nick']; - exports.info = { name: 'invite', - usage: 'invite {nick}', - description: 'Generates a unique (more or less) room name and passes it to two clients' + description: 'Generates a unique (more or less) room name and passes it to two clients', + usage: ` + API: { cmd: 'invite', nick: '' }` }; -- cgit v1.2.1