diff --git a/enums.js b/enums.js index ccbfa09..0345793 100644 --- a/enums.js +++ b/enums.js @@ -23,8 +23,9 @@ helperEnums.help = { SHORT_DESC_PLURALFLUX: "PluralFlux is a proxybot akin to PluralKit and Tupperbot, but for Fluxer. All commands are prefixed by `pf;`. Type `pf;help` for info on the bot itself.", PLURALFLUX: "PluralFlux is a proxybot akin to PluralKit and Tupperbot, but for Fluxer. All commands are prefixed by `pf;`. Add ` --help` to the end of a command to find out more about it, or just send it without arguments.", MEMBER: "Accesses the sub-commands related to editing proxy members. The available subcommands are `add`, `remove`, `displayname`, `proxy`, and `propic`. Add ` --help` to the end of a subcommand to find out more about it, or just send it without arguments.", - ADD: "Creates a new member to proxy with, for example: `pf;member jane`. The member name should ideally be short so you can write other commands with it. \n\nYou can optionally add a display name after the member name, for example: `pf;member new jane \"Jane Doe | ze/hir\"`. If it has spaces, put it in __double quotes__. The length limit is 32 characters.", + ADD: "Creates a new member to proxy with, for example: `pf;member jane`. The member name should ideally be short so you can write other commands with it easily. \n\nYou can optionally add a display name after the member name, for example: `pf;member new jane \"Jane Doe | ze/hir\"`. If it has spaces, put it in __double quotes__. The length limit is 32 characters.", REMOVE: "Removes a member based on their name, for example: `pf;member remove jane`.", + NAME: "Updates the name for a specific member based on their current name, for ex: `pf;member jane name jane`. The member name should ideally be short so you can write other commands with it easily.", DISPLAY_NAME: "Updates the display name for a specific member based on their name, for example: `pf;member jane \"Jane Doe | ze/hir\"`.This can be up to 32 characters long. If it has spaces, put it in __double quotes__.", PROXY: "Updates the proxy tag for a specific member based on their name, for example: `pf;member jane proxy Jane:` or `pf;member amal proxy A=`. This is put at *the start* of a message to allow it to be proxied. Proxies that wrap around text or go at the end are *not* currently supported.", PROPIC: "Updates the profile picture for the member. Must be in JPG or PNG format. The two options are:\n1. Pass in a direct remote image URL, for example: `pf;member jane propic `. You can upload images on sites like .\n2. Upload an attachment directly.\n\n**NOTE:** Fluxer does not save your attachments forever, so option #1 is recommended.", diff --git a/helpers/memberHelper.js b/helpers/memberHelper.js index 7ea9b48..cb66ee4 100644 --- a/helpers/memberHelper.js +++ b/helpers/memberHelper.js @@ -6,7 +6,7 @@ import {EmptyResultError} from "sequelize"; const mh = {}; // Has an empty "command" to parse the help message properly -const commandList = ['--help', 'add', 'remove', 'displayName', 'proxy', 'propic', '']; +const commandList = ['--help', 'add', 'remove', 'name', 'displayName', 'proxy', 'propic', '']; /** * Parses through the subcommands that come after "pf;member" and calls functions accordingly. @@ -30,6 +30,8 @@ mh.parseMemberCommand = async function(authorId, args, attachmentUrl){ return await addNewMember(authorId, args); case 'remove': return await removeMember(authorId, args); + case 'name': + return enums.help.NAME; case 'displayname': return enums.help.DISPLAY_NAME; case 'proxy': @@ -42,6 +44,8 @@ mh.parseMemberCommand = async function(authorId, args, attachmentUrl){ switch(args[1]) { case '--help': return enums.help.MEMBER; + case 'name': + return await updateName(authorId, args); case 'displayname': return await updateDisplayName(authorId, args); case 'proxy': @@ -68,7 +72,6 @@ async function addNewMember(authorId, args) { const memberName = args[1]; const displayName = args[2]; - const member = await getMemberInfo(authorId, memberName); const trimmedName = displayName ? displayName.replaceAll(' ', '') : null; return await db.members.create({ name: memberName, @@ -83,6 +86,27 @@ async function addNewMember(authorId, args) { }) } +/** + * Updates the name for a member. + * + * @param {string} authorId - The author of the message + * @param {string[]} args - The message arguments + * @returns {Promise} A successful update. + * @throws {RangeError} When the name doesn't exist. + */ +async function updateName(authorId, args) { + if (args[1] && args[1] === "--help" || !args[1]) { + return enums.help.DISPLAY_NAME; + } + + const name = args[2]; + const trimmed_name = name ? name.replaceAll(' ', '') : null; + if (!name || trimmed_name === null) { + throw new RangeError(`Display name ${enums.err.NO_VALUE}`); + } + return updateMember(authorId, args); +} + /** * Updates the display name for a member. *