mirror of
https://github.com/pieartsy/PluralFlux.git
synced 2026-04-16 17:45:28 +10:00
docstrings and more error description.
This commit is contained in:
@@ -62,7 +62,7 @@ mh.parseMemberCommand = async function(author, args, attachmentUrl){
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a member, first checking that there is no member of that name associated with the author.
|
* Adds a member.
|
||||||
*
|
*
|
||||||
* @param {string} authorId - The author of the message
|
* @param {string} authorId - The author of the message
|
||||||
* @param {string[]} args - The message arguments
|
* @param {string[]} args - The message arguments
|
||||||
@@ -232,20 +232,31 @@ async function removeMember(authorId, args) {
|
|||||||
|
|
||||||
/*======Non-Subcommands======*/
|
/*======Non-Subcommands======*/
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds a member with full details, first checking that there is no member of that name associated with the author.
|
||||||
|
*
|
||||||
|
* @param {string} authorId - The author of the message
|
||||||
|
* @param {string} memberName - The name of the member.
|
||||||
|
* @param {string} displayName - The display name of the member.
|
||||||
|
* @param {string} proxy - The proxy tag of the member.
|
||||||
|
* @param {string} propic - The profile picture URL of the member.
|
||||||
|
* @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.
|
||||||
|
*/
|
||||||
mh.addFullMember = async function(authorId, memberName, displayName, proxy, propic) {
|
mh.addFullMember = async function(authorId, memberName, displayName, proxy, propic) {
|
||||||
const member = await mh.getMemberByName(authorId, memberName);
|
const member = await mh.getMemberByName(authorId, memberName);
|
||||||
if (member) {
|
if (member) {
|
||||||
throw new Error(enums.err.MEMBER_EXISTS);
|
throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
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(enums.err.DISPLAY_NAME_TOO_LONG);
|
throw new RangeError(`Can't add ${memberName}. ${enums.err.DISPLAY_NAME_TOO_LONG}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (propic) {
|
if (propic) {
|
||||||
await loadImage(propic).catch((err) => {
|
await loadImage(propic).catch((err) => {
|
||||||
throw new Error(`${enums.err.PROPIC_CANNOT_LOAD}: ${err.message}`);
|
throw new Error(`Can't add ${memberName}. ${enums.err.PROPIC_CANNOT_LOAD}: ${err.message}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +267,7 @@ mh.addFullMember = async function(authorId, memberName, displayName, proxy, prop
|
|||||||
proxy: proxy,
|
proxy: proxy,
|
||||||
propic: propic,
|
propic: propic,
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
throw new Error(`${enums.err.ADD_ERROR}: ${e.message}`)
|
throw new Error(`Can't add ${memberName}. ${enums.err.ADD_ERROR}: ${e.message}`)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -283,10 +294,10 @@ async function updateMemberField(authorId, args) {
|
|||||||
return `Updated ${columnName} for ${memberName} to "${value}"${fluxerPropicWarning ?? ''}.`;
|
return `Updated ${columnName} for ${memberName} to "${value}"${fluxerPropicWarning ?? ''}.`;
|
||||||
}).catch(e => {
|
}).catch(e => {
|
||||||
if (e === EmptyResultError) {
|
if (e === EmptyResultError) {
|
||||||
throw new EmptyResultError(`${enums.err.NO_MEMBER}: ${e.message}`);
|
throw new EmptyResultError(`Can't update ${memberName}. ${enums.err.NO_MEMBER}: ${e.message}`);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new Error(e.message);
|
throw new Error(`Can't update ${memberName}. ${e.message}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -349,13 +360,13 @@ async function getAllMembersInfo(authorId, authorName) {
|
|||||||
* Gets a member based on the author and proxy tag.
|
* Gets a member based on the author and proxy tag.
|
||||||
*
|
*
|
||||||
* @param {string} authorId - The author of the message.
|
* @param {string} authorId - The author of the message.
|
||||||
* @param {string} name - The member's name.
|
* @param {string} memberName - The member's name.
|
||||||
* @returns {Promise<model>} The member object.
|
* @returns {Promise<model>} The member object.
|
||||||
* @throws { EmptyResultError } When the member is not found.
|
* @throws { EmptyResultError } When the member is not found.
|
||||||
*/
|
*/
|
||||||
mh.getMemberByName = async function(authorId, name) {
|
mh.getMemberByName = async function(authorId, memberName) {
|
||||||
return await db.members.findOne({ where: { userid: authorId, name: name } }).catch(e => {
|
return await db.members.findOne({ where: { userid: authorId, name: memberName } }).catch(e => {
|
||||||
throw new EmptyResultError(`${enums.err.NO_MEMBER}: ${e.message}`);
|
throw new EmptyResultError(`Can't get ${memberName}. ${enums.err.NO_MEMBER}: ${e.message}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -369,7 +380,7 @@ mh.getMemberByName = async function(authorId, name) {
|
|||||||
*/
|
*/
|
||||||
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 => {
|
||||||
throw new EmptyResultError(`${enums.err.NO_MEMBER}: ${e.message}`);
|
throw new EmptyResultError(`Can't add ${memberName}. ${enums.err.NO_MEMBER}: ${e.message}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user