Add timeouts to many projectlounge requests, fixed command bug
This commit is contained in:
parent
4684db06e8
commit
516570efe4
6 changed files with 60 additions and 22 deletions
|
@ -4,7 +4,13 @@ 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" });
|
||||
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,
|
||||
|
@ -13,6 +19,11 @@ class AncientCommand extends Command {
|
|||
}
|
||||
}
|
||||
};
|
||||
} 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";
|
||||
|
|
|
@ -4,7 +4,13 @@ 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" });
|
||||
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,
|
||||
|
@ -14,6 +20,11 @@ class CatCommand extends Command {
|
|||
}
|
||||
}
|
||||
};
|
||||
} 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";
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
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
|
||||
}
|
||||
return `${prefix}Like esmBot? Consider supporting the developer on Patreon to help keep it running! https://patreon.com/TheEssem`;
|
||||
}
|
||||
|
||||
|
|
|
@ -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:",
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue