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,6 +82,7 @@ async function CommandDispatcher(msg) {
const args = parseArguments(line);
try {
const response = await runCommand(msg, cmd, line, args);
if (response != null) {
let file;
@ -89,6 +90,9 @@ async function CommandDispatcher(msg) {
file = response.file;
delete response.file;
}
if (response.embed) {
response.embeds = [...(response.embeds ?? []), response.embed];
}
if (response.embeds) {
for (const embed of response.embeds) {
embed.color =
@ -99,8 +103,8 @@ async function CommandDispatcher(msg) {
if (response.reaction) {
msg.addReaction(response.reaction);
} else {
msg.channel
.createMessage(
try {
const outMessage = await msg.channel.createMessage(
Object.assign(
typeof response === "string" ? {content: response} : response,
{
@ -113,10 +117,16 @@ async function CommandDispatcher(msg) {
}
),
file
)
.catch((e) => {
);
if (response.addReactions) {
for (const index in response.addReactions) {
const reaction = response.addReactions[index];
await outMessage.addReaction(reaction);
}
}
} catch (err) {
msg.channel.createMessage({
content: `:warning: An error has occurred:\n\`\`\`${e}\`\`\``,
content: `:warning: An error has occurred:\n\`\`\`${err}\`\`\``,
allowedMentions: {
repliedUser: false,
},
@ -124,10 +134,21 @@ async function CommandDispatcher(msg) {
messageID: msg.id,
},
});
});
}
}
msg.hasRan = true;
}
} catch (err) {
msg.channel.createMessage({
content: `:warning: An error has occurred:\n\`\`\`${err}\`\`\``,
allowedMentions: {
repliedUser: false,
},
messageReference: {
messageID: msg.id,
},
});
}
}
}