updated enums and logic for member helper

This commit is contained in:
Aster Fialla
2026-02-13 22:18:43 -05:00
parent 1d1f62af31
commit 0829c7c5fc
2 changed files with 25 additions and 19 deletions

View File

@@ -1,7 +1,7 @@
const helperEnums = {};
helperEnums.err = {
NO_MEMBER: "No member was found.",
NO_MEMBER: "No such member was found.",
NO_NAME_PROVIDED: "No member name was provided for",
NO_VALUE: "has not been set for this member. Please provide a value.",
ADD_ERROR: "Error adding member.",
@@ -9,16 +9,16 @@ helperEnums.err = {
USER_NO_MEMBERS: "You have no members created.",
DISPLAY_NAME_TOO_LONG: "The display name is too long. Please limit it to 32 characters or less.",
PROXY_EXISTS: "A duplicate proxy already exists for one of your members. Please pick a new one, or change the old one first.",
NO_SUCH_COMMAND: "No such command exists."
NO_SUCH_COMMAND: "No such command exists"
}
helperEnums.help = {
PLURALFLUX: "PluralFlux is a proxybot akin to PluralKit and Tupperbot, but for Fluxer. All commands are prefixed by `pf;`. The current commands are: `pf;member`. Add ` --help` to the end of a command to find out more about it, or just send it without arguments.",
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.\n\nThe current commands are: `pf;member` and `pf;help`.",
MEMBER: "You can shorten this command to `pf;m`. The available subcommands for `pf;member` are `add`, `remove`, `displayname`, and `proxy`. 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. \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. \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`.",
DISPLAYNAME: "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 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."
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 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."
}
export const enums = helperEnums;

View File

@@ -3,7 +3,8 @@ import {enums} from "../enums.js";
const mh = {};
const commandList = ['--help', 'add', 'remove', 'displayName', 'proxy'];
// Has an empty "command" to parse the help message properly
const commandList = ['--help', 'add', 'remove', 'displayName', 'proxy', ''];
/**
* Parses through the subcommands that come after "pf;member" and calls functions accordingly.
@@ -14,18 +15,23 @@ const commandList = ['--help', 'add', 'remove', 'displayName', 'proxy'];
*/
mh.parseMemberCommand = async function(authorId, args){
console.log(authorId, args);
let member;
// checks whether command is in list, otherwise assumes it's a name
if(!commandList.includes(args[0])) {
return enums.err.NO_SUCH_COMMAND;
member = await getMemberInfo(authorId, args[0]);
if (!member) {
return enums.err.NO_SUCH_COMMAND;
}
}
switch(args[0]) {
case '--help':
return enums.help.MEMBER;
case 'add':
return addNewMember(authorId, args);
return await addNewMember(authorId, args);
case 'remove':
return removeMember(authorId, args);
return await removeMember(authorId, args);
case 'displayname':
return enums.help.DISPLAYNAME;
return enums.help.DISPLAY_NAME;
case 'proxy':
return enums.help.PROXY;
case '':
@@ -35,13 +41,13 @@ mh.parseMemberCommand = async function(authorId, args){
case '--help':
return enums.help.MEMBER;
case 'displayname':
return updateDisplayName(authorId, args);
return await updateDisplayName(authorId, args);
case 'proxy':
return updateProxy(authorId, args);
return await updateProxy(authorId, args);
// case 'avatar':
// return await set_avatar(authorId, args)
default:
return getMemberInfo(authorId, args[1]);
return member;
}
}
@@ -59,8 +65,8 @@ async function addNewMember(authorId, args) {
const memberName = args[1];
const displayName = args[2];
const member = getMemberInfo(authorId, memberName);
if (member !== enums.err.NO_MEMBER) {
const member = await getMemberInfo(authorId, memberName);
if (member && member !== enums.err.NO_MEMBER) {
return enums.err.MEMBER_EXISTS;
}
const trimmedName = displayName ? displayName.replaceAll(' ', '') : null;
@@ -86,7 +92,7 @@ async function addNewMember(authorId, args) {
*/
async function updateDisplayName(authorId, args) {
if (args[1] && args[1] === "--help" || !args[1]) {
return enums.help.DISPLAYNAME;
return enums.help.DISPLAY_NAME;
}
const memberName = args[0];
@@ -94,9 +100,9 @@ async function updateDisplayName(authorId, args) {
const trimmed_name = displayName ? displayName.replaceAll(' ', '') : null;
if (!displayName || trimmed_name === null ) {
let member = mh.getMemberByName(authorId, memberName);
let member = await mh.getMemberByName(authorId, memberName);
if (member.displayname) {
return `Display name for ${memberName} is: ${member.displayname}.`;
return `Display name for ${memberName} is: \"${member.displayname}\".`;
}
return `Display name ${enums.err.NO_VALUE}`
}