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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 379 by rakin, Mon Jul 29 17:29:52 2024 UTC revision 389 by rakin, Mon Jul 29 17:29:55 2024 UTC
# Line 1  Line 1 
1  import { dot, object } from "dot-object";  import { Collection } from "discord.js";
2  import { NextFunction, Response } from "express";  import { NextFunction, Response } from "express";
 import { body } from "express-validator";  
3  import KeyValuePair from "../../types/KeyValuePair";  import KeyValuePair from "../../types/KeyValuePair";
4    import BaseCommand from "../../utils/structures/BaseCommand";
5  import Controller from "../Controller";  import Controller from "../Controller";
6  import RequireAuth from "../middleware/RequireAuth";  import RequireAuth from "../middleware/RequireAuth";
7  import ValidatorError from "../middleware/ValidatorError";  import ValidatorError from "../middleware/ValidatorError";
# Line 10  import Request from "../Request"; Line 10  import Request from "../Request";
10  export default class InfoController extends Controller {  export default class InfoController extends Controller {
11      globalMiddleware(): Function[] {      globalMiddleware(): Function[] {
12          return [RequireAuth, ValidatorError, (request: Request, response: Response, next: NextFunction) => {          return [RequireAuth, ValidatorError, (request: Request, response: Response, next: NextFunction) => {
13                console.log(`URI: ` + request.path);
14    
15                if (request.path === "/systeminfo/commands") {
16                    next();
17                    return;
18                }
19    
20              const { id } = request.params;              const { id } = request.params;
21    
22              if (!request.user?.guilds.includes(id)) {              if (!request.user?.guilds.includes(id)) {
# Line 41  export default class InfoController exte Line 48  export default class InfoController exte
48          return channels;          return channels;
49      }      }
50    
51        public async indexRoles(request: Request) {
52            return this.client.guilds.cache.get(request.params.id)?.roles?.cache.sort((first, second) => second.position - first.position);
53        }
54    
55        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      public async indexGuilds(request: Request) {      public async indexGuilds(request: Request) {
80          return this.client.guilds.cache.filter(g => request.user?.guilds.includes(g.id) ?? false);          return this.client.guilds.cache.filter(g => request.user?.guilds.includes(g.id) ?? false);
81      }      }

Legend:
Removed from v.379  
changed lines
  Added in v.389

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26