1 |
import { dot, object } from "dot-object"; |
2 |
import { NextFunction, Response } from "express"; |
3 |
import { body } from "express-validator"; |
4 |
import KeyValuePair from "../../types/KeyValuePair"; |
5 |
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 |
const { id } = request.params; |
14 |
|
15 |
if (!request.user?.guilds.includes(id)) { |
16 |
return response.status(403).send({ error: "You don't have permission to access information of this guild." }); |
17 |
} |
18 |
|
19 |
if (id === "global" || !this.client.config.props[id]) { |
20 |
return response.status(404).send({ error: "No guild found with the given ID" }); |
21 |
} |
22 |
|
23 |
next(); |
24 |
}]; |
25 |
} |
26 |
|
27 |
middleware(): KeyValuePair<Function[]> { |
28 |
return { |
29 |
|
30 |
}; |
31 |
} |
32 |
|
33 |
public async indexChannels(request: Request) { |
34 |
const channels = this.client.guilds.cache.get(request.params.id)?.channels.cache; |
35 |
|
36 |
if (request.query?.types) { |
37 |
const types = request.query?.types.toString().split('|'); |
38 |
return channels?.filter(channel => types.includes(channel.type)); |
39 |
} |
40 |
|
41 |
return channels; |
42 |
} |
43 |
|
44 |
public async indexGuilds(request: Request) { |
45 |
return this.client.guilds.cache.filter(g => request.user?.guilds.includes(g.id) ?? false); |
46 |
} |
47 |
} |