-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
63 lines (53 loc) · 1.63 KB
/
utils.ts
File metadata and controls
63 lines (53 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import { NextFunction } from 'express';
import mongoose from 'mongoose';
export type LogoOptions = {
square: string;
[shape: string]: string;
root: string;
};
export const PROJECT_URL = process.env.URL || 'http://localhost:3030';
export function logoHandler(
req: any,
res: any,
next: NextFunction,
options: LogoOptions,
onlyLogo = false
): void {
if (onlyLogo) {
res.sendFile(options?.square, { root: options.root });
return;
}
for (const shape in options) {
if (shape === 'root') continue;
const optionShape = options[shape];
console.log(shape, optionShape);
if (shape === req.params.shape && optionShape) {
res.sendFile(optionShape, { root: options.root });
return;
}
}
const error = new Error('Invalid shape') as Error & { status: number };
error.status = 400;
next(error);
}
export async function findUser(user_id: string): Promise<any | void> {
const myHeaders = new Headers();
myHeaders.append('Authorization', 'Bot ' + process.env.DISCORD_BOT_TOKEN);
const requestOptions: RequestInit = {
method: 'GET',
headers: myHeaders,
redirect: 'follow'
};
let toReturn: any = {};
await fetch('https://discord.com/api/v10/users/' + user_id, requestOptions)
.then(async response => {
try {
toReturn = JSON.parse(await response.text());
} catch (error) {
console.error(error);
toReturn = response.text();
}
})
.catch(error => console.error(error));
return toReturn;
}