mrmBot-Matrix/commands/fun/bird.js

28 lines
839 B
JavaScript
Raw Normal View History

2023-03-15 14:09:09 +00:00
import { request } from "undici";
import Command from "../../classes/command.js";
class BirdCommand extends Command {
async run() {
2023-03-17 00:23:01 +00:00
// await this.acknowledge();
2023-03-15 14:09:09 +00:00
const controller = new AbortController();
const timeout = setTimeout(() => {
controller.abort();
}, 15000);
try {
const imageData = await request("http://shibe.online/api/birds", { signal: controller.signal });
clearTimeout(timeout);
const json = await imageData.body.json();
return json[0];
} catch (e) {
if (e.name === "AbortError") {
this.success = false;
return "I couldn't get a bird image in time. Maybe try again?";
}
}
}
static description = "Gets a random bird picture";
static aliases = ["birb", "birds", "birbs"];
}
export default BirdCommand;