/[sudobot]/trunk/extensions/neko/src/commands/AnimeCommand.ts
ViewVC logotype

Contents of /trunk/extensions/neko/src/commands/AnimeCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 611 - (show annotations)
Sun Aug 25 17:37:58 2024 UTC (7 months ago) by rakinar2
File MIME type: application/typescript
File size: 1356 byte(s)
fix(extensions:neko): support sudobot v9 APIs

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 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26