forked from PluralFlux/PluralFlux
updated enums and logic for member helper
This commit is contained in:
12
enums.js
12
enums.js
@@ -1,7 +1,7 @@
|
|||||||
const helperEnums = {};
|
const helperEnums = {};
|
||||||
|
|
||||||
helperEnums.err = {
|
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_NAME_PROVIDED: "No member name was provided for",
|
||||||
NO_VALUE: "has not been set for this member. Please provide a value.",
|
NO_VALUE: "has not been set for this member. Please provide a value.",
|
||||||
ADD_ERROR: "Error adding member.",
|
ADD_ERROR: "Error adding member.",
|
||||||
@@ -9,16 +9,16 @@ helperEnums.err = {
|
|||||||
USER_NO_MEMBERS: "You have no members created.",
|
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.",
|
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.",
|
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 = {
|
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.",
|
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`.",
|
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.",
|
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."
|
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;
|
export const enums = helperEnums;
|
||||||
@@ -3,7 +3,8 @@ import {enums} from "../enums.js";
|
|||||||
|
|
||||||
const mh = {};
|
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.
|
* 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){
|
mh.parseMemberCommand = async function(authorId, args){
|
||||||
console.log(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])) {
|
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]) {
|
switch(args[0]) {
|
||||||
case '--help':
|
case '--help':
|
||||||
return enums.help.MEMBER;
|
return enums.help.MEMBER;
|
||||||
case 'add':
|
case 'add':
|
||||||
return addNewMember(authorId, args);
|
return await addNewMember(authorId, args);
|
||||||
case 'remove':
|
case 'remove':
|
||||||
return removeMember(authorId, args);
|
return await removeMember(authorId, args);
|
||||||
case 'displayname':
|
case 'displayname':
|
||||||
return enums.help.DISPLAYNAME;
|
return enums.help.DISPLAY_NAME;
|
||||||
case 'proxy':
|
case 'proxy':
|
||||||
return enums.help.PROXY;
|
return enums.help.PROXY;
|
||||||
case '':
|
case '':
|
||||||
@@ -35,13 +41,13 @@ mh.parseMemberCommand = async function(authorId, args){
|
|||||||
case '--help':
|
case '--help':
|
||||||
return enums.help.MEMBER;
|
return enums.help.MEMBER;
|
||||||
case 'displayname':
|
case 'displayname':
|
||||||
return updateDisplayName(authorId, args);
|
return await updateDisplayName(authorId, args);
|
||||||
case 'proxy':
|
case 'proxy':
|
||||||
return updateProxy(authorId, args);
|
return await updateProxy(authorId, args);
|
||||||
// case 'avatar':
|
// case 'avatar':
|
||||||
// return await set_avatar(authorId, args)
|
// return await set_avatar(authorId, args)
|
||||||
default:
|
default:
|
||||||
return getMemberInfo(authorId, args[1]);
|
return member;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +65,8 @@ async function addNewMember(authorId, args) {
|
|||||||
const memberName = args[1];
|
const memberName = args[1];
|
||||||
const displayName = args[2];
|
const displayName = args[2];
|
||||||
|
|
||||||
const member = getMemberInfo(authorId, memberName);
|
const member = await getMemberInfo(authorId, memberName);
|
||||||
if (member !== enums.err.NO_MEMBER) {
|
if (member && member !== enums.err.NO_MEMBER) {
|
||||||
return enums.err.MEMBER_EXISTS;
|
return enums.err.MEMBER_EXISTS;
|
||||||
}
|
}
|
||||||
const trimmedName = displayName ? displayName.replaceAll(' ', '') : null;
|
const trimmedName = displayName ? displayName.replaceAll(' ', '') : null;
|
||||||
@@ -86,7 +92,7 @@ async function addNewMember(authorId, args) {
|
|||||||
*/
|
*/
|
||||||
async function updateDisplayName(authorId, args) {
|
async function updateDisplayName(authorId, args) {
|
||||||
if (args[1] && args[1] === "--help" || !args[1]) {
|
if (args[1] && args[1] === "--help" || !args[1]) {
|
||||||
return enums.help.DISPLAYNAME;
|
return enums.help.DISPLAY_NAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberName = args[0];
|
const memberName = args[0];
|
||||||
@@ -94,9 +100,9 @@ async function updateDisplayName(authorId, args) {
|
|||||||
const trimmed_name = displayName ? displayName.replaceAll(' ', '') : null;
|
const trimmed_name = displayName ? displayName.replaceAll(' ', '') : null;
|
||||||
|
|
||||||
if (!displayName || trimmed_name === null ) {
|
if (!displayName || trimmed_name === null ) {
|
||||||
let member = mh.getMemberByName(authorId, memberName);
|
let member = await mh.getMemberByName(authorId, memberName);
|
||||||
if (member.displayname) {
|
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}`
|
return `Display name ${enums.err.NO_VALUE}`
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user