put braces around throw e

This commit is contained in:
Aster Fialla
2026-02-14 21:10:20 -05:00
committed by pieartsy
parent 7c7b1f0202
commit 89fe2c70b2
5 changed files with 31 additions and 29 deletions

View File

@@ -24,7 +24,9 @@ client.on(Events.MessageCreate, async (message) => {
// If message doesn't start with the bot prefix, it could still be a message with a proxy tag. If it's not, return. // If message doesn't start with the bot prefix, it could still be a message with a proxy tag. If it's not, return.
if (!content.startsWith(messageHelper.prefix)) { if (!content.startsWith(messageHelper.prefix)) {
await webhookHelper.sendMessageAsMember(client, message, content).catch(e => throw e); await webhookHelper.sendMessageAsMember(client, message, content).catch((e) => {
throw e
});
return; return;
} }
@@ -36,7 +38,9 @@ client.on(Events.MessageCreate, async (message) => {
const command = commands.get(commandName); const command = commands.get(commandName);
if (command) { if (command) {
await command.execute(message, client, args).catch(e => throw e); await command.execute(message, client, args).catch(e => {
throw e
});
} }
} }
catch(error) { catch(error) {

View File

@@ -9,7 +9,7 @@ cmds.set('member', {
description: enums.help.SHORT_DESC_MEMBER, description: enums.help.SHORT_DESC_MEMBER,
async execute(message, client, args) { async execute(message, client, args) {
const authorFull = `${message.author.username}#${message.author.discriminator}` const authorFull = `${message.author.username}#${message.author.discriminator}`
const reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, message.attachments[0] = null).catch(e => throw e); const reply = await memberHelper.parseMemberCommand(message.author.id, authorFull, args, message.attachments[0] = null).catch(e =>{throw e});
if (typeof reply === 'string') { if (typeof reply === 'string') {
return await message.reply(reply); return await message.reply(reply);
} }

View File

@@ -17,21 +17,19 @@ const commandList = ['--help', 'add', 'remove', 'name', 'listall', 'displayName'
* @param {string | null} attachmentUrl - The message attachment url. * @param {string | null} attachmentUrl - The message attachment url.
* @returns {Promise<string> | Promise <EmbedBuilder>} A message, or an informational embed. * @returns {Promise<string> | Promise <EmbedBuilder>} A message, or an informational embed.
*/ */
mh.parseMemberCommand = async function(author, args, attachmentUrl){ mh.parseMemberCommand = async function(authorId, authorFull, args, attachmentUrl){
const authorId = author.id;
const authorFull = `${author.username}${author.discriminator}`;
let member; let member;
// checks whether command is in list, otherwise assumes it's a name // checks whether command is in list, otherwise assumes it's a name
if(!commandList.includes(args[0])) { if(!commandList.includes(args[0])) {
member = await getMemberInfo(authorId, args[0]); member = await mh.getMemberInfo(authorId, args[0]).catch((e) =>{throw e});
} }
switch(args[0]) { switch(args[0]) {
case '--help': case '--help':
return enums.help.MEMBER; return enums.help.MEMBER;
case 'add': case 'add':
return await mh.addNewMember(authorId, args).catch((e) => throw e); return await mh.addNewMember(authorId, args).catch((e) =>{throw e});
case 'remove': case 'remove':
return await mh.removeMember(authorId, args).catch((e) => throw e); return await mh.removeMember(authorId, args).catch((e) =>{throw e});
case 'name': case 'name':
return enums.help.NAME; return enums.help.NAME;
case 'displayname': case 'displayname':
@@ -41,19 +39,19 @@ mh.parseMemberCommand = async function(author, args, attachmentUrl){
case 'propic': case 'propic':
return enums.help.PROPIC; return enums.help.PROPIC;
case 'list': case 'list':
return await mh.getAllMembersInfo(authorId, authorFull).catch((e) => throw e); return await mh.getAllMembersInfo(authorId, authorFull).catch((e) =>{throw e});
case '': case '':
return enums.help.MEMBER; return enums.help.MEMBER;
} }
switch(args[1]) { switch(args[1]) {
case 'name': case 'name':
return await mh.updateName(authorId, args).catch((e) => throw e); return await mh.updateName(authorId, args).catch((e) =>{throw e});
case 'displayname': case 'displayname':
return await mh.updateDisplayName(authorId, args).catch((e) => throw e); return await mh.updateDisplayName(authorId, args).catch((e) =>{throw e});
case 'proxy': case 'proxy':
return await mh.updateProxy(authorId, args).catch((e) => throw e); return await mh.updateProxy(authorId, args).catch((e) =>{throw e});
case 'propic': case 'propic':
return await mh.updatePropic(authorId, args, attachmentUrl).catch((e) => throw e); return await mh.updatePropic(authorId, args, attachmentUrl).catch((e) =>{throw e});
default: default:
return member; return member;
} }
@@ -103,7 +101,7 @@ mh.updateName = async function (authorId, args) {
if (!name || trimmedName === null) { if (!name || trimmedName === null) {
throw new RangeError(`Display name ${enums.err.NO_VALUE}`); throw new RangeError(`Display name ${enums.err.NO_VALUE}`);
} }
return await mh.updateMemberField(authorId, args).catch((e) => throw e); return await mh.updateMemberField(authorId, args).catch((e) =>{throw e});
} }
/** /**
@@ -130,13 +128,13 @@ mh.updateDisplayName = async function(authorId, args) {
return `Display name for ${memberName} is: \"${member.displayname}\".`; return `Display name for ${memberName} is: \"${member.displayname}\".`;
} }
throw new RangeError(`Display name ${enums.err.NO_VALUE}`); throw new RangeError(`Display name ${enums.err.NO_VALUE}`);
}).catch((e) => throw e); }).catch((e) =>{throw e});
} }
else if (displayName.length > 32) { else if (displayName.length > 32) {
throw new RangeError(enums.err.DISPLAY_NAME_TOO_LONG); throw new RangeError(enums.err.DISPLAY_NAME_TOO_LONG);
} }
return await mh.updateMemberField(authorId, args).catch((e) => throw e); return await mh.updateMemberField(authorId, args).catch((e) =>{throw e});
} }
/** /**
@@ -154,9 +152,9 @@ mh.updateProxy = async function(authorId, args) {
} }
const proxyExists = await mh.checkIfProxyExists(authorId, args[2]).then((proxyExists) => { const proxyExists = await mh.checkIfProxyExists(authorId, args[2]).then((proxyExists) => {
return proxyExists; return proxyExists;
}).catch((e) => throw e); }).catch((e) =>{throw e});
if (!proxyExists) { if (!proxyExists) {
return await mh.updateMemberField(authorId, args).catch((e) => throw e); return await mh.updateMemberField(authorId, args).catch((e) =>{throw e});
} }
} }
@@ -182,7 +180,7 @@ mh.checkIfProxyExists = async function(authorId, proxy) {
throw new Error(enums.err.PROXY_EXISTS); throw new Error(enums.err.PROXY_EXISTS);
} }
return false; return false;
}).catch(e => throw e); }).catch(e =>{throw e});
} }
/** /**
@@ -217,7 +215,7 @@ mh.updatePropic = async function(authorId, args, attachment) {
throw new Error(`${enums.err.PROPIC_CANNOT_LOAD}: ${err.message}`); throw new Error(`${enums.err.PROPIC_CANNOT_LOAD}: ${err.message}`);
}); });
if (loadedImage) { if (loadedImage) {
return await mh.updateMemberField(authorId, updatedArgs).catch((e) => throw e); return await mh.updateMemberField(authorId, updatedArgs).catch((e) =>{throw e});
} }
} }
@@ -350,7 +348,7 @@ mh.getMemberInfo = async function(authorId, memberName) {
{name: 'Proxy tag: ', value: member.proxy ?? 'unset', inline: true}, {name: 'Proxy tag: ', value: member.proxy ?? 'unset', inline: true},
) )
.setImage(member.propic); .setImage(member.propic);
}).catch((e) => throw e) }).catch((e) =>{throw e})
} }
/** /**
@@ -363,7 +361,7 @@ mh.getMemberInfo = async function(authorId, memberName) {
* @throws {Error} * @throws {Error}
*/ */
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(([member]) => ({
name: member.name, name: member.name,
value: `(Proxy: \`${member.proxy}\`)`, value: `(Proxy: \`${member.proxy}\`)`,

View File

@@ -39,7 +39,7 @@ msgh.parseCommandArgs = function(content, commandName) {
* @returns {Object} The proxy message object. * @returns {Object} The proxy message object.
*/ */
msgh.parseProxyTags = async function (authorId, attachment, content){ msgh.parseProxyTags = async function (authorId, attachment, content){
const members = await memberHelper.getMembersByAuthor(authorId).catch(e => throw e); const members = await memberHelper.getMembersByAuthor(authorId).catch(e =>{throw e});
const proxyMessage = {} const proxyMessage = {}
members.filter(member => member.proxy).forEach(member => { members.filter(member => member.proxy).forEach(member => {

View File

@@ -15,7 +15,7 @@ const name = 'PluralFlux Proxy Webhook';
* @throws {Error} When the proxy message is not in a server. * @throws {Error} When the proxy message is not in a server.
*/ */
wh.sendMessageAsMember = async function(client, message, content) { wh.sendMessageAsMember = async function(client, message, content) {
const proxyMatch = await messageHelper.parseProxyTags(message.author.id, message.attachments[0] ?? null, content).catch(e => throw e); const proxyMatch = await messageHelper.parseProxyTags(message.author.id, message.attachments[0] ?? null, content).catch(e =>{throw e});
// If the message doesn't match a proxy, just return. // If the message doesn't match a proxy, just return.
if (!proxyMatch.proxy) { if (!proxyMatch.proxy) {
return; return;
@@ -24,8 +24,8 @@ wh.sendMessageAsMember = async function(client, message, content) {
if (!message.guildId) { if (!message.guildId) {
throw new Error(enums.err.NOT_IN_SERVER); throw new Error(enums.err.NOT_IN_SERVER);
} }
const member = await memberHelper.getMemberByProxy(message.author.id, proxyMatch.proxy).catch(e => throw e); const member = await memberHelper.getMemberByProxy(message.author.id, proxyMatch.proxy).catch(e =>{throw e});
await replaceMessage(client, message, message.channelId, proxyMatch.message, member).catch(e => throw e); await replaceMessage(client, message, message.channelId, proxyMatch.message, member).catch(e =>{throw e});
} }
/** /**
@@ -40,7 +40,7 @@ wh.sendMessageAsMember = async function(client, message, content) {
async function replaceMessage(client, message, channelId, text, member) { async function replaceMessage(client, message, channelId, text, member) {
if (text.length > 0) { if (text.length > 0) {
const channel = client.channels.get(channelId); const channel = client.channels.get(channelId);
const webhook = await getOrCreateWebhook(client, channel).catch((e) => throw e); const webhook = await getOrCreateWebhook(client, channel).catch((e) =>{throw e});
const username = member.displayname ?? member.name; const username = member.displayname ?? member.name;
await webhook.send({content: text, username: username, avatar_url: member.propic}); await webhook.send({content: text, username: username, avatar_url: member.propic});
await message.delete(); await message.delete();
@@ -74,7 +74,7 @@ async function replaceMessage(client, message, channelId, text, member) {
async function getOrCreateWebhook(client, channel) { async function getOrCreateWebhook(client, channel) {
// If channel doesn't allow webhooks // If channel doesn't allow webhooks
if (!channel?.createWebhook) throw new Error(enums.err.NO_WEBHOOKS_ALLOWED); if (!channel?.createWebhook) throw new Error(enums.err.NO_WEBHOOKS_ALLOWED);
let webhook = await getWebhook(client, channel).catch((e) => throw e); let webhook = await getWebhook(client, channel).catch((e) =>{throw e});
if (!webhook) { if (!webhook) {
webhook = await channel.createWebhook({name: name}); webhook = await channel.createWebhook({name: name});
} }