2026-02-17 22:23:47 -05:00
import { database } from '../database.js' ;
2026-02-17 17:25:18 -05:00
import { enums } from "../enums.js" ;
import { EmptyResultError , Op } from "sequelize" ;
import { EmbedBuilder } from "@fluxerjs/core" ;
const mh = { } ;
// Has an empty "command" to parse the help message properly
const commandList = [ '--help' , 'new' , 'remove' , 'name' , 'list' , 'displayName' , 'proxy' , 'propic' , '' ] ;
/ * *
* Parses through the subcommands that come after "pf;member" and calls functions accordingly .
*
* @ async
* @ param { string } authorId - The id of the message author
* @ param { string } authorFull - The username and discriminator of the message author
* @ param { string [ ] } args - The message arguments
* @ param { string | null } attachmentUrl - The message attachment url .
* @ param { string | null } attachmentExpiration - The message attachment expiration ( if uploaded via Fluxer )
2026-02-19 21:36:19 -05:00
* @ returns { Promise < string > } A success message .
* @ returns { Promise < EmbedBuilder > } A list of 25 members as an embed .
2026-02-20 11:00:21 -05:00
* @ returns { Promise < EmbedBuilder > } A list of member commands and descriptions .
* @ returns { Promise < { EmbedBuilder , [ string ] , string } > } A member info embed + info / errors .
2026-02-17 17:25:18 -05:00
* @ throws { Error }
* /
mh . parseMemberCommand = async function ( authorId , authorFull , args , attachmentUrl = null , attachmentExpiration = null ) {
2026-02-20 11:28:28 -05:00
const memberName = ! commandList . includes ( args [ 0 ] ) ? args [ 0 ] : args [ 1 ] ;
2026-02-17 17:25:18 -05:00
// checks whether command is in list, otherwise assumes it's a name
2026-02-20 11:28:28 -05:00
const member = await mh . getMemberByName ( authorId , memberName ) . then ( ( m ) => {
if ( ! m ) {
return enums . err . NO _MEMBER ;
}
} )
2026-02-17 17:25:18 -05:00
switch ( args [ 0 ] ) {
case 'new' :
2026-02-19 20:08:26 -05:00
return await mh . addNewMember ( authorId , args , attachmentUrl ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
case 'remove' :
return await mh . removeMember ( authorId , args ) . catch ( ( e ) => {
throw e
} ) ;
case 'name' :
return enums . help . NAME ;
case 'displayname' :
2026-02-13 22:18:43 -05:00
return enums . help . DISPLAY _NAME ;
2026-02-17 17:25:18 -05:00
case 'proxy' :
return enums . help . PROXY ;
case 'propic' :
return enums . help . PROPIC ;
case 'list' :
if ( args [ 1 ] && args [ 1 ] === "--help" ) {
return enums . help . LIST ;
}
return await mh . getAllMembersInfo ( authorId , authorFull ) . catch ( ( e ) => {
throw e
} ) ;
2026-02-20 11:28:28 -05:00
case '--help' :
2026-02-17 17:25:18 -05:00
case '' :
2026-02-20 11:28:28 -05:00
return mh . getMemberCommandInfo ( ) ;
2026-02-17 17:25:18 -05:00
}
switch ( args [ 1 ] ) {
case 'name' :
2026-02-20 11:28:28 -05:00
if ( ! args [ 2 ] ) return member . name ? ? ` Name ${ enums . err . NO _VALUE } ` ;
return await mh . updateName ( authorId , args [ 1 ] , args [ 2 ] ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
case 'displayname' :
2026-02-20 11:00:21 -05:00
if ( ! args [ 2 ] ) return member . displayname ? ? ` Display name ${ enums . err . NO _VALUE } ` ;
2026-02-20 11:28:28 -05:00
return await mh . updateDisplayName ( authorId , args [ 1 ] , args [ 2 ] ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
case 'proxy' :
2026-02-20 11:00:21 -05:00
if ( ! args [ 2 ] ) return member . proxy ? ? ` Proxy ${ enums . err . NO _VALUE } ` ;
2026-02-20 11:28:28 -05:00
return await mh . updateProxy ( authorId , args [ 1 ] , args [ 2 ] ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
case 'propic' :
2026-02-20 11:00:21 -05:00
if ( ! args [ 2 ] ) return member . propic ? ? ` Profile picture ${ enums . err . NO _VALUE } ` ;
2026-02-20 11:28:28 -05:00
return await mh . updatePropic ( authorId , args [ 1 ] , args [ 2 ] , attachmentUrl , attachmentExpiration ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
default :
2026-02-20 11:28:28 -05:00
return await mh . getMemberInfo ( authorId , args [ 1 ] ) ;
2026-02-17 17:25:18 -05:00
}
}
2026-02-14 13:37:51 -05:00
2026-02-17 17:25:18 -05:00
/ * *
* Adds a member .
*
* @ async
* @ param { string } authorId - The author of the message
* @ param { string [ ] } args - The message arguments
2026-02-19 20:08:26 -05:00
* @ param { string | null } attachmentURL - The attachment URL , if any exists
2026-02-17 17:25:18 -05:00
* @ returns { Promise < string > } A successful addition .
* @ throws { Error } When the member exists , or creating a member doesn ' t work .
* /
2026-02-19 20:08:26 -05:00
mh . addNewMember = async function ( authorId , args , attachmentURL = null ) {
2026-02-17 17:25:18 -05:00
if ( args [ 1 ] && args [ 1 ] === "--help" || ! args [ 1 ] ) {
return enums . help . NEW ;
}
const memberName = args [ 1 ] ;
const displayName = args [ 2 ] ;
2026-02-19 20:08:26 -05:00
const proxy = args [ 3 ] ;
const propic = args [ 4 ] ? ? attachmentURL ;
2026-02-17 17:25:18 -05:00
2026-02-19 21:36:19 -05:00
return await mh . addFullMember ( authorId , memberName , displayName , proxy , propic ) . then ( async ( response ) => {
2026-02-20 11:00:21 -05:00
const memberInfoEmbed = await mh . getMemberInfo ( authorId , response . member ) . catch ( ( e ) => { throw e } )
2026-02-19 21:36:19 -05:00
return { embed : memberInfoEmbed , errors : response . errors , success : ` ${ memberName } has been added successfully. ` } ;
2026-02-17 17:25:18 -05:00
} ) . catch ( e => {
throw e ;
} )
}
2026-02-14 13:37:51 -05:00
2026-02-17 17:25:18 -05:00
/ * *
* Updates the name for a member .
*
* @ async
* @ param { string } authorId - The author of the message
2026-02-20 11:00:21 -05:00
* @ param { string } memberName - The member to update
* @ param { string } name - The message arguments
2026-02-17 17:25:18 -05:00
* @ returns { Promise < string > } A successful update .
* @ throws { RangeError } When the name doesn ' t exist .
* /
2026-02-20 11:00:21 -05:00
mh . updateName = async function ( authorId , memberName , name ) {
if ( name === "--help" ) {
2026-02-17 22:23:47 -05:00
return enums . help . NAME ;
2026-02-17 17:25:18 -05:00
}
2026-02-17 22:23:47 -05:00
const trimmedName = name . trim ( ) ;
if ( trimmedName === '' ) {
throw new RangeError ( ` Name ${ enums . err . NO _VALUE } ` ) ;
2026-02-17 17:25:18 -05:00
}
2026-02-20 11:00:21 -05:00
return await mh . updateMemberField ( authorId , memberName , "name" , trimmedName ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
}
/ * *
* Updates the display name for a member .
*
* @ async
* @ param { string } authorId - The author of the message
2026-02-20 11:00:21 -05:00
* @ param { string } membername - The member to update
* @ param { string } displayname - The display name to set
2026-02-17 17:25:18 -05:00
* @ returns { Promise < string > } A successful update .
* @ throws { RangeError } When the display name is too long or doesn ' t exist .
* /
2026-02-20 11:00:21 -05:00
mh . updateDisplayName = async function ( authorId , membername , displayname ) {
if ( displayname === "--help" ) {
2026-02-17 17:25:18 -05:00
return enums . help . DISPLAY _NAME ;
}
2026-02-20 11:00:21 -05:00
const trimmedName = displayname . trim ( ) ;
2026-02-17 17:25:18 -05:00
2026-02-20 11:00:21 -05:00
if ( trimmedName . length > 32 ) {
2026-02-19 01:31:38 -05:00
throw new RangeError ( enums . err . DISPLAY _NAME _TOO _LONG ) ;
2026-02-17 22:23:47 -05:00
}
else if ( trimmedName === '' ) {
throw new RangeError ( ` Display name ${ enums . err . NO _VALUE } ` ) ;
2026-02-17 17:25:18 -05:00
}
2026-02-20 11:00:21 -05:00
return await mh . updateMemberField ( authorId , membername , "displayname" , trimmedName ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
}
/ * *
* Updates the proxy for a member , first checking that no other members attached to the author have the tag .
*
* @ async
* @ param { string } authorId - The author of the message
2026-02-20 11:00:21 -05:00
* @ param { string } memberName - The member to update
* @ param { string } proxy - The proxy to set
2026-02-17 17:25:18 -05:00
* @ returns { Promise < string > } A successful update .
* @ throws { RangeError | Error } When an empty proxy was provided , or no proxy exists .
* /
2026-02-20 11:00:21 -05:00
mh . updateProxy = async function ( authorId , memberName , proxy ) {
if ( proxy === "--help" ) {
2026-02-17 17:25:18 -05:00
return enums . help . PROXY ;
}
2026-02-20 11:00:21 -05:00
const proxyExists = await mh . checkIfProxyExists ( authorId , proxy ) . then ( ( proxyExists ) => {
2026-02-17 17:25:18 -05:00
return proxyExists ;
} ) . catch ( ( e ) => {
throw e
} ) ;
if ( ! proxyExists ) {
2026-02-20 11:00:21 -05:00
return await mh . updateMemberField ( authorId , memberName , "proxy" , proxy ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
}
}
/ * *
* Updates the profile pic for a member , based on either the attachment or the args provided .
*
* @ async
* @ param { string } authorId - The author of the message
2026-02-20 11:00:21 -05:00
* @ param { string } memberName - The member to update
* @ param { string } imgUrl - The message arguments
* @ param { string | null } attachmentUrl - The url of the first attachment in the message
2026-02-17 17:25:18 -05:00
* @ param { string | null } attachmentExpiry - The expiration date of the first attachment in the message ( if uploaded to Fluxer )
* @ returns { Promise < string > } A successful update .
* @ throws { Error } When loading the profile picture from a URL doesn ' t work .
* /
2026-02-20 11:00:21 -05:00
mh . updatePropic = async function ( authorId , memberName , imgUrl , attachmentUrl = null , attachmentExpiry = null ) {
if ( imgUrl === "--help" ) {
2026-02-17 17:25:18 -05:00
return enums . help . PROPIC ;
}
2026-02-20 11:00:21 -05:00
const isValidImage = await mh . checkImageFormatValidity ( attachmentUrl ? ? imgUrl ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
if ( isValidImage ) {
2026-02-20 11:00:21 -05:00
return await mh . updateMemberField ( authorId , memberName , "propic" , attachmentUrl ? ? imgUrl , attachmentExpiry ) . catch ( ( e ) => {
2026-02-17 17:25:18 -05:00
throw e
} ) ;
}
}
/ * *
* Checks if an uploaded picture is in the right format .
*
* @ async
* @ param { string } imageUrl - The url of the image
* @ returns { Promise < boolean > } - If the image is a valid format .
* @ throws { Error } When loading the profile picture from a URL doesn ' t work , or it fails requirements .
* /
mh . checkImageFormatValidity = async function ( imageUrl ) {
const acceptableImages = [ 'image/png' , 'image/jpg' , 'image/jpeg' , 'image/webp' ] ;
return await fetch ( imageUrl ) . then ( r => r . blob ( ) ) . then ( blobFile => {
if ( blobFile . size > 1000000 || ! acceptableImages . includes ( blobFile . type ) ) throw new Error ( enums . err . PROPIC _FAILS _REQUIREMENTS ) ;
return true ;
} ) . catch ( ( error ) => {
throw new Error ( ` ${ enums . err . PROPIC _CANNOT _LOAD } : ${ error . message } ` ) ;
} ) ;
}
/ * *
* Removes a member .
*
* @ async
* @ param { string } authorId - The author of the message
* @ param { string [ ] } args - The message arguments
* @ returns { Promise < string > } A successful removal .
* @ throws { EmptyResultError } When there is no member to remove .
* /
mh . removeMember = async function ( authorId , args ) {
if ( args [ 1 ] && args [ 1 ] === "--help" || ! args [ 1 ] ) {
return enums . help . REMOVE ;
}
const memberName = args [ 1 ] ;
return await database . members . destroy ( {
where : {
name : { [ Op . iLike ] : memberName } ,
userid : authorId
2026-02-16 14:29:53 -05:00
}
2026-02-17 17:25:18 -05:00
} ) . then ( ( result ) => {
if ( result ) {
return ` Member " ${ memberName } " has been deleted. ` ;
2026-02-16 14:29:53 -05:00
}
2026-02-17 17:25:18 -05:00
throw new EmptyResultError ( ` ${ enums . err . NO _MEMBER } ` ) ;
} )
}
/*======Non-Subcommands======*/
/ * *
* Adds a member with full details , first checking that there is no member of that name associated with the author .
*
* @ async
* @ param { string } authorId - The author of the message
* @ param { string } memberName - The 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 } propic - The profile picture URL of the member .
2026-02-20 11:00:21 -05:00
* @ returns { Promise < { model , string [ ] } > } A successful addition object , including errors if there are any .
2026-02-19 20:08:26 -05:00
* @ throws { Error } When the member already exists , there are validation errors , or adding a member doesn ' t work .
2026-02-17 17:25:18 -05:00
* /
2026-02-19 20:08:26 -05:00
mh . addFullMember = async function ( authorId , memberName , displayName = null , proxy = null , propic = null ) {
2026-02-17 17:25:18 -05:00
await mh . getMemberByName ( authorId , memberName ) . then ( ( member ) => {
if ( member ) {
throw new Error ( ` Can't add ${ memberName } . ${ enums . err . MEMBER _EXISTS } ` ) ;
2026-02-16 14:29:53 -05:00
}
2026-02-17 17:25:18 -05:00
} ) ;
2026-02-19 20:08:26 -05:00
const errors = [ ] ;
let isValidDisplayName ;
if ( displayName && displayName . length > 0 ) {
2026-02-17 17:25:18 -05:00
const trimmedName = displayName ? displayName . trim ( ) : null ;
if ( trimmedName && trimmedName . length > 32 ) {
2026-02-19 20:08:26 -05:00
errors . push ( ` Tried to set displayname to \" ${ displayName } \" . ${ enums . err . DISPLAY _NAME _TOO _LONG } . ${ enums . err . SET _TO _NULL } ` ) ;
isValidDisplayName = false ;
}
else {
isValidDisplayName = true ;
2026-02-16 14:29:53 -05:00
}
2026-02-17 17:25:18 -05:00
}
2026-02-19 20:08:26 -05:00
let isValidProxy ;
if ( proxy && proxy . length > 0 ) {
await mh . checkIfProxyExists ( authorId , proxy ) . then ( ( ) => {
isValidProxy = true ;
} ) . catch ( ( e ) => {
errors . push ( ` Tried to set proxy to \" ${ proxy } \" . ${ e . message } . ${ enums . err . SET _TO _NULL } ` ) ;
isValidProxy = false ;
2026-02-16 14:29:53 -05:00
} ) ;
2026-02-17 17:25:18 -05:00
}
2026-02-19 20:08:26 -05:00
let isValidPropic ;
if ( propic && propic . length > 0 ) {
await mh . checkImageFormatValidity ( propic ) . then ( ( ) => {
isValidPropic = true ;
2026-02-17 17:25:18 -05:00
} ) . catch ( ( e ) => {
2026-02-19 20:08:26 -05:00
errors . push ( ` Tried to set profile picture to \" ${ propic } \" . ${ e . message } . ${ enums . err . SET _TO _NULL } ` ) ;
isValidPropic = false ;
2026-02-15 15:57:08 -05:00
} ) ;
2026-02-17 17:25:18 -05:00
}
const member = await database . members . create ( {
2026-02-19 20:08:26 -05:00
name : memberName , userid : authorId , displayname : isValidDisplayName ? displayName : null , proxy : isValidProxy ? proxy : null , propic : isValidPropic ? propic : null
2026-02-17 17:25:18 -05:00
} ) ;
2026-02-19 20:08:26 -05:00
return { member : member , errors : errors } ;
2026-02-17 17:25:18 -05:00
}
2026-02-19 20:08:26 -05:00
// mh.mergeFullMember = async function (authorId, memberName, displayName = null, proxy = null, propic = null) {
// await mh.getMemberByName(authorId, memberName).then((member) => {
// if (member) {
// throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`);
// }
// });
//
// let isValidDisplayName;
// if (displayName) {
// const trimmedName = displayName ? displayName.trim() : null;
// if (trimmedName && trimmedName.length > 32) {
// if (!isImport) {
// throw new RangeError(`Can't add ${memberName}. ${enums.err.DISPLAY_NAME_TOO_LONG}`);
// }
// isValidDisplayName = false;
// }
// }
//
// let isValidProxy;
// if (proxy) {
// isValidProxy = await mh.checkIfProxyExists(authorId, proxy).then((res) => {
// return res;
// }).catch((e) => {
// if (!isImport) {
// throw e
// }
// return false;
// });
// }
//
// let isValidPropic;
// if (propic) {
// isValidPropic = await mh.checkImageFormatValidity(propic).then((valid) => {
// return valid;
// }).catch((e) => {
// if (!isImport) {
// throw (e);
// }
// return false;
// });
// }
//
// const member = await database.members.create({
// name: memberName, userid: authorId, displayname: isValidDisplayName ? displayName: null, proxy: isValidProxy ? proxy : null, propic: isValidPropic ? propic : null,
// });
// if (!member) {
// new Error(`${enums.err.ADD_ERROR}`);
// }
// return member;
// }
//
// mh.overwriteFullMemberFromImport = async function (authorId, memberName, displayName = null, proxy = null, propic = null) {
// await mh.getMemberByName(authorId, memberName).then((member) => {
// if (member) {
// throw new Error(`Can't add ${memberName}. ${enums.err.MEMBER_EXISTS}`);
// }
// });
//
// let isValidDisplayName;
// if (displayName) {
// const trimmedName = displayName ? displayName.trim() : null;
// if (trimmedName && trimmedName.length > 32) {
// if (!isImport) {
// throw new RangeError(`Can't add ${memberName}. ${enums.err.DISPLAY_NAME_TOO_LONG}`);
// }
// isValidDisplayName = false;
// }
// }
//
// let isValidProxy;
// if (proxy) {
// isValidProxy = await mh.checkIfProxyExists(authorId, proxy).then((res) => {
// return res;
// }).catch((e) => {
// if (!isImport) {
// throw e
// }
// return false;
// });
// }
//
// let isValidPropic;
// if (propic) {
// isValidPropic = await mh.checkImageFormatValidity(propic).then((valid) => {
// return valid;
// }).catch((e) => {
// if (!isImport) {
// throw (e);
// }
// return false;
// });
// }
//
// const member = await database.members.create({
// name: memberName, userid: authorId, displayname: isValidDisplayName ? displayName: null, proxy: isValidProxy ? proxy : null, propic: isValidPropic ? propic : null,
// });
// if (!member) {
// new Error(`${enums.err.ADD_ERROR}`);
// }
// return member;
// }
2026-02-17 17:25:18 -05:00
/ * *
* Updates one fields for a member in the database .
*
* @ async
* @ param { string } authorId - The author of the message
2026-02-20 11:00:21 -05:00
* @ param { string } memberName - The member to update
* @ param { string } columnName - The column name to update .
* @ param { string } value - The value to update to .
* @ param { string | null } attachmentExpiration - The attachment expiration date ( if any )
2026-02-17 17:25:18 -05:00
* @ returns { Promise < string > } A successful update .
2026-02-20 11:00:21 -05:00
* @ throws { Error } When the member is not found , or catchall error .
2026-02-17 17:25:18 -05:00
* /
2026-02-20 11:00:21 -05:00
mh . updateMemberField = async function ( authorId , memberName , columnName , value , attachmentExpiration = null ) {
2026-02-17 17:25:18 -05:00
let fluxerPropicWarning ;
// indicates that an attachment was uploaded on Fluxer directly
2026-02-20 11:00:21 -05:00
if ( columnName === "propic" && attachmentExpiration ) {
fluxerPropicWarning = mh . setExpirationWarning ( value ) ;
2026-02-17 17:25:18 -05:00
}
return await database . members . update ( { [ columnName ] : value } , {
where : {
name : { [ Op . iLike ] : memberName } ,
userid : authorId
2026-02-15 15:57:08 -05:00
}
2026-02-17 22:23:47 -05:00
} ) . then ( ( res ) => {
if ( res [ 0 ] === 0 ) {
2026-02-20 11:00:21 -05:00
throw new Error ( ` Can't update ${ memberName } . ${ enums . err . NO _MEMBER } . ` ) ;
2026-02-17 22:23:47 -05:00
} else {
return ` Updated ${ columnName } for ${ memberName } to ${ value } ${ fluxerPropicWarning ? ? '' } . ` ;
}
} )
2026-02-17 17:25:18 -05:00
}
2026-02-14 15:55:32 -05:00
2026-02-17 17:25:18 -05:00
/ * *
* Sets the warning for an expiration date .
*
* @ param { string } expirationString - An expiration date string .
* @ returns { string } A description of the expiration , interpolating the expiration string .
* /
mh . setExpirationWarning = function ( expirationString ) {
let expirationDate = new Date ( expirationString ) ;
if ( ! isNaN ( expirationDate . valueOf ( ) ) ) {
expirationDate = expirationDate . toDateString ( ) ;
return ` \n **NOTE:** Because this profile picture was uploaded via Fluxer, it will currently expire on * ${ expirationDate } *. To avoid this, upload the picture to another website like <https://imgbb.com/> and link to it directly `
}
}
/ * *
* Gets the details for a member .
*
* @ async
* @ param { string } authorId - The author of the message
2026-02-20 11:00:21 -05:00
* @ param { model } member - The member object
2026-02-17 17:25:18 -05:00
* @ returns { Promise < EmbedBuilder > } The member ' s info .
* /
2026-02-20 11:00:21 -05:00
mh . getMemberInfo = async function ( authorId , member ) {
return new EmbedBuilder ( )
. setTitle ( member . name )
. setDescription ( ` Details for ${ member . name } ` )
. addFields ( {
name : 'Display name: ' ,
value : member . displayname ? ? 'unset' ,
inline : true
} , { name : 'Proxy tag: ' , value : member . proxy ? ? 'unset' , inline : true } , )
. setImage ( member . propic ) ;
2026-02-17 17:25:18 -05:00
}
/ * *
* Gets all members for an author .
*
* @ async
* @ param { string } authorId - The id of the message author
* @ param { string } authorName - The id name the message author
* @ returns { Promise < EmbedBuilder > } The info for all members .
* @ throws { Error } When there are no members for an author .
* /
mh . getAllMembersInfo = async function ( authorId , authorName ) {
const members = await mh . getMembersByAuthor ( authorId ) ;
if ( members == null ) throw Error ( enums . err . USER _NO _MEMBERS ) ;
const fields = [ ... members . entries ( ) ] . map ( ( [ name , member ] ) => ( {
name : member . name , value : ` (Proxy: \` ${ member . proxy ? ? "unset" } \` ) ` , inline : true ,
} ) ) ;
return new EmbedBuilder ( )
. setTitle ( ` ${ fields > 25 ? "First 25 m" : "M" } embers for ${ authorName } ` )
. addFields ( ... fields ) ;
}
/ * *
* Gets a member based on the author and proxy tag .
*
* @ async
* @ param { string } authorId - The author of the message .
* @ param { string } memberName - The member ' s name .
* @ returns { Promise < model > } The member object .
* @ throws { EmptyResultError } When the member is not found .
* /
mh . getMemberByName = async function ( authorId , memberName ) {
return await database . members . findOne ( { where : { userid : authorId , name : { [ Op . iLike ] : memberName } } } ) ;
}
/ * *
* Gets all members belonging to the author .
*
* @ async
* @ param { string } authorId - The author of the message
* @ returns { Promise < model [ ] | null > } The member object array .
* /
mh . getMembersByAuthor = async function ( authorId ) {
return await database . members . findAll ( { where : { userid : authorId } } ) ;
}
/ * *
* Checks if proxy exists for a member .
*
* @ param { string } authorId - The author of the message
* @ param { string } proxy - The proxy tag .
* @ returns { Promise < boolean > } Whether the proxy exists .
* @ throws { Error } When an empty proxy was provided , or no proxy exists .
* /
mh . checkIfProxyExists = async function ( authorId , proxy ) {
if ( proxy ) {
const splitProxy = proxy . trim ( ) . split ( "text" ) ;
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 ) ;
await mh . getMembersByAuthor ( authorId ) . then ( ( memberList ) => {
const proxyExists = memberList . some ( member => member . proxy === proxy ) ;
if ( proxyExists ) {
throw new Error ( enums . err . PROXY _EXISTS ) ;
2026-02-16 14:29:53 -05:00
}
2026-02-17 17:25:18 -05:00
} ) . catch ( e => {
throw e
2026-02-16 14:29:53 -05:00
} ) ;
2026-02-16 10:55:28 -05:00
}
2026-02-17 17:25:18 -05:00
2026-02-14 22:11:04 -05:00
}
2026-02-20 11:00:21 -05:00
/ * *
* Creates an embed with all member commands
*
* @ returns { EmbedBuilder } An embed of member commands .
* /
mh . getMemberCommandInfo = function ( ) {
const fields = [
2026-02-20 11:03:50 -05:00
{ name : ` **new** ` , value : enums . help . NEW , inline : false } ,
{ name : ` **remove** ` , value : enums . help . REMOVE , inline : false } ,
{ name : ` **name** ` , value : enums . help . NAME , inline : false } ,
{ name : ` **displayname** ` , value : enums . help . DISPLAY _NAME , inline : false } ,
{ name : ` **proxy** ` , value : enums . help . PROXY , inline : false } ,
{ name : ` **propic** ` , value : enums . help . PROPIC , inline : false } ,
{ name : ` **list** ` , value : enums . help . LIST , inline : false } ,
2026-02-20 11:00:21 -05:00
] ;
return new EmbedBuilder ( )
. setTitle ( "Member subcommands" )
. setDescription ( enums . help . MEMBER )
. addFields ( ... fields ) ;
}
2026-02-14 22:11:04 -05:00
2026-02-17 17:25:18 -05:00
export const memberHelper = mh ;