Added (hacky) message command support, lots of work to prepare for message content intent enforcement, improve broadcast, remove evalraw, update packages
This commit is contained in:
parent
3392c3c89e
commit
d33a7804d7
56 changed files with 443 additions and 315 deletions
|
@ -1,31 +1,40 @@
|
|||
import database from "../utils/database.js";
|
||||
import * as logger from "../utils/logger.js";
|
||||
import { commands } from "../utils/collections.js";
|
||||
import { CommandInteraction } from "eris";
|
||||
import { commands, messageCommands } from "../utils/collections.js";
|
||||
import { clean } from "../utils/misc.js";
|
||||
import { upload } from "../utils/tempimages.js";
|
||||
|
||||
// run when a slash command is executed
|
||||
export default async (client, cluster, worker, ipc, interaction) => {
|
||||
if (!(interaction instanceof CommandInteraction)) return;
|
||||
if (interaction?.type !== 2) return;
|
||||
|
||||
// check if command exists and if it's enabled
|
||||
const command = interaction.data.name;
|
||||
const cmd = commands.get(command);
|
||||
if (!cmd) return;
|
||||
let cmd = commands.get(command);
|
||||
if (!cmd) {
|
||||
cmd = messageCommands.get(command);
|
||||
if (!cmd) return;
|
||||
}
|
||||
|
||||
const invoker = interaction.member ?? interaction.user;
|
||||
|
||||
// actually run the command
|
||||
logger.log("log", `${invoker.username} (${invoker.id}) ran slash command ${command}`);
|
||||
logger.log("log", `${invoker.username} (${invoker.id}) ran application command ${command}`);
|
||||
try {
|
||||
await database.addCount(command);
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
const commandClass = new cmd(client, cluster, worker, ipc, { type: "application", interaction });
|
||||
const result = await commandClass.run();
|
||||
const replyMethod = interaction.acknowledged ? "editOriginalMessage" : "createMessage";
|
||||
if (typeof result === "string" || (typeof result === "object" && result.embeds)) {
|
||||
await interaction[replyMethod](result);
|
||||
if (typeof result === "string") {
|
||||
await interaction[replyMethod]({
|
||||
content: result,
|
||||
flags: commandClass.success ? 0 : 64
|
||||
});
|
||||
} else if (typeof result === "object" && result.embeds) {
|
||||
await interaction[replyMethod](Object.assign(result, {
|
||||
flags: result.flags ?? (commandClass.success ? 0 : 64)
|
||||
}));
|
||||
} else if (typeof result === "object" && result.file) {
|
||||
let fileSize = 8388119;
|
||||
if (interaction.channel.guild) {
|
||||
|
@ -42,7 +51,10 @@ export default async (client, cluster, worker, ipc, interaction) => {
|
|||
if (process.env.TEMPDIR && process.env.TEMPDIR !== "") {
|
||||
await upload(client, ipc, result, interaction, true);
|
||||
} else {
|
||||
await interaction[replyMethod]("The resulting image was more than 8MB in size, so I can't upload it.");
|
||||
await interaction[replyMethod]({
|
||||
content: "The resulting image was more than 8MB in size, so I can't upload it.",
|
||||
flags: 64
|
||||
});
|
||||
}
|
||||
} else {
|
||||
await interaction[replyMethod](result.text ? result.text : {}, result);
|
||||
|
@ -51,13 +63,13 @@ export default async (client, cluster, worker, ipc, interaction) => {
|
|||
} catch (error) {
|
||||
const replyMethod = interaction.acknowledged ? "editOriginalMessage" : "createMessage";
|
||||
if (error.toString().includes("Request entity too large")) {
|
||||
await interaction[replyMethod]("The resulting file was too large to upload. Try again with a smaller image if possible.");
|
||||
await interaction[replyMethod]({ content: "The resulting file was too large to upload. Try again with a smaller image if possible.", flags: 64 });
|
||||
} else if (error.toString().includes("Job ended prematurely")) {
|
||||
await interaction[replyMethod]("Something happened to the image servers before I could receive the image. Try running your command again.");
|
||||
await interaction[replyMethod]({ content: "Something happened to the image servers before I could receive the image. Try running your command again.", flags: 64 });
|
||||
} else if (error.toString().includes("Timed out")) {
|
||||
await interaction[replyMethod]("The request timed out before I could download that image. Try uploading your image somewhere else or reducing its size.");
|
||||
await interaction[replyMethod]({ content: "The request timed out before I could download that image. Try uploading your image somewhere else or reducing its size.", flags: 64 });
|
||||
} else {
|
||||
logger.error(`Error occurred with slash command ${command} with arguments ${JSON.stringify(interaction.data.options)}: ${error.stack || error}`);
|
||||
logger.error(`Error occurred with application command ${command} with arguments ${JSON.stringify(interaction.data.options)}: ${error.stack || error}`);
|
||||
try {
|
||||
await interaction[replyMethod]("Uh oh! I ran into an error while running this command. Please report the content of the attached file at the following link or on the esmBot Support server: <https://github.com/esmBot/esmBot/issues>", {
|
||||
file: `Message: ${await clean(error)}\n\nStack Trace: ${await clean(error.stack)}`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue