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

Annotation of /trunk/extensions/neko/src/commands/NekoCommand.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

1 rakinar2 611 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     }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26