1 |
import { Command, CommandMessage } from "@framework/commands/Command"; |
2 |
import Context from "@framework/commands/Context"; |
3 |
import { getAxiosClient } from "@sudobot/utils/axios"; |
4 |
|
5 |
export default class AnimeCommand extends Command { |
6 |
public override readonly name = "anime"; |
7 |
public override readonly description = "Fetch a random neko, waifu, or kitsune image"; |
8 |
public override readonly permissions = []; |
9 |
public override readonly defer = true; |
10 |
|
11 |
public override async execute(context: Context<CommandMessage>) { |
12 |
const apis = [ |
13 |
"https://nekos.best/api/v2/neko", |
14 |
"https://nekos.best/api/v2/waifu", |
15 |
"https://nekos.best/api/v2/kitsune" |
16 |
]; |
17 |
|
18 |
const randomApi = apis[Math.floor(Math.random() * apis.length)]; |
19 |
|
20 |
try { |
21 |
const response = await getAxiosClient().get(randomApi); |
22 |
|
23 |
if (response.status < 200 || response.status >= 300) { |
24 |
throw new Error("Invalid status code"); |
25 |
} |
26 |
|
27 |
await context.reply({ |
28 |
files: [ |
29 |
{ |
30 |
attachment: response.data.results[0].url |
31 |
} |
32 |
] |
33 |
}); |
34 |
} catch (error) { |
35 |
this.application.logger.error(error); |
36 |
await context.error("Failed to fetch an image."); |
37 |
} |
38 |
} |
39 |
} |