mrmBot-Matrix/commands/fun/dog.js
2023-03-19 01:10:48 -04:00

29 lines
No EOL
938 B
JavaScript

import { request } from "undici";
import Command from "../../classes/command.js";
class DogCommand extends Command {
static category = "general"
async run() {
// await this.acknowledge();
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, 15000);
try {
const imageData = await request("https://dog.ceo/api/breeds/image/random", { signal: controller.signal });
clearTimeout(timeout);
const json = await imageData.body.json();
return json.message;
} catch (e) {
if (e.name === "AbortError") {
this.success = false;
return "I couldn't get a dog image in time. Maybe try again?";
}
}
}
static description = "Gets a random dog picture";
static aliases = ["doggos", "doggo", "pupper", "puppers", "dogs", "puppy", "puppies", "pups", "pup"];
}
export default DogCommand;