/[sudobot]/trunk/src/api/controllers/InfoController.ts
ViewVC logotype

Annotation of /trunk/src/api/controllers/InfoController.ts

Parent Directory Parent Directory | Revision Log Revision Log


Revision 389 - (hide annotations)
Mon Jul 29 17:29:55 2024 UTC (8 months, 3 weeks ago) by rakin
File MIME type: application/typescript
File size: 2809 byte(s)
style: fix with eslint
1 rakin 381 import { Collection } from "discord.js";
2 rakin 369 import { NextFunction, Response } from "express";
3     import KeyValuePair from "../../types/KeyValuePair";
4 rakin 381 import BaseCommand from "../../utils/structures/BaseCommand";
5 rakin 369 import Controller from "../Controller";
6     import RequireAuth from "../middleware/RequireAuth";
7     import ValidatorError from "../middleware/ValidatorError";
8     import Request from "../Request";
9    
10     export default class InfoController extends Controller {
11     globalMiddleware(): Function[] {
12     return [RequireAuth, ValidatorError, (request: Request, response: Response, next: NextFunction) => {
13 rakin 381 console.log(`URI: ` + request.path);
14    
15     if (request.path === "/systeminfo/commands") {
16     next();
17     return;
18     }
19    
20 rakin 369 const { id } = request.params;
21    
22     if (!request.user?.guilds.includes(id)) {
23     return response.status(403).send({ error: "You don't have permission to access information of this guild." });
24     }
25    
26     if (id === "global" || !this.client.config.props[id]) {
27     return response.status(404).send({ error: "No guild found with the given ID" });
28     }
29    
30     next();
31     }];
32     }
33    
34     middleware(): KeyValuePair<Function[]> {
35     return {
36    
37     };
38     }
39    
40     public async indexChannels(request: Request) {
41     const channels = this.client.guilds.cache.get(request.params.id)?.channels.cache;
42    
43     if (request.query?.types) {
44     const types = request.query?.types.toString().split('|');
45     return channels?.filter(channel => types.includes(channel.type));
46     }
47    
48     return channels;
49     }
50 rakin 379
51 rakin 380 public async indexRoles(request: Request) {
52 rakin 381 return this.client.guilds.cache.get(request.params.id)?.roles?.cache.sort((first, second) => second.position - first.position);
53 rakin 380 }
54    
55 rakin 381 public async indexCommands() {
56     const commands = new Collection<string, BaseCommand>();
57    
58     for (const [name, command] of this.client.commands) {
59     if (command.getAliases().includes(name)) {
60     console.log(command.getAliases(), "includes", name);
61     continue;
62     }
63    
64     if (commands.has(name) || command.ownerOnly) {
65     console.log(commands.get(name)?.getName(), name);
66     continue;
67     }
68    
69     if (commands.get(name) !== command)
70     commands.set(name, command);
71     }
72    
73     return commands.map(command => ({
74     ...command,
75     permissions: command.permissions.map(perm => perm.toString()),
76     }));
77     }
78    
79 rakin 379 public async indexGuilds(request: Request) {
80     return this.client.guilds.cache.filter(g => request.user?.guilds.includes(g.id) ?? false);
81     }
82 rakin 369 }

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26