forked from PluralFlux/PluralFlux
putting everything in a try catch block to hopefully not crash the bot....
This commit is contained in:
15
bot.js
15
bot.js
@@ -32,13 +32,13 @@ let pluralFluxName = "PluralFlux";
|
||||
let pluralFluxDiscriminator = "8677";
|
||||
|
||||
client.on(GatewayDispatchEvents.MessageCreate, async ({ api, data }) => {
|
||||
try {
|
||||
if (data.webhook_id) {
|
||||
return;
|
||||
}
|
||||
else if (data.author.username === pluralFluxName && data.author.discriminator === pluralFluxDiscriminator) {
|
||||
} else if (data.author.username === pluralFluxName && data.author.discriminator === pluralFluxDiscriminator) {
|
||||
return;
|
||||
}
|
||||
else if (data.content.startsWith(messageHelper.prefix)) {
|
||||
} else if (data.content.startsWith(messageHelper.prefix)) {
|
||||
|
||||
const commandName = data.content.slice(messageHelper.prefix.length).split(" ")[0];
|
||||
const args = messageHelper.parseCommandArgs(data.content, commandName);
|
||||
if (!commandName) {
|
||||
@@ -55,14 +55,17 @@ client.on(GatewayDispatchEvents.MessageCreate, async ({ api, data }) => {
|
||||
default:
|
||||
return await api.channels.createMessage(data.channel_id, {content: enums.err.NO_SUCH_COMMAND});
|
||||
}
|
||||
}
|
||||
const proxyMatch = await messageHelper.parseProxyTags(data.author.id, data.content);
|
||||
if (!proxyMatch.proxy) {
|
||||
return;
|
||||
}
|
||||
const member = await memberHelper.getMemberByProxy(data.author.id, proxyMatch.proxy);
|
||||
await webhookHelper.replaceMessage(api, data, proxyMatch.message, member);
|
||||
|
||||
}
|
||||
}
|
||||
catch(error) {
|
||||
return await api.channels.createMessage(data.channel_id, {content: error});
|
||||
}
|
||||
});
|
||||
|
||||
client.on(GatewayDispatchEvents.Ready, async ({data}) => {
|
||||
|
||||
@@ -191,7 +191,7 @@ async function removeMember(authorId, args) {
|
||||
return `${enums.err.NO_NAME_PROVIDED} deletion.`;
|
||||
}
|
||||
return await db.members.destroy({ where: { name: memberName, userid: authorId } }).then(() => {
|
||||
return `${memberName} has been deleted.`;
|
||||
return `Member "${memberName}" has been deleted.`;
|
||||
}).catch(e => {
|
||||
return `${enums.err.NO_MEMBER}: ${e.message}`;
|
||||
});
|
||||
@@ -218,7 +218,7 @@ async function updateMember(authorId, args) {
|
||||
fluxerPropicWarning = setExpirationWarning(args[3]);
|
||||
}
|
||||
return await db.members.update({[columnName]: value}, { where: { name: memberName, userid: authorId } }).then(() => {
|
||||
return `Updated ${columnName} for ${memberName} to ${value}${fluxerPropicWarning}.`;
|
||||
return `Updated ${columnName} for ${memberName} to "${value}"${fluxerPropicWarning ?? ''}.`;
|
||||
}).catch(e => {
|
||||
return `${enums.err.NO_MEMBER}: ${e.message}`;
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user