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,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";
|
||||
|
|
|
@ -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";
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue