mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-16 17:45:28 +10:00
added update proxy method and documentation
This commit is contained in:
@@ -5,10 +5,19 @@ const mh = {};
|
|||||||
const errorEnums = {
|
const errorEnums = {
|
||||||
NO_MEMBER: "No member was found.",
|
NO_MEMBER: "No 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.",
|
NO_VALUE: "has not been set for this member. Please provide a value.",
|
||||||
ADD_ERROR: "Error adding member.",
|
ADD_ERROR: "Error adding member.",
|
||||||
MEMBER_EXISTS: "A member with that name already exists.",
|
MEMBER_EXISTS: "A member with that name already exists. Please pick a unique name.",
|
||||||
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.",
|
||||||
|
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 = {
|
||||||
|
NEW: "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.parse_member_command = async function(author_id, args){
|
mh.parse_member_command = async function(author_id, args){
|
||||||
@@ -19,14 +28,16 @@ mh.parse_member_command = async function(author_id, args){
|
|||||||
switch(args[0]) {
|
switch(args[0]) {
|
||||||
case 'new':
|
case 'new':
|
||||||
return await add_new_member(author_id, args);
|
return await add_new_member(author_id, args);
|
||||||
case 'delete':
|
case 'remove':
|
||||||
return await delete_member(author_id, args);
|
return await remove_member(author_id, args);
|
||||||
}
|
}
|
||||||
switch(args[1]) {
|
switch(args[1]) {
|
||||||
|
case '--help':
|
||||||
|
return
|
||||||
case 'displayname':
|
case 'displayname':
|
||||||
return await set_display_name(author_id, args);
|
return await update_display_name(author_id, args);
|
||||||
// case 'proxy':
|
case 'proxy':
|
||||||
// return await set_proxy(author_id, args);
|
return await update_proxy(author_id, args);
|
||||||
// case 'avatar':
|
// case 'avatar':
|
||||||
// return await set_avatar(author_id, args)
|
// return await set_avatar(author_id, args)
|
||||||
default:
|
default:
|
||||||
@@ -37,8 +48,6 @@ mh.parse_member_command = async function(author_id, args){
|
|||||||
async function add_new_member(author_id, args) {
|
async function add_new_member(author_id, args) {
|
||||||
const member_name = args[1];
|
const member_name = args[1];
|
||||||
const display_name = args[2];
|
const display_name = args[2];
|
||||||
const proxy = args[3];
|
|
||||||
const propic = args[4];
|
|
||||||
if (!member_name) {
|
if (!member_name) {
|
||||||
return `${errorEnums.NO_NAME_PROVIDED} adding.`;
|
return `${errorEnums.NO_NAME_PROVIDED} adding.`;
|
||||||
}
|
}
|
||||||
@@ -47,18 +56,13 @@ async function add_new_member(author_id, args) {
|
|||||||
return errorEnums.MEMBER_EXISTS;
|
return errorEnums.MEMBER_EXISTS;
|
||||||
}
|
}
|
||||||
const trimmed_name = display_name ? display_name.replaceAll(' ', '') : null;
|
const trimmed_name = display_name ? display_name.replaceAll(' ', '') : null;
|
||||||
const trimmed_proxy = proxy ? proxy.trim() : null;
|
|
||||||
return await db.members.create({
|
return await db.members.create({
|
||||||
name: member_name,
|
name: member_name,
|
||||||
userid: author_id,
|
userid: author_id,
|
||||||
displayname: trimmed_name !== null ? display_name : null,
|
displayname: trimmed_name !== null ? display_name : null,
|
||||||
proxy: trimmed_proxy,
|
|
||||||
propic: propic
|
|
||||||
}).then((m) => {
|
}).then((m) => {
|
||||||
let success = `Member was successfully added.\nName: ${m.dataValues.name}`
|
let success = `Member was successfully added.\nName: ${m.dataValues.name}`
|
||||||
success += display_name ? `\nDisplay name: ${m.dataValues.displayname}` : "";
|
success += display_name ? `\nDisplay name: ${m.dataValues.displayname}` : "";
|
||||||
success += proxy ? `\nProxy tag: ${m.dataValues.proxy} `: "";
|
|
||||||
success += propic ? `\nProfile picture: ${m.dataValues.proxy} `: "";
|
|
||||||
return success;
|
return success;
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
return `${errorEnums.ADD_ERROR}: ${e.message}`;
|
return `${errorEnums.ADD_ERROR}: ${e.message}`;
|
||||||
@@ -77,7 +81,7 @@ async function get_member_info(author_id, member_name) {
|
|||||||
return errorEnums.NO_MEMBER;
|
return errorEnums.NO_MEMBER;
|
||||||
}
|
}
|
||||||
|
|
||||||
async function set_display_name(author_id, args) {
|
async function update_display_name(author_id, args) {
|
||||||
const member_name = args[0];
|
const member_name = args[0];
|
||||||
const display_name = args[2];
|
const display_name = args[2];
|
||||||
const trimmed_name = display_name ? display_name.replaceAll(' ', '') : null;
|
const trimmed_name = display_name ? display_name.replaceAll(' ', '') : null;
|
||||||
@@ -93,10 +97,31 @@ async function set_display_name(author_id, args) {
|
|||||||
}
|
}
|
||||||
return `Display name ${errorEnums.NO_VALUE}`
|
return `Display name ${errorEnums.NO_VALUE}`
|
||||||
}
|
}
|
||||||
|
else if (display_name.count > 32) {
|
||||||
|
return errorEnums.DISPLAY_NAME_TOO_LONG;
|
||||||
|
}
|
||||||
console.log(display_name);
|
console.log(display_name);
|
||||||
return await update_member(author_id, args);
|
return await update_member(author_id, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function update_proxy(author_id, args) {
|
||||||
|
const proxy = args[2];
|
||||||
|
const trimmed_proxy = proxy ? proxy.replaceAll(' ', '') : null;
|
||||||
|
|
||||||
|
if (trimmed_proxy == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const members = mh.get_members_by_author(author_id);
|
||||||
|
members.forEach(member => {
|
||||||
|
if (member.proxy === proxy) {
|
||||||
|
return errorEnums.PROXY_EXISTS;
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
return await update_member(author_id, args);
|
||||||
|
}
|
||||||
|
|
||||||
async function update_member(author_id, args) {
|
async function update_member(author_id, args) {
|
||||||
const member_name = args[0];
|
const member_name = args[0];
|
||||||
const column_Name = args[1];
|
const column_Name = args[1];
|
||||||
@@ -108,7 +133,7 @@ async function update_member(author_id, args) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async function delete_member(author_id, args) {
|
async function remove_member(author_id, args) {
|
||||||
const member_name = args[1];
|
const member_name = args[1];
|
||||||
if (!member_name) {
|
if (!member_name) {
|
||||||
return `${errorEnums.NO_NAME_PROVIDED} deletion.`;
|
return `${errorEnums.NO_NAME_PROVIDED} deletion.`;
|
||||||
|
|||||||
Reference in New Issue
Block a user