commandDispatcher: convert embed to embeds, add addReactions

This commit is contained in:
Cynthia Foxwell 2022-04-01 18:10:10 -06:00
parent ff8d811ee3
commit 2577a7e847

View file

@ -82,41 +82,51 @@ async function CommandDispatcher(msg) {
const args = parseArguments(line); const args = parseArguments(line);
const response = await runCommand(msg, cmd, line, args); try {
if (response != null) { const response = await runCommand(msg, cmd, line, args);
let file; if (response != null) {
if (response.file) { let file;
file = response.file; if (response.file) {
delete response.file; file = response.file;
} delete response.file;
if (response.embeds) {
for (const embed of response.embeds) {
embed.color =
embed.color ||
getTopColor(msg, hf.bot.user.id, pastelize(hf.bot.user.id));
} }
} if (response.embed) {
if (response.reaction) { response.embeds = [...(response.embeds ?? []), response.embed];
msg.addReaction(response.reaction); }
} else { if (response.embeds) {
msg.channel for (const embed of response.embeds) {
.createMessage( embed.color =
Object.assign( embed.color ||
typeof response === "string" ? {content: response} : response, getTopColor(msg, hf.bot.user.id, pastelize(hf.bot.user.id));
{ }
allowedMentions: { }
repliedUser: false, if (response.reaction) {
}, msg.addReaction(response.reaction);
messageReference: { } else {
messageID: msg.id, try {
}, const outMessage = await msg.channel.createMessage(
Object.assign(
typeof response === "string" ? {content: response} : response,
{
allowedMentions: {
repliedUser: false,
},
messageReference: {
messageID: msg.id,
},
}
),
file
);
if (response.addReactions) {
for (const index in response.addReactions) {
const reaction = response.addReactions[index];
await outMessage.addReaction(reaction);
} }
), }
file } catch (err) {
)
.catch((e) => {
msg.channel.createMessage({ msg.channel.createMessage({
content: `:warning: An error has occurred:\n\`\`\`${e}\`\`\``, content: `:warning: An error has occurred:\n\`\`\`${err}\`\`\``,
allowedMentions: { allowedMentions: {
repliedUser: false, repliedUser: false,
}, },
@ -124,9 +134,20 @@ async function CommandDispatcher(msg) {
messageID: msg.id, messageID: msg.id,
}, },
}); });
}); }
}
msg.hasRan = true;
} }
msg.hasRan = true; } catch (err) {
msg.channel.createMessage({
content: `:warning: An error has occurred:\n\`\`\`${err}\`\`\``,
allowedMentions: {
repliedUser: false,
},
messageReference: {
messageID: msg.id,
},
});
} }
} }
} }