/[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 393 by rakin, Mon Jul 29 17:29:59 2024 UTC
# Line 1  Line 1 
1  import { dot, object } from "dot-object";  /**
2    * This file is part of SudoBot.
3    *
4    * Copyright (C) 2021-2022 OSN Inc.
5    *
6    * SudoBot is free software; you can redistribute it and/or modify it
7    * under the terms of the GNU Affero General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10    *
11    * SudoBot is distributed in the hope that it will be useful, but
12    * WITHOUT ANY WARRANTY; without even the implied warranty of
13    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14    * GNU Affero General Public License for more details.
15    *
16    * You should have received a copy of the GNU Affero General Public License
17    * along with SudoBot. If not, see <https://www.gnu.org/licenses/>.
18    */
19    
20    import { Collection } from "discord.js";
21  import { NextFunction, Response } from "express";  import { NextFunction, Response } from "express";
 import { body } from "express-validator";  
22  import KeyValuePair from "../../types/KeyValuePair";  import KeyValuePair from "../../types/KeyValuePair";
23    import BaseCommand from "../../utils/structures/BaseCommand";
24  import Controller from "../Controller";  import Controller from "../Controller";
25  import RequireAuth from "../middleware/RequireAuth";  import RequireAuth from "../middleware/RequireAuth";
26  import ValidatorError from "../middleware/ValidatorError";  import ValidatorError from "../middleware/ValidatorError";
# Line 10  import Request from "../Request"; Line 29  import Request from "../Request";
29  export default class InfoController extends Controller {  export default class InfoController extends Controller {
30      globalMiddleware(): Function[] {      globalMiddleware(): Function[] {
31          return [RequireAuth, ValidatorError, (request: Request, response: Response, next: NextFunction) => {          return [RequireAuth, ValidatorError, (request: Request, response: Response, next: NextFunction) => {
32                console.log(`URI: ` + request.path);
33    
34                if (request.path === "/systeminfo/commands") {
35                    next();
36                    return;
37                }
38    
39              const { id } = request.params;              const { id } = request.params;
40    
41              if (!request.user?.guilds.includes(id)) {              if (!request.user?.guilds.includes(id)) {
# Line 41  export default class InfoController exte Line 67  export default class InfoController exte
67          return channels;          return channels;
68      }      }
69    
70        public async indexRoles(request: Request) {
71            return this.client.guilds.cache.get(request.params.id)?.roles?.cache.sort((first, second) => second.position - first.position);
72        }
73    
74        public async indexCommands() {
75            const commands = new Collection<string, BaseCommand>();
76    
77            for (const [name, command] of this.client.commands) {
78                if (command.getAliases().includes(name)) {
79                    console.log(command.getAliases(), "includes", name);
80                    continue;
81                }
82    
83                if (commands.has(name) || command.ownerOnly) {
84                    console.log(commands.get(name)?.getName(), name);
85                    continue;
86                }
87    
88                if (commands.get(name) !== command)
89                    commands.set(name, command);
90            }
91            
92            return commands.map(command => ({
93                ...command,
94                permissions: command.permissions.map(perm => perm.toString()),
95            }));
96        }
97    
98      public async indexGuilds(request: Request) {      public async indexGuilds(request: Request) {
99          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);
100      }      }

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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26