diff options
author | MinusGix <MinusGix@gmail.com> | 2020-03-06 21:41:09 +0100 |
---|---|---|
committer | MinusGix <MinusGix@gmail.com> | 2020-03-06 21:41:09 +0100 |
commit | eec99669c8b6d08bf4153a58aa72dabd5aacdae0 (patch) | |
tree | de2f05d19fdbe74bc7ac6469316a399a3cbb003f /server/src/commands/core | |
parent | Minor UAC tweaks (diff) | |
download | hackchat-eec99669c8b6d08bf4153a58aa72dabd5aacdae0.tar.gz hackchat-eec99669c8b6d08bf4153a58aa72dabd5aacdae0.zip |
Deduplicate verifyNickname into a single importable function
Diffstat (limited to 'server/src/commands/core')
-rw-r--r-- | server/src/commands/core/changenick.js | 5 | ||||
-rw-r--r-- | server/src/commands/core/invite.js | 5 | ||||
-rw-r--r-- | server/src/commands/core/join.js | 4 | ||||
-rw-r--r-- | server/src/commands/core/whisper.js | 5 |
4 files changed, 8 insertions, 11 deletions
diff --git a/server/src/commands/core/changenick.js b/server/src/commands/core/changenick.js index 6dbdfd2..6e9e59f 100644 --- a/server/src/commands/core/changenick.js +++ b/server/src/commands/core/changenick.js @@ -2,8 +2,7 @@ Description: Allows calling client to change their current nickname */ -// module support functions -const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick); +import * as UAC from "../utility/UAC/_info"; // module main export async function run(core, server, socket, data) { @@ -21,7 +20,7 @@ export async function run(core, server, socket, data) { // make sure requested nickname meets standards const newNick = data.nick.trim(); - if (!verifyNickname(newNick)) { + if (!UAC.verifyNickname(newNick)) { return server.reply({ cmd: 'warn', text: 'Nickname must consist of up to 24 letters, numbers, and underscores', diff --git a/server/src/commands/core/invite.js b/server/src/commands/core/invite.js index b594586..6d7c2af 100644 --- a/server/src/commands/core/invite.js +++ b/server/src/commands/core/invite.js @@ -2,8 +2,7 @@ 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); +import * as UAC from "../utility/UAC/_info"; // module main export async function run(core, server, socket, data) { @@ -16,7 +15,7 @@ export async function run(core, server, socket, data) { } // verify user input - if (typeof data.nick !== 'string' || !verifyNickname(data.nick)) { + if (typeof data.nick !== 'string' || !UAC.verifyNickname(data.nick)) { return true; } diff --git a/server/src/commands/core/join.js b/server/src/commands/core/join.js index 3a59a6d..7e98721 100644 --- a/server/src/commands/core/join.js +++ b/server/src/commands/core/join.js @@ -13,8 +13,6 @@ const hash = (password) => { return sha.digest('base64').substr(0, 6); }; -const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick); - // exposed "login" function to allow hooks to verify user join events // returns object containing user info or string if error export function parseNickname(core, data) { @@ -29,7 +27,7 @@ export function parseNickname(core, data) { const nickArray = data.nick.split('#', 2); userInfo.nick = nickArray[0].trim(); - if (!verifyNickname(userInfo.nick)) { + if (!UAC.verifyNickname(userInfo.nick)) { // return error as string return 'Nickname must consist of up to 24 letters, numbers, and underscores'; } diff --git a/server/src/commands/core/whisper.js b/server/src/commands/core/whisper.js index decf765..e574e1f 100644 --- a/server/src/commands/core/whisper.js +++ b/server/src/commands/core/whisper.js @@ -2,8 +2,9 @@ Description: Display text on targets screen that only they can see */ +import * as UAC from "../utility/UAC/_info"; + // module support functions -const verifyNickname = (nick) => /^[a-zA-Z0-9_]{1,24}$/.test(nick); const parseText = (text) => { // verifies user input is text @@ -41,7 +42,7 @@ export async function run(core, server, socket, payload) { } const targetNick = payload.nick; - if (!verifyNickname(targetNick)) { + if (!UAC.verifyNickname(targetNick)) { return true; } |