diff --git a/commands/fun/ancient.js b/commands/fun/ancient.js index 4e8078d..f75074c 100644 --- a/commands/fun/ancient.js +++ b/commands/fun/ancient.js @@ -4,15 +4,26 @@ const Command = require("../../classes/command.js"); class AncientCommand extends Command { async run() { this.client.sendChannelTyping(this.message.channel.id); - const data = await fetch("https://projectlounge.pw/meme/", { redirect: "manual" }); - return { - embed: { - color: 16711680, - image: { - url: data.headers.get("location") + const controller = new AbortController(); // eslint-disable-line no-undef + const timeout = setTimeout(() => { + controller.abort(); + }, 15000); + try { + const data = await fetch("https://projectlounge.pw/meme/", { redirect: "manual", signal: controller.signal }); + clearTimeout(timeout); + return { + embed: { + color: 16711680, + image: { + url: data.headers.get("location") + } } + }; + } catch (e) { + if (e.name === "AbortError") { + return "I couldn't get a meme in time. Maybe try again?"; } - }; + } } static description = "Gets a random ancient meme"; diff --git a/commands/fun/cat.js b/commands/fun/cat.js index 9b2d4ba..d9e1046 100644 --- a/commands/fun/cat.js +++ b/commands/fun/cat.js @@ -4,16 +4,27 @@ const Command = require("../../classes/command.js"); class CatCommand extends Command { async run() { this.client.sendChannelTyping(this.message.channel.id); - const data = await fetch("https://projectlounge.pw/cta/", { redirect: "manual" }); - return { - embed: { - color: 16711680, - description: "Cat images are sourced from a subset of the [dm4catbot](https://twitter.com/dm4catbot) database.", - image: { - url: data.headers.get("location") + const controller = new AbortController(); // eslint-disable-line no-undef + const timeout = setTimeout(() => { + controller.abort(); + }, 15000); + try { + const data = await fetch("https://projectlounge.pw/cta/", { redirect: "manual", signal: controller.signal }); + clearTimeout(timeout); + return { + embed: { + color: 16711680, + description: "Cat images are sourced from a subset of the [dm4catbot](https://twitter.com/dm4catbot) database.", + image: { + url: data.headers.get("location") + } } + }; + } catch (e) { + if (e.name === "AbortError") { + return "I couldn't get a cat image in time. Maybe try again?"; } - }; + } } static description = "Gets a random cat picture"; diff --git a/commands/general/command.js b/commands/general/command.js index 82732bc..702a466 100644 --- a/commands/general/command.js +++ b/commands/general/command.js @@ -15,6 +15,7 @@ class CommandCommand extends Command { if (this.args[0].toLowerCase() === "disable") { if (!collections.commands.has(this.args[1].toLowerCase()) && !collections.aliases.has(this.args[1].toLowerCase())) return "That isn't a command!"; const command = collections.aliases.has(this.args[1].toLowerCase()) ? collections.aliases.get(this.args[1].toLowerCase()) : this.args[1].toLowerCase(); + if (command === "command") return "You can't disable that command!"; if (disabled && disabled.includes(command)) return "That command is already disabled!"; await db.disableCommand(this.message.channel.guild.id, command); diff --git a/commands/general/donate.js b/commands/general/donate.js index 7141844..bfbe362 100644 --- a/commands/general/donate.js +++ b/commands/general/donate.js @@ -3,13 +3,23 @@ const Command = require("../../classes/command.js"); class DonateCommand extends Command { async run() { + this.client.sendChannelTyping(this.message.channel.id); let prefix = ""; - const patrons = await fetch("https://projectlounge.pw/patrons").then(data => data.json()); - prefix = "Thanks to the following patrons for their support:\n"; - for (const patron of patrons) { - prefix += `**- ${patron}**\n`; + const controller = new AbortController(); // eslint-disable-line no-undef + const timeout = setTimeout(() => { + controller.abort(); + }, 5000); + try { + const patrons = await fetch("https://projectlounge.pw/patrons", { signal: controller.signal }).then(data => data.json()); + clearTimeout(timeout); + prefix = "Thanks to the following patrons for their support:\n"; + for (const patron of patrons) { + prefix += `**- ${patron}**\n`; + } + prefix += "\n"; + } catch (e) { + // no-op } - prefix += "\n"; return `${prefix}Like esmBot? Consider supporting the developer on Patreon to help keep it running! https://patreon.com/TheEssem`; } diff --git a/commands/general/info.js b/commands/general/info.js index 8c16822..580e595 100644 --- a/commands/general/info.js +++ b/commands/general/info.js @@ -23,7 +23,7 @@ class InfoCommand extends Command { }, { "name": "💬 Total Servers:", - "value": stats.guilds ? stats.guilds : `${this.client.guilds.size} (for this cluster only)` + "value": stats && stats.guilds ? stats.guilds : `${this.client.guilds.size} (for this cluster only)` }, { "name": "✅ Official Server:", diff --git a/events/messageCreate.js b/events/messageCreate.js index e12ed51..d20209f 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -118,8 +118,13 @@ module.exports = async (client, cluster, worker, ipc, message) => { const filename = `${Math.random().toString(36).substring(2, 15)}.${result.name.split(".")[1]}`; await fs.promises.writeFile(`${process.env.TEMPDIR}/${filename}`, result.file); const imageURL = `${process.env.TMP_DOMAIN == "" ? "https://tmp.projectlounge.pw" : process.env.TMP_DOMAIN}/${filename}`; + const controller = new AbortController(); // eslint-disable-line no-undef + const timeout = setTimeout(() => { + controller.abort(); + }, 5000); try { - await fetch(imageURL); + await fetch(imageURL, { signal: controller.signal }); + clearTimeout(timeout); } catch { // this is here to make sure the image is properly cached by discord }