mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-16 17:45:28 +10:00
moved enums to enums file
This commit is contained in:
22
enums.js
Normal file
22
enums.js
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
const helperEnums = {};
|
||||||
|
|
||||||
|
helperEnums.err = {
|
||||||
|
NO_MEMBER: "No 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.",
|
||||||
|
MEMBER_EXISTS: "A member with that name already exists. Please pick a unique name.",
|
||||||
|
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."
|
||||||
|
}
|
||||||
|
|
||||||
|
helperEnums.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: `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: `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. `pf;member remove jane`.",
|
||||||
|
DISPLAYNAME: "Updates the display name for a specific member based on their name. `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. `pf;member jane proxy Jane:`. 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;
|
||||||
@@ -2,33 +2,14 @@ import { db } from '../sequelize.js';
|
|||||||
|
|
||||||
const mh = {};
|
const mh = {};
|
||||||
|
|
||||||
const errorEnums = {
|
|
||||||
NO_MEMBER: "No 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.",
|
|
||||||
MEMBER_EXISTS: "A member with that name already exists. Please pick a unique name.",
|
|
||||||
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."
|
|
||||||
}
|
|
||||||
|
|
||||||
const helpEnums = {
|
|
||||||
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: `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: `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. `pf;member remove jane`.",
|
|
||||||
DISPLAYNAME: "Updates the display name for a specific member based on their name. `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. `pf;member jane proxy Jane:`. 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."
|
|
||||||
}
|
|
||||||
|
|
||||||
mh.parseMemberCommand = async function(authorId, args){
|
mh.parseMemberCommand = async function(authorId, args){
|
||||||
console.log(authorId, args);
|
console.log(authorId, args);
|
||||||
if (!args) {
|
if (!args) {
|
||||||
return helpEnums.MEMBER;
|
return enums.help.MEMBER;
|
||||||
}
|
}
|
||||||
switch(args[0]) {
|
switch(args[0]) {
|
||||||
case '--help':
|
case '--help':
|
||||||
return helpEnums.MEMBER;
|
return enums.help.MEMBER;
|
||||||
case 'add':
|
case 'add':
|
||||||
return await addNewMember(authorId, args);
|
return await addNewMember(authorId, args);
|
||||||
case 'remove':
|
case 'remove':
|
||||||
@@ -36,7 +17,7 @@ mh.parseMemberCommand = async function(authorId, args){
|
|||||||
}
|
}
|
||||||
switch(args[1]) {
|
switch(args[1]) {
|
||||||
case '--help':
|
case '--help':
|
||||||
return helpEnums.MEMBER;
|
return enums.help.MEMBER;
|
||||||
case 'displayname':
|
case 'displayname':
|
||||||
return await updateDisplayName(authorId, args);
|
return await updateDisplayName(authorId, args);
|
||||||
case 'proxy':
|
case 'proxy':
|
||||||
@@ -50,7 +31,7 @@ mh.parseMemberCommand = async function(authorId, args){
|
|||||||
|
|
||||||
async function addNewMember(authorId, args) {
|
async function addNewMember(authorId, args) {
|
||||||
if (args[1] && args[1] === "--help" || !args[1]) {
|
if (args[1] && args[1] === "--help" || !args[1]) {
|
||||||
return helpEnums.ADD;
|
return enums.help.ADD;
|
||||||
}
|
}
|
||||||
const memberName = args[1];
|
const memberName = args[1];
|
||||||
const displayName = args[2];
|
const displayName = args[2];
|
||||||
@@ -58,6 +39,8 @@ async function addNewMember(authorId, args) {
|
|||||||
const member = await getMemberInfo(authorId, memberName);
|
const member = await getMemberInfo(authorId, memberName);
|
||||||
if (member !== errorEnums.NO_MEMBER) {
|
if (member !== errorEnums.NO_MEMBER) {
|
||||||
return errorEnums.MEMBER_EXISTS;
|
return errorEnums.MEMBER_EXISTS;
|
||||||
|
if (member !== enums.err.NO_MEMBER) {
|
||||||
|
return enums.err.MEMBER_EXISTS;
|
||||||
}
|
}
|
||||||
const trimmedName = displayName ? displayName.replaceAll(' ', '') : null;
|
const trimmedName = displayName ? displayName.replaceAll(' ', '') : null;
|
||||||
return await db.members.create({
|
return await db.members.create({
|
||||||
@@ -69,13 +52,13 @@ async function addNewMember(authorId, args) {
|
|||||||
success += displayName ? `\nDisplay name: ${m.dataValues.displayname}` : "";
|
success += displayName ? `\nDisplay name: ${m.dataValues.displayname}` : "";
|
||||||
return success;
|
return success;
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
return `${errorEnums.ADD_ERROR}: ${e.message}`;
|
return `${enums.err.ADD_ERROR}: ${e.message}`;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
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 helpEnums.DISPLAYNAME;
|
return enums.help.DISPLAYNAME;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberName = args[0];
|
const memberName = args[0];
|
||||||
@@ -87,10 +70,11 @@ async function updateDisplayName(authorId, args) {
|
|||||||
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 ${errorEnums.NO_VALUE}`
|
return `Display name ${enums.err.NO_VALUE}`
|
||||||
}
|
}
|
||||||
else if (displayName.count > 32) {
|
else if (displayName.count > 32) {
|
||||||
return errorEnums.DISPLAY_NAME_TOO_LONG;
|
return errorEnums.DISPLAY_NAME_TOO_LONG;
|
||||||
|
return enums.err.DISPLAY_NAME_TOO_LONG;
|
||||||
}
|
}
|
||||||
console.log(displayName);
|
console.log(displayName);
|
||||||
return await updateMember(authorId, args);
|
return await updateMember(authorId, args);
|
||||||
@@ -98,7 +82,7 @@ async function updateDisplayName(authorId, args) {
|
|||||||
|
|
||||||
async function updateProxy(authorId, args) {
|
async function updateProxy(authorId, args) {
|
||||||
if (args[1] && args[1] === "--help" || !args[1]) {
|
if (args[1] && args[1] === "--help" || !args[1]) {
|
||||||
return helpEnums.PROXY;
|
return enums.help.PROXY;
|
||||||
}
|
}
|
||||||
const proxy = args[2];
|
const proxy = args[2];
|
||||||
const trimmedProxy = proxy ? proxy.replaceAll(' ', '') : null;
|
const trimmedProxy = proxy ? proxy.replaceAll(' ', '') : null;
|
||||||
@@ -110,24 +94,24 @@ async function updateProxy(authorId, args) {
|
|||||||
const members = await mh.getMembersByAuthor(authorId);
|
const members = await mh.getMembersByAuthor(authorId);
|
||||||
const proxyExists = members.some(member => member.proxy === proxy);
|
const proxyExists = members.some(member => member.proxy === proxy);
|
||||||
if (proxyExists) {
|
if (proxyExists) {
|
||||||
return errorEnums.PROXY_EXISTS;
|
return enums.err.PROXY_EXISTS;
|
||||||
}
|
}
|
||||||
return await updateMember(authorId, args);
|
return await updateMember(authorId, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
async function removeMember(authorId, args) {
|
async function removeMember(authorId, args) {
|
||||||
if (args[1] && args[1] === "--help") {
|
if (args[1] && args[1] === "--help") {
|
||||||
return helpEnums.REMOVE;
|
return enums.help.REMOVE;
|
||||||
}
|
}
|
||||||
|
|
||||||
const memberName = args[1];
|
const memberName = args[1];
|
||||||
if (!memberName) {
|
if (!memberName) {
|
||||||
return `${errorEnums.NO_NAME_PROVIDED} deletion.`;
|
return `${enums.err.NO_NAME_PROVIDED} deletion.`;
|
||||||
}
|
}
|
||||||
return await db.members.destroy({ where: { name: memberName, userid: authorId } }).then(() => {
|
return await db.members.destroy({ where: { name: memberName, userid: authorId } }).then(() => {
|
||||||
return `${memberName} has been deleted.`;
|
return `${memberName} has been deleted.`;
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
return `${errorEnums.NO_MEMBER}: ${e.message}`;
|
return `${enums.err.NO_MEMBER}: ${e.message}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +123,7 @@ async function updateMember(authorId, args) {
|
|||||||
return await db.members.update({[columnName]: value}, { where: { name: memberName, userid: authorId } }).then(() => {
|
return await db.members.update({[columnName]: value}, { where: { name: memberName, userid: authorId } }).then(() => {
|
||||||
return `Updated ${columnName} for ${memberName} to ${value}`;
|
return `Updated ${columnName} for ${memberName} to ${value}`;
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
return `${errorEnums.NO_MEMBER}: ${e.message}`;
|
return `${enums.err.NO_MEMBER}: ${e.message}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,19 +136,19 @@ async function getMemberInfo(authorId, memberName) {
|
|||||||
member_info += member.propic ? `\nProfile pic: ${member.propic}` : '\nProfile pic: unset';
|
member_info += member.propic ? `\nProfile pic: ${member.propic}` : '\nProfile pic: unset';
|
||||||
return member_info;
|
return member_info;
|
||||||
}
|
}
|
||||||
return errorEnums.NO_MEMBER;
|
return enums.err.NO_MEMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
mh.getMemberByProxy = async function(authorId, proxy) {
|
mh.getMemberByProxy = async function(authorId, proxy) {
|
||||||
return await db.members.findOne({ where: { userid: authorId, proxy: proxy } }).catch(e => {
|
return await db.members.findOne({ where: { userid: authorId, proxy: proxy } }).catch(e => {
|
||||||
return `${errorEnums.NO_MEMBER}: ${e.message}`;
|
return `${enums.err.NO_MEMBER}: ${e.message}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
mh.getMembersByAuthor = async function(authorId) {
|
mh.getMembersByAuthor = async function(authorId) {
|
||||||
return await db.members.findAll({ where: { userid: authorId } }).catch(e => {
|
return await db.members.findAll({ where: { userid: authorId } }).catch(e => {
|
||||||
// I have no idea how this could possibly happen but better safe than sorry
|
// I have no idea how this could possibly happen but better safe than sorry
|
||||||
return `${errorEnums.USER_NO_MEMBERS}: ${e.message}`;
|
return `${enums.err.USER_NO_MEMBERS}: ${e.message}`;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user