forked from PluralFlux/PluralFlux
adjusting member helper logic
This commit is contained in:
@@ -177,12 +177,11 @@ mh.checkIfProxyExists = async function(authorId, proxy) {
|
|||||||
if(splitProxy.length < 2) throw new Error(enums.err.NO_TEXT_FOR_PROXY);
|
if(splitProxy.length < 2) throw new Error(enums.err.NO_TEXT_FOR_PROXY);
|
||||||
if(!splitProxy[0] && !splitProxy[1]) throw new Error(enums.err.NO_PROXY_WRAPPER);
|
if(!splitProxy[0] && !splitProxy[1]) throw new Error(enums.err.NO_PROXY_WRAPPER);
|
||||||
|
|
||||||
const members = await mh.getMembersByAuthor(authorId).then(() => {
|
await mh.getMembersByAuthor(authorId).then((memberList) => {
|
||||||
const proxyExists = members.some(member => member.proxy === proxy);
|
const proxyExists = memberList.some(member => member.proxy === proxy);
|
||||||
if (proxyExists) {
|
if (proxyExists) {
|
||||||
throw new Error(enums.err.PROXY_EXISTS);
|
throw new Error(enums.err.PROXY_EXISTS);
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}).catch(e =>{throw e});
|
}).catch(e =>{throw e});
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -252,23 +251,26 @@ mh.removeMember = async function(authorId, args) {
|
|||||||
* @async
|
* @async
|
||||||
* @param {string} authorId - The author of the message
|
* @param {string} authorId - The author of the message
|
||||||
* @param {string} memberName - The name of the member.
|
* @param {string} memberName - The name of the member.
|
||||||
* @param {string} displayName - The display name of the member.
|
* @param {string | null} displayName - The display name of the member.
|
||||||
* @param {string | null} proxy - The proxy tag of the member.
|
* @param {string | null} proxy - The proxy tag of the member.
|
||||||
* @param {string | null} propic - The profile picture URL of the member.
|
* @param {string | null} propic - The profile picture URL of the member.
|
||||||
* @returns {Promise<string>} A successful addition.
|
* @returns {Promise<string>} A successful addition.
|
||||||
* @throws {Error | RangeError} When the member already exists, there are validation errors, or adding a member doesn't work.
|
* @throws {Error | RangeError} When the member already exists, there are validation errors, or adding a member doesn't work.
|
||||||
*/
|
*/
|
||||||
mh.addFullMember = async function(authorId, memberName, displayName, proxy = null, propic= null) {
|
mh.addFullMember = async function(authorId, memberName, displayName = null, proxy = null, propic= null) {
|
||||||
const member = await mh.getMemberByName(authorId, memberName);
|
const member = await mh.getMemberByName(authorId, memberName).catch((e) =>{throw e});
|
||||||
if (member) {
|
if (member) {
|
||||||
throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`);
|
throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`);
|
||||||
}
|
}
|
||||||
|
if (displayName) {
|
||||||
const trimmedName = displayName ? displayName.trim() : null;
|
const trimmedName = displayName ? displayName.trim() : null;
|
||||||
if (trimmedName && trimmedName.length > 32) {
|
if (trimmedName && trimmedName.length > 32) {
|
||||||
throw new RangeError(`Can't add ${memberName}. ${enums.err.DISPLAY_NAME_TOO_LONG}`);
|
throw new RangeError(`Can't add ${memberName}. ${enums.err.DISPLAY_NAME_TOO_LONG}`);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (proxy) {
|
||||||
|
await mh.checkIfProxyExists(authorId, proxy).catch((e) =>{throw e});
|
||||||
|
}
|
||||||
if (propic) {
|
if (propic) {
|
||||||
await loadImage(propic).catch((err) => {
|
await loadImage(propic).catch((err) => {
|
||||||
throw new Error(`Can't add ${memberName}. ${enums.err.PROPIC_CANNOT_LOAD}: ${err.message}`);
|
throw new Error(`Can't add ${memberName}. ${enums.err.PROPIC_CANNOT_LOAD}: ${err.message}`);
|
||||||
@@ -365,9 +367,9 @@ mh.getMemberInfo = async function(authorId, memberName) {
|
|||||||
*/
|
*/
|
||||||
mh.getAllMembersInfo = async function(authorId, authorName) {
|
mh.getAllMembersInfo = async function(authorId, authorName) {
|
||||||
const members = await mh.getMembersByAuthor(authorId).catch(e =>{throw e});
|
const members = await mh.getMembersByAuthor(authorId).catch(e =>{throw e});
|
||||||
const fields = [...members.entries()].map(([member]) => ({
|
const fields = [...members.entries()].map(([name, member]) => ({
|
||||||
name: member.name,
|
name: member.name,
|
||||||
value: `(Proxy: \`${member.proxy}\`)`,
|
value: `(Proxy: \`${member.proxy ?? "unset"}\`)`,
|
||||||
inline: true,
|
inline: true,
|
||||||
}));
|
}));
|
||||||
return new EmbedBuilder()
|
return new EmbedBuilder()
|
||||||
|
|||||||
Reference in New Issue
Block a user