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 response = await runCommand(msg, cmd, line, args);
if (response != null) {
let file;
if (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));
try {
const response = await runCommand(msg, cmd, line, args);
if (response != null) {
let file;
if (response.file) {
file = response.file;
delete response.file;
}
}
if (response.reaction) {
msg.addReaction(response.reaction);
} else {
msg.channel
.createMessage(
Object.assign(
typeof response === "string" ? {content: response} : response,
{
allowedMentions: {
repliedUser: false,
},
messageReference: {
messageID: msg.id,
},
if (response.embed) {
response.embeds = [...(response.embeds ?? []), response.embed];
}
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.reaction) {
msg.addReaction(response.reaction);
} else {
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((e) => {
}
} 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,9 +134,20 @@ async function CommandDispatcher(msg) {
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,
},
});
}
}
}