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 NekoCommand extends Command { |
6 |
public override readonly name = "neko"; |
7 |
public override readonly description = "Fetch a random neko image"; |
8 |
public override readonly permissions = []; |
9 |
public override readonly defer = true; |
10 |
|
11 |
public override async execute(context: Context<CommandMessage>) { |
12 |
try { |
13 |
const response = await getAxiosClient().get("https://nekos.best/api/v2/neko"); |
14 |
|
15 |
if (response.status < 200 || response.status >= 300) |
16 |
throw new Error("Invalid status code"); |
17 |
|
18 |
await context.reply({ |
19 |
files: [ |
20 |
{ |
21 |
attachment: response.data.results[0].url |
22 |
} |
23 |
] |
24 |
}); |
25 |
} catch (error) { |
26 |
this.application.logger.error(error); |
27 |
await context.error("Failed to fetch a neko image."); |
28 |
} |
29 |
} |
30 |
} |